Skip to content

Commit

Permalink
Testing fixes (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 authored Jul 4, 2023
1 parent 7eb3a74 commit 52ab167
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/integration/template_directions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cd #expand expected_dir#expected_bundles
find . -type f -name '*.png' > ../image_list_expected_bundles.txt
cd <top level of zppy repo>
# Rerun test
python -u -m unittest tests/integration/test_bundles_#expand machine#.py
python -u -m unittest tests/integration/test_bundles.py
```

### test_campaign
Expand Down Expand Up @@ -83,7 +83,7 @@ cd #expand expected_dir#expected_complete_run
find . -type f -name '*.png' > ../image_list_expected_complete_run.txt
cd <top level of zppy repo>
# Rerun test
python -u -m unittest tests/integration/test_complete_run_#expand machine#.py
python -u -m unittest tests/integration/test_complete_run.py
```

### test_defaults
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def test_bundles_images(self):
expansions = get_expansions()
expected_dir = expansions["expected_dir"]
user_www = expansions["user_www"]
actual_images_dir = f"{user_www}zppy_test_bundles_www/v2.LR.historical_0201"
actual_images_dir = f"{user_www}zppy_test_bundles_www/v2.LR.historical_0201/"

# The expected_images_file lists all images we expect to compare.
expected_images_file = f"{expected_dir}image_list_expected_bundles.txt"
expected_images_dir = f"{expected_dir}expected_bundles"

# The directory to place differences in.
diff_dir = "tests/integration/image_check_failures_bundles"
diff_dir = f"{actual_images_dir}image_check_failures_bundles"

check_mismatched_images(
self, actual_images_dir, expected_images_file, expected_images_dir, diff_dir
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_complete_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def test_complete_run(self):
expected_dir = expansions["expected_dir"]
user_www = expansions["user_www"]
actual_images_dir = (
f"{user_www}zppy_test_complete_run_www/v2.LR.historical_0201"
f"{user_www}zppy_test_complete_run_www/v2.LR.historical_0201/"
)

# The expected_images_file lists all images we expect to compare.
expected_images_file = f"{expected_dir}image_list_expected_complete_run.txt"
expected_images_dir = f"{expected_dir}expected_complete_run"

# The directory to place differences in.
diff_dir = "tests/integration/image_check_failures_complete_run"
diff_dir = f"{actual_images_dir}image_check_failures_complete_run"

check_mismatched_images(
self, actual_images_dir, expected_images_file, expected_images_dir, diff_dir
Expand Down
14 changes: 9 additions & 5 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ def compare_images(
.getdata()
)
num_nonzero_pixels = sum(nonzero_pixels)
print("\npath_to_actual_png={}".format(path_to_actual_png))
print("path_to_expected_png={}".format(path_to_expected_png))
print("diff has {} nonzero pixels.".format(num_nonzero_pixels))
width, height = expected_png.size
num_pixels = width * height
print("total number of pixels={}".format(num_pixels))
fraction = num_nonzero_pixels / num_pixels
print("num_nonzero_pixels/num_pixels fraction={}".format(fraction))
# Fraction of mismatched pixels should be less than 0.02%
if fraction >= 0.0002:
print("\npath_to_actual_png={}".format(path_to_actual_png))
print("path_to_expected_png={}".format(path_to_expected_png))
print("diff has {} nonzero pixels.".format(num_nonzero_pixels))
print("total number of pixels={}".format(num_pixels))
print("num_nonzero_pixels/num_pixels fraction={}".format(fraction))

mismatched_images.append(image_name)

simple_image_name = image_name.split("/")[-1].split(".")[0]
Expand Down Expand Up @@ -113,6 +114,9 @@ def check_mismatched_images(
for i in mismatched_images:
print(i)

# Make diff_dir readable
os.system(f"chmod -R 755 {diff_dir}")

test.assertEqual(missing_images, [])
test.assertEqual(mismatched_images, [])

Expand Down

0 comments on commit 52ab167

Please sign in to comment.