-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_magic.py
More file actions
73 lines (52 loc) · 2.41 KB
/
Copy pathtest_magic.py
File metadata and controls
73 lines (52 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
from pathlib import Path
import pytest
from herethere.there.commands import ContextObject
from magic_here import shortcuts # noqa
@pytest.mark.asyncio
async def test_kv_command_runcode_called(call_there_group, mocker):
runcode = mocker.patch.object(ContextObject, "runcode", autospec=True)
await call_there_group(["kv"], "Label:")
runcode.assert_called_once()
ctx_obj = runcode.call_args[0][0]
assert "load_kv_string(r'''# %%there ... \nLabel: '''" in ctx_obj.code
@pytest.mark.asyncio
async def test_kv_command_executed(capfd, app_instance, call_there_group):
assert not getattr(app_instance.root, "text", "")
await call_there_group(["kv"], "Label:\n text: '''Hello there'''")
captured = capfd.readouterr()
assert not captured.out and not captured.err
assert app_instance.root.text == "Hello there"
@pytest.mark.asyncio
async def test_screenshot_command_executed(app_instance, call_there_group):
await call_there_group(["screenshot"], "")
@pytest.mark.asyncio
async def test_screenshot_saved_to_file(tmpdir, app_instance, call_there_group):
output = Path(tmpdir) / "test.png"
assert not os.path.exists(output)
await call_there_group(["screenshot", "-o", output], "")
assert os.path.exists(output)
@pytest.mark.asyncio
async def test_screenshot_resized_to_width(tmpdir, app_instance, call_there_group):
output = Path(tmpdir) / "test.png"
await call_there_group(["screenshot", "--width", "100", "-o", output], "")
image = shortcuts.PILImage.open(output)
assert image.size[0] == 100
@pytest.mark.asyncio
async def test_pin_command_pin_shortcut_called(
mocker, capfd, mocked_android_modules, call_there_group, test_py_script
):
pin_shortcut = mocker.patch("android_here.pin_shortcut")
await call_there_group(["pin", test_py_script, "--label", "Test label"], "")
captured = capfd.readouterr()
assert not captured.out and not captured.err
pin_shortcut.assert_called_once_with(script=test_py_script, label="Test label")
@pytest.mark.asyncio
async def test_pin_command_default_label(
mocker, capfd, mocked_android_modules, call_there_group, test_py_script
):
pin_shortcut = mocker.patch("android_here.pin_shortcut")
await call_there_group(["pin", test_py_script], "")
captured = capfd.readouterr()
assert not captured.out and not captured.err
pin_shortcut.assert_called_once_with(script=test_py_script, label="test.py")