X-Git-Url: http://git.kaliko.me/?p=python-musicpd.git;a=blobdiff_plain;f=test.py;h=6265af246a6efb5a364e5b5b68c5eed34692262f;hp=2c5094d9106296911223a1d3220c4213380d0f25;hb=80fdad9f2cad5b3759351ab38bf32cad863cd3cb;hpb=e616985e3da118a4e2b14afe331446633e7e2254 diff --git a/test.py b/test.py index 2c5094d..6265af2 100755 --- a/test.py +++ b/test.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +# coding: utf-8 +# SPDX-FileCopyrightText: 2012-2021 kaliko +# SPDX-License-Identifier: LGPL-3.0-or-later # pylint: disable=missing-docstring """ Test suite highly borrowed^Wsteal from python-mpd2 [0] project. @@ -593,6 +595,18 @@ class testException(unittest.TestCase): with self.assertRaises(musicpd.CommandError): cli.find('(album == "foo\nbar")') +class testContextManager(unittest.TestCase): + + def test_enter_exit(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() + with cli as c: + sock.connect.assert_called_with('\0abstract') + sock.close.assert_not_called() + sock.close.assert_called() if __name__ == '__main__': unittest.main()