Skip to content

Commit

Permalink
Compress images a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jan 25, 2022
1 parent 921e236 commit db1199b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update_references.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
git add docrepr/tests/references
git commit -m "Update references"
git commit -m "Update references for ${{ matrix.os }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _open_browser(url):

@pytest.fixture
async def compare_screenshots(request):
"""Do visual regression tests on the output."""
"""Run visual regression test on the output."""
async def _compare_screenshots(test_id, url):
if (request.config.getoption(COMPARE_SCREENSHOTS_OPTION) or
request.config.getoption(UPDATE_REFERENCE_SCREENSHOTS_OPTION)):
Expand Down Expand Up @@ -89,14 +89,18 @@ async def _compare_screenshots(test_id, url):
await page.screenshot(path=screenshot)
await browser.close()

# Compress the screenshot
screenshot_im = Image.open(screenshot).convert('RGB')
screenshot_im.save(screenshot, quality=80, optimize=True)

# If a reference update has been requested, we copy the screenshot
# and consider the test as "passing"
if request.config.getoption(UPDATE_REFERENCE_SCREENSHOTS_OPTION):
shutil.copyfile(screenshot, reference)
# Do not run the visual regression test
return

# Compare the screenshot with the reference
reference_im = Image.open(reference).convert('RGB')
screenshot_im = Image.open(screenshot).convert('RGB')
diff_im = ImageChops.difference(screenshot_im, reference_im)

bbox = diff_im.getbbox()
Expand Down

0 comments on commit db1199b

Please sign in to comment.