From f3d16775e22063048d7716825d0e57b703b495fa Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Wed, 16 Feb 2022 19:54:48 +0100 Subject: [PATCH] Fix linting --- soco/events_twisted.py | 1 + tests/test_core.py | 36 ++++++++++++++++++------------------ tests/test_musicservices.py | 5 +---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/soco/events_twisted.py b/soco/events_twisted.py index 9a81804a1..0702b7c08 100644 --- a/soco/events_twisted.py +++ b/soco/events_twisted.py @@ -72,6 +72,7 @@ def before_shutdown(): class Resource: # pylint: disable=no-init """Fake Resource class to use when building docs""" + else: from twisted.internet import reactor from twisted.web.server import Site diff --git a/tests/test_core.py b/tests/test_core.py index b4375ada6..0d2756d1f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1280,7 +1280,7 @@ def test_soco_soundbar_audio_input_format(self, moco): def test_soco_audio_delay(self, moco): moco._is_soundbar = False - assert moco.audio_delay == None + assert moco.audio_delay is None assert not moco.renderingControl.GetEQ.called with pytest.raises(NotSupportedException): @@ -1355,12 +1355,15 @@ def test_soco_balance(self, moco): [("InstanceID", 0), ("Channel", "RF"), ("DesiredVolume", 100)] ) - @pytest.mark.parametrize("prop,variable,type,min,max", [ - ("surround_enabled", "SurroundEnable", bool, None, None), - ("surround_ambient_enabled", "SurroundMode", bool, None, None), - ("surround_volume_tv", "SurroundLevel", int, -15, 15), - ("surround_volume_music", "MusicSurroundLevel", int, -15, 15), - ]) + @pytest.mark.parametrize( + "prop,variable,type,min,max", + [ + ("surround_enabled", "SurroundEnable", bool, None, None), + ("surround_ambient_enabled", "SurroundMode", bool, None, None), + ("surround_volume_tv", "SurroundLevel", int, -15, 15), + ("surround_volume_music", "MusicSurroundLevel", int, -15, 15), + ], + ) def test_soco_surround_settings(self, moco, prop, variable, type, min, max): """Test the surround settings. @@ -1368,6 +1371,7 @@ def test_soco_surround_settings(self, moco, prop, variable, type, min, max): * For boolean values, check toggling and payloads * For ranged int values, check the ranges and payloads. """ + def _assert_seteq_call(prop, variable, value, type): desired_value = value setattr(moco, prop, value) @@ -1383,27 +1387,24 @@ def _assert_seteq_call(prop, variable, value, type): ] ) - moco.renderingControl.GetEQ.return_value = {"CurrentValue": int(desired_value)} + moco.renderingControl.GetEQ.return_value = { + "CurrentValue": int(desired_value) + } if type == bool: assert getattr(moco, prop) == bool(value) elif type == int: assert getattr(moco, prop) == value moco.renderingControl.GetEQ.assert_any_call( - [ - ("InstanceID", 0), - ("EQType", variable) - ] + [("InstanceID", 0), ("EQType", variable)] ) moco.renderingControl.SetEQ.reset_mock() moco.renderingControl.GetEQ.reset_mock() - - with mock.patch( - "soco.SoCo.is_soundbar", new_callable=mock.PropertyMock + "soco.SoCo.is_soundbar", new_callable=mock.PropertyMock ) as mock_is_soundbar: - mock_is_soundbar = True + mock_is_soundbar = True # noqa: F841 if type == bool: for target in [True, False]: @@ -1413,7 +1414,7 @@ def _assert_seteq_call(prop, variable, value, type): for target in [min, max]: _assert_seteq_call(prop, variable, target, type) - for target in [min-5, max+5]: + for target in [min - 5, max + 5]: with pytest.raises(ValueError): setattr(moco, prop, target) @@ -1421,7 +1422,6 @@ def _assert_seteq_call(prop, variable, value, type): raise Exception("unhandled type %s" % type) - class TestDeviceProperties: def test_soco_status_light(self, moco): moco.deviceProperties.GetLEDState.return_value = {"CurrentLEDState": "On"} diff --git a/tests/test_musicservices.py b/tests/test_musicservices.py index ea28fd6ed..a6f435901 100644 --- a/tests/test_musicservices.py +++ b/tests/test_musicservices.py @@ -7,10 +7,7 @@ import soco.soap from soco.exceptions import MusicServiceException from soco.music_services.accounts import Account -from soco.music_services.music_service import ( - MusicService, - MusicServiceSoapClient, -) +from soco.music_services.music_service import MusicService # Typical account data from http://{Sonos-ip}:1400/status/accounts