Skip to content

Commit

Permalink
tests(intergration): reproducible master image
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Jul 5, 2024
1 parent eae9177 commit 7cda2bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Binary file modified tests/data/mosaic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions tests/integration/test_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DATA_DIR = Path(__file__).parents[1] / "data"
FACES_TAR = DATA_DIR / "faces.tar.gz"
EXPECTED_MOSAIC = DATA_DIR / "mosaic.png"
UPDATE_EXPECTED_IMG = os.getenv("PHOMO_UPDATE_EXPECTED_IMG", False)


def is_within_directory(directory, target):
Expand Down Expand Up @@ -41,19 +42,21 @@ def faces_dir(tmp_path):

@pytest.fixture
def master_file(faces_dir):
return list((faces_dir).glob("*"))[1000]
return sorted(list((faces_dir).glob("*")))[1000]


def test__mosaic_faces(faces_dir, master_file):
pool = Pool.from_dir(faces_dir, crop_ratio=1, tile_size=(20, 20))
master = Master.from_file(master_file, crop_ratio=1, img_size=(200, 200))
mosaic = Mosaic(master, pool)
mosaic_img = mosaic.build(mosaic.d_matrix(workers=2))
if UPDATE_EXPECTED_IMG:
mosaic_img.save(EXPECTED_MOSAIC)
assert np.allclose(np.array(mosaic_img), np.array(Image.open(EXPECTED_MOSAIC)))


def test__mosaic_faces_cli(faces_dir, master_file, tmp_path):
outfile = tmp_path / "mosaic.png"
outfile: Path = tmp_path / "mosaic.png"
subprocess.run(
f"phomo {str(master_file)} {str(faces_dir)} -c 1 -s 200 200 -C 1 -S 20 20 -o {str(outfile)}",
check=True,
Expand Down

0 comments on commit 7cda2bf

Please sign in to comment.