Test utils misc load_template() (#396)
This commit is contained in:
@@ -77,9 +77,13 @@ def hms(seconds: int):
|
||||
|
||||
def load_template(path, scale_factor: float = 1.0, alpha: bool = False):
|
||||
if os.path.isfile(path):
|
||||
template_img = cv2.imread(path, cv2.IMREAD_UNCHANGED) if alpha else cv2.imread(path)
|
||||
template_img = cv2.resize(template_img, None, fx=scale_factor, fy=scale_factor, interpolation=cv2.INTER_NEAREST)
|
||||
return template_img
|
||||
try:
|
||||
template_img = cv2.imread(path, cv2.IMREAD_UNCHANGED) if alpha else cv2.imread(path)
|
||||
template_img = cv2.resize(template_img, None, fx=scale_factor, fy=scale_factor, interpolation=cv2.INTER_NEAREST)
|
||||
return template_img
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise ValueError(f"Could not load template: {path}")
|
||||
return None
|
||||
|
||||
def alpha_to_mask(img: np.ndarray):
|
||||
|
||||
18
test/utils/misc_test.py
Normal file
18
test/utils/misc_test.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
from logger import Logger
|
||||
from utils.misc import load_template
|
||||
|
||||
|
||||
class TestUtilsMisc:
|
||||
def setup_method(self):
|
||||
Logger.init()
|
||||
Logger.remove_file_logger()
|
||||
|
||||
@pytest.mark.parametrize("path, should_be_success", [
|
||||
("test/assets/hero_select.png", True),
|
||||
("some/random/path/that/not/a/file.png", False),
|
||||
])
|
||||
def test_load_template(self, path: str, should_be_success: bool):
|
||||
template_img = load_template(path, 1.0, alpha=True)
|
||||
success = template_img is not None
|
||||
assert(success == should_be_success)
|
||||
Reference in New Issue
Block a user