Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Feb 16, 2022
1 parent b285def commit f3d1677
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions soco/events_twisted.py
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions tests/test_core.py
Expand Up @@ -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):
Expand Down Expand Up @@ -1355,19 +1355,23 @@ 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.
This performs the following checks:
* 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)
Expand All @@ -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]:
Expand All @@ -1413,15 +1414,14 @@ 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)

else:
raise Exception("unhandled type %s" % type)



class TestDeviceProperties:
def test_soco_status_light(self, moco):
moco.deviceProperties.GetLEDState.return_value = {"CurrentLEDState": "On"}
Expand Down
5 changes: 1 addition & 4 deletions tests/test_musicservices.py
Expand Up @@ -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
Expand Down

0 comments on commit f3d1677

Please sign in to comment.