Skip to content

Commit

Permalink
Add changed_screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Brody committed Sep 17, 2024
1 parent bd6ef88 commit a2bbbe8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ jobs:
with:
name: delta-${{ matrix.test-file }}
path: react/delta
- uses: actions/upload-artifact@v4
if: "!cancelled()"
with:
name: changed_screenshots-${{ matrix.test-file }}
path: react/changed_screenshots

merge-screenshots:
runs-on: ubuntu-22.04
Expand All @@ -153,8 +158,13 @@ jobs:
name: delta
pattern: "delta-*"
continue-on-error: true
- uses: actions/upload-artifact/merge@v4
with:
name: changed_screenshots
pattern: "changed_screenshots-*"
continue-on-error: true
- uses: actions/upload-artifact/merge@v4
with:
name: combined
pattern: "{screenshots,delta}"
pattern: "{screenshots,delta,changed_screenshots}"
separate-directories: true
4 changes: 3 additions & 1 deletion react/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
screenshots
delta
delta
changed_screenshots
videos
31 changes: 22 additions & 9 deletions tests/check_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,46 @@ def compute_delta_image(ref, act):
delta = np.concatenate([ref, indicator], axis=1)
return diff_mask.any(), delta

def test_paths(reference, actual, delta_path):
def test_paths(reference, actual, delta_path, changed_path):
ref = np.array(Image.open(reference))
act = np.array(Image.open(actual))
diff, delta = compute_delta_image(ref, act)
if diff:
try:
os.makedirs(os.path.dirname(delta_path))
except FileExistsError:
pass
os.makedirs(os.path.dirname(delta_path), exist_ok=True)
Image.fromarray(delta).save(delta_path)
print(f"{reference} and {actual} are different")
os.makedirs(os.path.dirname(changed_path), exist_ok=True)
shutil.copy(actual, changed_path)
return False
else:
return True

def test_all_same(reference, actual, delta):
def test_all_same(reference, actual, delta, changed):
shutil.rmtree(delta, ignore_errors=True)
errors = 0
for root, dirs, files in os.walk(actual):
for file in files:
actual_path = os.path.join(root, file)
relative = os.path.relpath(actual_path, actual)
reference_path = os.path.join(reference, relative)
changed_path = os.path.join(changed, relative)
if not os.path.isfile(reference_path):
errors += 1
print(f"Expected reference file {reference_path} not found")
os.makedirs(os.path.dirname(changed_path), exist_ok=True)
shutil.copy(actual_path, changed_path)
for root, dirs, files in os.walk(reference):
for file in files:
reference_path = os.path.join(root, file)
relative = os.path.relpath(reference_path, reference)
actual_path = os.path.join(actual, relative)
changed_path = os.path.join(changed, relative)
if not os.path.isfile(actual_path):
errors += 1
print(f"Expected actual file {actual_path} not found")
continue
delta_path = os.path.join(delta, relative)
errors += not test_paths(reference_path, actual_path, delta_path)
errors += not test_paths(reference_path, actual_path, delta_path, changed_path)
if errors:
print(f"{errors} errors found")
exit(1)
Expand All @@ -107,6 +110,16 @@ def test_all_same(reference, actual, delta):
p.add_argument("--test", required=False)
args = p.parse_args()
if args.test:
test_all_same(reference=f"reference_test_screenshots/{args.test}", actual=f"react/screenshots/{args.test}", delta=f"react/delta/{args.test}")
test_all_same(
reference=f"reference_test_screenshots/{args.test}",
actual=f"react/screenshots/{args.test}",
delta=f"react/delta/{args.test}"
changed=f"react/changed_screenshots/{args.test}"
)
else:
test_all_same(reference="reference_test_screenshots", actual="react/screenshots", delta="react/delta")
test_all_same(
reference="reference_test_screenshots",
actual="react/screenshots",
delta="react/delta"
changed=f"react/changed_screenshots"
)

0 comments on commit a2bbbe8

Please sign in to comment.