diff --git a/auto_derby/templates/Makefile b/auto_derby/templates/Makefile index 17e50a58..d8a9a25f 100644 --- a/auto_derby/templates/Makefile +++ b/auto_derby/templates/Makefile @@ -1,6 +1,10 @@ - - __init__.py: *.png __init__.py.gotmpl # http://github.com/NateScarlet/gotmpl ls *.png | jq -nR 'reduce inputs as $$item ([]; . + [$$item]) | { Files: . }' | gotmpl -o $@ __init__.py.gotmpl py -3.8 -m black -t py38 $@ + + +%.pos.png: + magick convert $@ -depth 1 $@ + + \ No newline at end of file diff --git a/auto_derby/templates/_test.py b/auto_derby/templates/_test.py new file mode 100644 index 00000000..5ae48340 --- /dev/null +++ b/auto_derby/templates/_test.py @@ -0,0 +1,15 @@ +from auto_derby import template +from pathlib import Path +from typing import Text + +import PIL.Image + +from .. import mathtools + +DATA_PATH = Path(__file__).parent / "test_data" + + +def use_screenshot(name: Text): + img = PIL.Image.open(DATA_PATH / name).convert("RGB") + template.g.screenshot_width = img.width + return img, mathtools.ResizeProxy(img.width) diff --git a/auto_derby/templates/single_mode_class_detail_button.png b/auto_derby/templates/single_mode_class_detail_button.png index bbc89cf0..55aeb502 100644 Binary files a/auto_derby/templates/single_mode_class_detail_button.png and b/auto_derby/templates/single_mode_class_detail_button.png differ diff --git a/auto_derby/templates/single_mode_class_detail_button.pos.png b/auto_derby/templates/single_mode_class_detail_button.pos.png index b160a0e3..c087730f 100644 Binary files a/auto_derby/templates/single_mode_class_detail_button.pos.png and b/auto_derby/templates/single_mode_class_detail_button.pos.png differ diff --git a/auto_derby/templates/single_mode_class_detail_button_test.py b/auto_derby/templates/single_mode_class_detail_button_test.py new file mode 100644 index 00000000..feb7da85 --- /dev/null +++ b/auto_derby/templates/single_mode_class_detail_button_test.py @@ -0,0 +1,21 @@ +from . import _test +from .. import template, templates, action + + +_EXPECTED_POS = (114, 165) + + +def test_match(): + img, rp = _test.use_screenshot("single_mode_command_scene.png") + res = tuple(template.match(img, templates.SINGLE_MODE_CLASS_DETAIL_BUTTON)) + assert len(res) == 1 + (match1,) = res + assert match1[1] == rp.vector2(_EXPECTED_POS, 540) + + +def test_match_issue135(): + img, rp = _test.use_screenshot("single_mode_command_scene_issue135.png") + res = tuple(template.match(img, templates.SINGLE_MODE_CLASS_DETAIL_BUTTON)) + assert len(res) == 1 + (match1,) = res + assert match1[1] == rp.vector2(_EXPECTED_POS, 540) diff --git a/auto_derby/templates/test_data/single_mode_command_scene.png b/auto_derby/templates/test_data/single_mode_command_scene.png new file mode 100644 index 00000000..536d9cc6 Binary files /dev/null and b/auto_derby/templates/test_data/single_mode_command_scene.png differ diff --git a/auto_derby/templates/test_data/single_mode_command_scene_issue135.png b/auto_derby/templates/test_data/single_mode_command_scene_issue135.png new file mode 100644 index 00000000..787ae101 Binary files /dev/null and b/auto_derby/templates/test_data/single_mode_command_scene_issue135.png differ