-
Notifications
You must be signed in to change notification settings - Fork 159
TST add visual regression tests #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac11d8d
tests: visual regression for the quickflat and webgl renderers
kroq-gar78 0ee0b0b
tests: the reference renders themselves
kroq-gar78 b730a29
webgl: propagate the failures that render a blank screen without raising
kroq-gar78 dcd4c24
tests: address review comments on gh-672
kroq-gar78 ef0076c
Addressing review for comments (verbosity, spelling)
kroq-gar78 bc98215
tests: render through make_png and save_3d_views directly
kroq-gar78 e8fe6c7
webgl: polling loop fixes, and put the tests where they belong
kroq-gar78 5fd63ee
tests: fail on a missing reference rather than skipping
kroq-gar78 b04719a
trim docstrings ugh
kroq-gar78 f2b7acb
tests: pin cortex.db to the bundled filestore
kroq-gar78 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cortex/tests/reference_images/**/*.webp filter=lfs diff=lfs merge=lfs -text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Pin ``cortex.db`` to the filestore bundled with pycortex. | ||
|
|
||
| The filestore is a configured path (``basic.filestore`` in ``options.cfg``), | ||
| so on a machine with a real filestore the suite would otherwise run against | ||
| whatever subjects that machine happens to have. Every test here uses the demo | ||
| subject ``S1``, and the reference renders in ``reference_images/`` are pixel | ||
| comparisons against the bundled one; a lab filestore with its own ``S1`` would | ||
| fail them for reasons that have nothing to do with the code under test, and | ||
| would collect flatmap caches along the way. | ||
| """ | ||
| import os | ||
| import sys | ||
|
|
||
| import cortex | ||
| from cortex import database, options | ||
|
|
||
|
|
||
| def _bundled_filestore(): | ||
| """The demo filestore shipped alongside the installed ``cortex`` package.""" | ||
| pkgdir = os.path.dirname(os.path.abspath(cortex.__file__)) | ||
| candidates = [ | ||
| # Source checkout or editable install: filestore/ sits beside cortex/. | ||
| os.path.join(pkgdir, os.pardir, "filestore", "db"), | ||
| # Installed: setup.py copies filestore/ to <install_base>/share/pycortex. | ||
| os.path.join(sys.prefix, "share", "pycortex", "db"), | ||
| ] | ||
| for path in candidates: | ||
| path = os.path.realpath(path) | ||
| if os.path.isdir(path): | ||
| return path | ||
| raise RuntimeError( | ||
| "could not locate the filestore bundled with pycortex; looked in " | ||
| + ", ".join(candidates) | ||
| ) | ||
|
|
||
|
|
||
| FILESTORE = _bundled_filestore() | ||
|
|
||
| options.config.set("basic", "filestore", FILESTORE) | ||
| database.default_filestore = FILESTORE | ||
| # The `filestore=default_filestore` defaults throughout database.py were bound | ||
| # at import, so the singleton has to be repointed by hand. Everything reached | ||
| # through it (SubjectDB and below) is passed `self.filestore` explicitly. | ||
| cortex.db.filestore = FILESTORE | ||
| cortex.db.reload_subjects() | ||
|
|
||
|
|
||
| def pytest_report_header(config): | ||
| return f"pycortex filestore: {FILESTORE}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Reference images | ||
|
|
||
| Stored renders that `cortex/tests/test_visual_regression.py` asserts against. | ||
|
|
||
| ## Contents | ||
|
|
||
| | directory | images | contents | | ||
| | --- | --- | --- | | ||
| | `alpha_dataviews/` | 10 | five of the six public dataview classes (`Volume`, `Vertex`, `Volume2D`, `VolumeRGB`, `VertexRGB`), both renderers | | ||
| | `nan_dataviews/` | 10 | the same five, with NaNs over roughly half the primary data channel | | ||
| | `nan_alpha_dataviews/` | 4 | `VolumeRGB`/`VertexRGB` only, with the NaNs in the `alpha=` map | | ||
| | `nonflat_views/` | 4 | `Volume`/`Vertex` on the inflated and fiducial surfaces at `lateral_pivot`, webgl only | | ||
|
|
||
| Filenames are `quickflat_<Class>` and `webgl_<Class>`, except `nonflat_views/`, | ||
| which uses `webgl_<surface>_<angle>_<Class>`. | ||
|
|
||
| `Vertex2D` is the sixth class and has no images: its webgl flatmap renders | ||
| blank (gh-714) and `save_3d_views` raises, so it cannot be tested through the | ||
| webgl path at all. The two `Vertex2D` tests are **xfailed** on that | ||
| `RuntimeError`, strictly — if the render ever succeeds the XPASS says so rather | ||
| than passing silently. | ||
|
|
||
| ## Render settings | ||
|
|
||
| The three flatmap directories render `quickflat_*` with | ||
| `cortex.quickflat.make_png` and `webgl_*` with `save_3d_views`, both with | ||
| curvature **un-thresholded** (`curvature_threshold=False` and | ||
| `surface.{subject}.curvature.smoothness=1.0`). (This is to avoid failures from | ||
| differences in the renderers' anti-aliasing implementations.) | ||
| Everything else is at its default. | ||
|
|
||
| `nonflat_views/` keeps pycortex's default thresholded curvature, unlike the | ||
| flatmap groups. | ||
|
|
||
| The exact keyword arguments are in `_render_and_check_dataview` and | ||
| `_render_and_check_webgl_only`; change either and the references must be | ||
| regenerated. | ||
|
|
||
| ## Checks | ||
|
|
||
| The three flatmap tests check each render twice: against its own stored | ||
| reference at a tight tolerance (`MAX_MEAN_ABS_DIFF`, `MAX_FRACTION_DIFFERING`, | ||
| `MAX_FRACTION_GROSSLY_DIFFERING`, `MAX_SSIM_LOSS`, all four of which must pass), | ||
| and against the other renderer's render of the same dataview at a loose one | ||
| (`CROSS_MAX_MEAN_ABS_DIFF`, `CROSS_MAX_FRACTION_DIFFERING`), with no stored | ||
| fixture. `test_visual_comparison_nonflat_views` runs the reference check only. | ||
|
|
||
| Both renderers write their flatmap content-tight and transparent outside it, so | ||
| the cross-renderer check only resizes webgl to quickflat's size before diffing. | ||
| RGB under fully transparent pixels is normalized first: it is undefined there, | ||
| and matplotlib leaves white where the browser leaves black. | ||
|
|
||
| ## Provenance | ||
|
|
||
| Generated on `main` (`3779f7ca`), from the demo subject `S1` in the filestore | ||
| bundled with pycortex, which is pinned by `cortex/tests/conftest.py`. | ||
|
|
||
| | | | | ||
| | --- | --- | | ||
| | chromium | 151.0.7922.34 (headless shell, SwiftShader software rendering) | | ||
| | playwright | 1.62.0 (fixes the chromium build above) | | ||
| | matplotlib | 3.10.9 | | ||
|
|
||
| Both are pinned in the `test` dependency group, and re-pinning is part of | ||
| regenerating. playwright fixes the chromium build, which determines the 16 webgl | ||
| references; matplotlib rasterizes the 12 quickflat ones. | ||
|
|
||
| Update matplotlib beyond 3.10.9 once Python 3.10 is dropped. | ||
|
|
||
| ## Format | ||
|
|
||
| Lossless WebP (`method=6`, `quality=100`, `exact=True`): bit-exact after decode, | ||
| and 59% the size of optimized PNG (1229 KiB versus 2061 KiB for the set of 28). | ||
|
|
||
| ## Storage | ||
|
|
||
| Tracked with **git LFS**. If yours are 130-byte text files rather than images, | ||
| the clone has not fetched them: | ||
|
|
||
| ``` | ||
| git lfs install && git lfs pull | ||
| ``` | ||
|
|
||
| The tests skip on that, and on the images being absent altogether, rather than | ||
| failing. | ||
|
|
||
| ## Distribution | ||
|
|
||
| Kept out of the wheel (`exclude_package_data` in `setup.py`) and kept in the | ||
| source tarball (`MANIFEST.in`'s `recursive-include cortex *`), so a run against | ||
| an installed wheel degrades gracefully. | ||
|
|
||
| ## Regenerating | ||
|
|
||
| The renders are deterministic: repeated runs on one machine produce | ||
| bit-identical output, including the WebGL ones under software rendering. They | ||
| are coupled to the Chromium and matplotlib builds above, so an upgrade can shift | ||
| anti-aliasing and rasterization; the tolerances absorb small shifts. If a | ||
| failure exceeds them, inspect the `diff_*.png` files it writes, confirm the | ||
| change is cosmetic, then: | ||
|
|
||
| ``` | ||
| REGENERATE_REFERENCE_IMAGES=1 pytest cortex/tests/test_visual_regression.py | ||
| ``` | ||
|
|
||
| That rewrites all four directories in one run. Review the resulting diff before | ||
| committing. |
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/quickflat_Vertex.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/quickflat_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/quickflat_Volume.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/quickflat_Volume2D.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/quickflat_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/webgl_Vertex.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/webgl_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/webgl_Volume.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/webgl_Volume2D.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/alpha_dataviews/webgl_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_alpha_dataviews/quickflat_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_alpha_dataviews/quickflat_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_alpha_dataviews/webgl_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_alpha_dataviews/webgl_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/quickflat_Vertex.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/quickflat_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/quickflat_Volume.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/quickflat_Volume2D.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/quickflat_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/webgl_Vertex.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/webgl_VertexRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/webgl_Volume.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/webgl_Volume2D.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
cortex/tests/reference_images/nan_dataviews/webgl_VolumeRGB.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...x/tests/reference_images/nonflat_views/webgl_fiducial_lateral_pivot_Vertex.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...x/tests/reference_images/nonflat_views/webgl_fiducial_lateral_pivot_Volume.webp
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.