Skip to content

Commit

Permalink
Merge branch 'develop' into feature/pull_run_once
Browse files Browse the repository at this point in the history
  • Loading branch information
HazardDede committed Apr 29, 2020
2 parents b199e28 + 9752c79 commit 2bc0d04
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pnp/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PluginStoppedError(RuntimeError):
class PluginMeta(type):
"""Metaclasses for plugins. Hooks up the `argresolver`-package to inject any missing arguments
at runtime if provided as an environment variable."""
def __new__(cls, name: str, bases: Any, dct: Dict[Any, Any]) -> type:
def __new__(cls, name: str, bases: Any, dct: Dict[Any, Any]) -> type: # type: ignore
newly = super().__new__(cls, name, bases, dct)
# Force all __init__ of plugins to be decorated with envargs
newly.__init__ = EnvironmentResolver(default_override=True)(newly.__init__) # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion pnp/plugins/pull/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def _throttled():

out = subprocess.run(
['vcgencmd', 'get_throttled'],
stdout=subprocess.PIPE
stdout=subprocess.PIPE,
check=False
).stdout.decode('utf-8')
hex_num = int(out[out.find('=') + 1:], 16)

Expand Down
2 changes: 1 addition & 1 deletion pnp/plugins/pull/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _on_message(self, client, obj, msg): # pylint: disable=unused-argument
# This one is an envelope with data
self.notify(dict(
topic=str(msg.topic),
levels=[level for level in msg.topic.split('/')],
levels=msg.topic.split('/'),
payload=msg.payload.decode('utf-8')
))

Expand Down
23 changes: 14 additions & 9 deletions pnp/plugins/push/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,21 @@ def _parse_envelope_value(
Validator.is_function(allow_none=True, parse_fun=parse_fun)
Validator.is_function(allow_none=True, instance_lookup_fun=instance_lookup_fun)

lookups = cast(Dict[str, str],
utils.make_public_protected_private_attr_lookup(name, as_dict=True))
lookups = cast(
Dict[str, str], utils.make_public_protected_private_attr_lookup(name, as_dict=True)
)

if envelope is None or name not in envelope:
return (instance_lookup_fun(name)
if instance_lookup_fun is not None
else _lookup(self, list(lookups.values())))
return (
instance_lookup_fun(name)
if instance_lookup_fun is not None
else _lookup(self, list(lookups.values())) # pylint: disable=no-member
)

val = envelope[name]
try:
if parse_fun is None:
public_attr_name = lookups['public']
public_attr_name = lookups['public'] # pylint: disable=invalid-sequence-index
fun_base = 'parse_' + public_attr_name
parse_fun_names = utils.make_public_protected_private_attr_lookup(fun_base)
parse_fun = _lookup(self, parse_fun_names)
Expand All @@ -217,9 +220,11 @@ def _parse_envelope_value(
"Cannot parse value for '%s' from envelope",
name
)
return (instance_lookup_fun(name)
if instance_lookup_fun is not None
else _lookup(self, list(lookups.values())))
return (
instance_lookup_fun(name)
if instance_lookup_fun is not None
else _lookup(self, list(lookups.values())) # pylint: disable=no-member
)

@staticmethod
def envelope_payload(payload: Payload) -> Tuple[Envelope, Payload]:
Expand Down
2 changes: 1 addition & 1 deletion pnp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ def __str__(self: object) -> str:
"{name}={value}".format(
name=name,
value=vars(self)[name].__repr__()
) for name in [key for key in sorted(vars(self))]
) for name in sorted(vars(self))
if name not in get_field_mro(self.__class__, '__auto_str_ignore__')
]
return "{clazz}({items})".format(
Expand Down
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ disable=print-statement,
too-many-instance-attributes,
too-many-arguments,
import-error,
duplicate-code
duplicate-code,
import-outside-toplevel

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
12 changes: 6 additions & 6 deletions requirements.dev
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
astroid==2.2.5
astroid
bumpversion
coveralls
flake8
MarkdownPP==1.4
MarkdownPP
mock
mypy==0.701
pylint==2.3.1
pytest<=4.6.5
mypy
pylint
pytest>=5.4.0
pytest-asyncio
pytest-cov
setuptools
twine
typing_extensions
websockets
yamllint>=1.15.0
yamllint
3 changes: 1 addition & 2 deletions tests/plugins/pull/test_camera_motioneyewatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,5 @@ def expected(tmpdir):

@pytest.mark.skipif(not _required_packages_installed(), reason="requires package watchdog")
def test_motioneye_watcher_no_exts():
with pytest.raises(TypeError) as e:
with pytest.raises(TypeError, match="You have to specify either `image_file_ext`, `movie_file_ext` or both") as e:
MotionEyeWatcher(name='pytest', path='/tmp', image_ext=None, movie_ext=None)
assert "TypeError: You have to specify either `image_file_ext`, `movie_file_ext` or both" in str(e)
6 changes: 2 additions & 4 deletions tests/plugins/pull/test_ftp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def test_ftp_server_init_user_pwd():
assert dut.user == 'admin'
assert dut.password == 'root'

with pytest.raises(TypeError) as err:
with pytest.raises(TypeError, match="Argument 'user_pwd' is expected to be a str \(user\) or a tuple of user and password") as err:
ftp.Server(name='pytest', user_pwd=5)
assert "TypeError: Argument 'user_pwd' is expected to be a str (user) or a tuple of user and password." in str(err)


def test_ftp_server_init_events():
Expand All @@ -47,9 +46,8 @@ def test_ftp_server_init_events():
dut = ftp.Server(name='pytest', events=('login', 'logout'))
assert dut.events == [dut.EVENT_LOGIN, dut.EVENT_LOGOUT]

with pytest.raises(ValueError) as err:
with pytest.raises(ValueError, match="Argument 'events' is expected to be a subset of") as err:
ftp.Server(name='pytest', events='unknown')
assert "ValueError: Argument 'events' is expected to be a subset of" in str(err)


def test_ftp_server_pull_connect_login_disconnect():
Expand Down
3 changes: 1 addition & 2 deletions tests/plugins/push/test_hass_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ def call_validator(*args, **kwargs):

dut = Service(name='pytest', url=HASS_URL, token=HA_TOKEN, timeout=TIMEOUT, domain=DOMAIN, service=SERVICE)

with pytest.raises(RuntimeError) as e:
with pytest.raises(RuntimeError, match="Failed to call the service services/frontend/set_theme @ http://hass:8123") as e:
dut.push(DATA)
assert "RuntimeError: Failed to call the service services/frontend/set_theme @ http://hass:8123" in str(e)

0 comments on commit 2bc0d04

Please sign in to comment.