From 691958e03673c01f8c4ea2f18cb9e8fe3ca3fab3 Mon Sep 17 00:00:00 2001 From: Kaliko Jack Date: Fri, 19 Feb 2021 15:55:42 +0100 Subject: [PATCH] Add tests for socket connections --- test.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test.py b/test.py index 9ec94e6..7f1890f 100755 --- 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() -- 2.39.5