diff --git a/roku/scripting.py b/roku/scripting.py index 33d9fa4..0f65c60 100644 --- a/roku/scripting.py +++ b/roku/scripting.py @@ -4,22 +4,24 @@ import time from collections import namedtuple -SCRIPT_RE = re.compile(r"(?P\w+)(?:\:(?P[\w\s]+))?(?:\@(?P\d+))?(?:\*(?P[\d\.]+))?") # noqa +SCRIPT_RE = re.compile( + r"(?P\w+)(?:\:(?P[\w\s]+))?(?:\@(?P\d+))?(?:\*(?P[\d\.]+))?" +) # noqa -Command = namedtuple('Command', ['command', 'param', 'count', 'sleep']) +Command = namedtuple("Command", ["command", "param", "count", "sleep"]) -logger = logging.getLogger('roku.scripting') +logger = logging.getLogger("roku.scripting") def load_script(path, params=None, raw=False): if not os.path.exists(path): - raise ValueError(f'script at {path} not found') + raise ValueError(f"script at {path} not found") with open(path) as infile: content = infile.read() if params: content = content.format(**params) if not raw: - content = content.strip().split('\n') + content = content.strip().split("\n") return content @@ -31,8 +33,8 @@ def parse_script(script): m = SCRIPT_RE.match(line) if m: data = m.groupdict() - data['count'] = int(data['count'] or 1) - data['sleep'] = float(data['sleep']) if data['sleep'] else None + data["count"] = int(data["count"] or 1) + data["sleep"] = float(data["sleep"]) if data["sleep"] else None commands.append(Command(**data)) return commands diff --git a/roku/tests/conftest.py b/roku/tests/conftest.py index da917f0..d61af9d 100644 --- a/roku/tests/conftest.py +++ b/roku/tests/conftest.py @@ -4,14 +4,13 @@ class Fauxku(Roku): - def __init__(self, *args, **kwargs): super(Fauxku, self).__init__(*args, **kwargs) self._calls = [] def _call(self, method, path, *args, **kwargs): self._calls.append((method, path, args, kwargs)) - return '' + return "" def calls(self): return self._calls @@ -22,15 +21,15 @@ def last_call(self): @pytest.fixture def roku(): - return Fauxku('0.0.0.0') + return Fauxku("0.0.0.0") @pytest.fixture def apps(roku): faux_apps = [ - Application('11', '1.0.1', 'Fauxku Channel Store', roku), - Application('22', '2.0.2', 'Faux Netflix', roku), - Application('33', '3.0.3', 'Faux YouTube', roku), - Application('44HL', '4.0.4', 'Faux Hulu', roku), + Application("11", "1.0.1", "Fauxku Channel Store", roku), + Application("22", "2.0.2", "Faux Netflix", roku), + Application("33", "3.0.3", "Faux YouTube", roku), + Application("44HL", "4.0.4", "Faux Hulu", roku), ] return faux_apps diff --git a/roku/tests/test_scripting.py b/roku/tests/test_scripting.py index 47f4613..3ddaac4 100644 --- a/roku/tests/test_scripting.py +++ b/roku/tests/test_scripting.py @@ -3,7 +3,7 @@ from roku import scripting -SCRIPT_PATH = 'roku/tests/scripts/testscript.txt' +SCRIPT_PATH = "roku/tests/scripts/testscript.txt" def test_loading(): @@ -12,8 +12,8 @@ def test_loading(): def test_loading_params(): params = { - 'avar': 'here', - 'notavar': 'missing', + "avar": "here", + "notavar": "missing", } content = scripting.load_script(SCRIPT_PATH, params=params, raw=True) assert "literal:here" in content @@ -22,48 +22,48 @@ def test_loading_params(): def test_loading_notfound(): with pytest.raises(ValueError): - scripting.load_script('thisisnotarealscript.txt') + scripting.load_script("thisisnotarealscript.txt") def test_parse_command_only(): - content = ('home',) + content = ("home",) script = scripting.parse_script(content) command = script[0] - assert command == scripting.Command('home', None, 1, None) + assert command == scripting.Command("home", None, 1, None) def test_parse_command_param(): - content = ('literal:barbecue',) + content = ("literal:barbecue",) script = scripting.parse_script(content) command = script[0] - assert command == scripting.Command('literal', 'barbecue', 1, None) + assert command == scripting.Command("literal", "barbecue", 1, None) def test_parse_command_count(): - content = ('left@10',) + content = ("left@10",) script = scripting.parse_script(content) command = script[0] - assert command == scripting.Command('left', None, 10, None) + assert command == scripting.Command("left", None, 10, None) def test_parse_command_sleep(): - content = ('left*2',) + content = ("left*2",) script = scripting.parse_script(content) command = script[0] - assert command == scripting.Command('left', None, 1, 2.0) + assert command == scripting.Command("left", None, 1, 2.0) def test_parse_command_all(): - content = ('literal:barbecue@3*5.1',) + content = ("literal:barbecue@3*5.1",) script = scripting.parse_script(content) command = script[0] - assert command == scripting.Command('literal', 'barbecue', 3, 5.1) + assert command == scripting.Command("literal", "barbecue", 3, 5.1) def test_run_script(roku): - content = ('home', 'literal:x') + content = ("home", "literal:x") script = scripting.parse_script(content) scripting.run_script(roku, script) calls = roku.calls() - assert 'keypress/Home' in calls[0][1] - assert 'keypress/Lit_x' in calls[1][1] + assert "keypress/Home" in calls[0][1] + assert "keypress/Lit_x" in calls[1][1]