Files
my-botty/test/test_ui_meters.py

41 lines
1.3 KiB
Python

"""
Tests for ui.meters — health/mana/merc health reading.
These test the math: given a known image, the percentage should be deterministic.
"""
import pytest
import numpy as np
import cv2
from logger import Logger
from config import Config
class TestMeters:
def setup_method(self):
Logger.init()
Logger.remove_file_logger()
def test_get_health_returns_value_between_0_and_1(self):
from ui.meters import get_health
# All-white image — no red/green pixels, so health = 0
img = np.full((720, 1280, 3), 255, dtype=np.uint8)
result = get_health(img)
assert 0.0 <= result <= 1.0
def test_get_mana_returns_value_between_0_and_1(self):
from ui.meters import get_mana
img = np.full((720, 1280, 3), 255, dtype=np.uint8)
result = get_mana(img)
assert 0.0 <= result <= 1.0
def test_get_merc_health_returns_value_between_0_and_1(self):
from ui.meters import get_merc_health
img = np.full((720, 1280, 3), 255, dtype=np.uint8)
result = get_merc_health(img)
assert 0.0 <= result <= 1.0
def test_get_merc_health_black_image_is_zero(self):
from ui.meters import get_merc_health
img = np.zeros((720, 1280, 3), dtype=np.uint8)
result = get_merc_health(img)
assert result == 0.0