]> kaliko git repositories - python-musicpd.git/commitdiff
Add tests for socket connections
authorKaliko Jack <kaliko@azylum.org>
Fri, 19 Feb 2021 14:55:42 +0000 (15:55 +0100)
committerKaliko Jack <kaliko@azylum.org>
Fri, 19 Feb 2021 14:55:42 +0000 (15:55 +0100)
test.py

diff --git a/test.py b/test.py
index 9ec94e645e40148aeaacc6da904cd0da1008130d..7f1890fe9f325ec1b4c5c450ea8048d8b5727cca 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -552,5 +552,35 @@ class TestMPDClient(unittest.TestCase):
         self.assertMPDReceived('command_list_end\n')
 
 
+class testConnection(unittest.TestCase):
+
+    def test_exposing_fileno(self):
+        with mock.patch('musicpd.socket') as socket_mock:
+            sock = mock.MagicMock(name='socket')
+            socket_mock.socket.return_value = sock
+            cli = musicpd.MPDClient()
+            cli.connect()
+            cli.fileno()
+            cli._sock.fileno.assert_called_with()
+
+    def test_connect_abstract(self):
+        os.environ['MPD_HOST'] = '@abstract'
+        with mock.patch('musicpd.socket') as socket_mock:
+            sock = mock.MagicMock(name='socket')
+            socket_mock.socket.return_value = sock
+            cli = musicpd.MPDClient()
+            cli.connect()
+            sock.connect.assert_called_with('\0abstract')
+
+    def test_connect_unix(self):
+        os.environ['MPD_HOST'] = '/run/mpd/socket'
+        with mock.patch('musicpd.socket') as socket_mock:
+            sock = mock.MagicMock(name='socket')
+            socket_mock.socket.return_value = sock
+            cli = musicpd.MPDClient()
+            cli.connect()
+            sock.connect.assert_called_with('/run/mpd/socket')
+
+
 if __name__ == '__main__':
     unittest.main()