|
| 1 | +import pytest |
| 2 | + |
| 3 | +from roku import scripting |
| 4 | + |
| 5 | + |
| 6 | +SCRIPT_PATH = 'roku/tests/scripts/testscript.txt' |
| 7 | + |
| 8 | + |
| 9 | +def test_loading(): |
| 10 | + scripting.load_script(SCRIPT_PATH) |
| 11 | + |
| 12 | + |
| 13 | +def test_loading_params(): |
| 14 | + params = { |
| 15 | + 'avar': 'here', |
| 16 | + 'notavar': 'missing', |
| 17 | + } |
| 18 | + content = scripting.load_script(SCRIPT_PATH, params=params, raw=True) |
| 19 | + assert "literal:here" in content |
| 20 | + assert "literal:missing" not in content |
| 21 | + |
| 22 | + |
| 23 | +def test_loading_notfound(): |
| 24 | + with pytest.raises(ValueError): |
| 25 | + scripting.load_script('thisisnotarealscript.txt') |
| 26 | + |
| 27 | + |
| 28 | +def test_parse_command_only(): |
| 29 | + content = ('home',) |
| 30 | + script = scripting.parse_script(content) |
| 31 | + command = script[0] |
| 32 | + assert command == scripting.Command('home', None, 1, None) |
| 33 | + |
| 34 | + |
| 35 | +def test_parse_command_param(): |
| 36 | + content = ('literal:barbecue',) |
| 37 | + script = scripting.parse_script(content) |
| 38 | + command = script[0] |
| 39 | + assert command == scripting.Command('literal', 'barbecue', 1, None) |
| 40 | + |
| 41 | + |
| 42 | +def test_parse_command_count(): |
| 43 | + content = ('left@10',) |
| 44 | + script = scripting.parse_script(content) |
| 45 | + command = script[0] |
| 46 | + assert command == scripting.Command('left', None, 10, None) |
| 47 | + |
| 48 | + |
| 49 | +def test_parse_command_sleep(): |
| 50 | + content = ('left*2',) |
| 51 | + script = scripting.parse_script(content) |
| 52 | + command = script[0] |
| 53 | + assert command == scripting.Command('left', None, 1, 2.0) |
| 54 | + |
| 55 | + |
| 56 | +def test_parse_command_all(): |
| 57 | + content = ('literal:barbecue@3*5.1',) |
| 58 | + script = scripting.parse_script(content) |
| 59 | + command = script[0] |
| 60 | + assert command == scripting.Command('literal', 'barbecue', 3, 5.1) |
| 61 | + |
| 62 | + |
| 63 | +def test_run_script(roku): |
| 64 | + content = ('home', 'literal:x') |
| 65 | + script = scripting.parse_script(content) |
| 66 | + scripting.run_script(roku, script) |
| 67 | + calls = roku.calls() |
| 68 | + assert 'keypress/Home' in calls[0][1] |
| 69 | + assert 'keypress/Lit_x' in calls[1][1] |
0 commit comments