Working harvesting detection, working manufacturing detection.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import analyze
|
||||
|
||||
ALL_IMAGES = (
|
||||
sorted(Path("tests/images/harvesting").glob("*.png"))
|
||||
+ sorted(Path("tests/images/not_harvesting").glob("*.png"))
|
||||
)
|
||||
|
||||
assert len(ALL_IMAGES) > 0, "no images found under tests/images"
|
||||
|
||||
# Inventory capacity was observed to change as the player collects items.
|
||||
# Frames not listed here are expected to read 106.
|
||||
INVENTORY_EXPECTED = {
|
||||
"frame_00000.png": 110,
|
||||
"frame_00001.png": 110,
|
||||
"frame_00002.png": 108,
|
||||
"frame_00003.png": 108,
|
||||
}
|
||||
|
||||
OCR_AVAILABLE = analyze.pytesseract is not None and shutil.which("tesseract") is not None
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not OCR_AVAILABLE,
|
||||
reason="pytesseract or tesseract-ocr not installed",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def bar_values():
|
||||
values = {}
|
||||
for path in ALL_IMAGES:
|
||||
image = analyze.load_image(path)
|
||||
assert image is not None, f"cannot load {path}"
|
||||
values[path.name] = analyze.read_bar_values(image)
|
||||
return values
|
||||
|
||||
|
||||
def test_mana_is_32(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
assert values["mana"] == 32, name
|
||||
|
||||
|
||||
def test_food_is_39(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
assert values["food"] == 39, name
|
||||
|
||||
|
||||
def test_health_is_40(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
assert values["health"] == 40, name
|
||||
|
||||
|
||||
def test_action_points_are_140(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
assert values["action_points"] == 140, name
|
||||
|
||||
|
||||
def test_inventory_matches_expected(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
expected = INVENTORY_EXPECTED.get(name, 106)
|
||||
assert values["inventory"] == expected, name
|
||||
|
||||
|
||||
def test_every_bar_has_a_value(bar_values):
|
||||
for name, values in bar_values.items():
|
||||
assert all(v is not None for v in values.values()), name
|
||||
Reference in New Issue
Block a user