-
Notifications
You must be signed in to change notification settings - Fork 316
Convert graphics testing conveniences to PyTest #5832
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
ESadek-MO
merged 9 commits into
SciTools:FEATURE_pytest_conversion
from
trexfeathers:graphics_tests_new
Mar 14, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5fbcd53
PyTest-compatible check_graphic.
trexfeathers 7c4f700
Demonstrate new check_graphic in test_plot.
trexfeathers 68f81ac
7c4f7003a
trexfeathers 94d7af9
Revert "7c4f7003a"
trexfeathers da7ee2a
Revert "Demonstrate new check_graphic in test_plot."
trexfeathers 2544c4a
Tidy up other unittest references in iris.tests.graphics.
trexfeathers e928e0e
Tidy up other unittest references in iris.tests.graphics.
trexfeathers dfd186b
check_graphic_caller docstring example.
trexfeathers db0da75
Make check_graphic_caller only accessible from conftest.
trexfeathers 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
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,53 @@ | ||
| # Copyright Iris contributors | ||
| # | ||
| # This file is part of Iris and is released under the BSD license. | ||
| # See LICENSE in the root of the repository for full licensing details. | ||
| """Top-level fixture infra-structure. | ||
|
|
||
| Before adding to this: consider if :mod:`iris.tests.unit.conftest` or | ||
| :mod:`iris.tests.integration.conftest` might be more appropriate. | ||
| """ | ||
| from collections import defaultdict | ||
|
|
||
| import pytest | ||
|
|
||
| import iris.tests.graphics | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", autouse=True) | ||
| def test_call_counter(): | ||
| """Provide a session-persistent tracker of the number of calls per test name. | ||
|
|
||
| Used by :func:`_unique_id` to ensure uniqueness if called multiple times | ||
| per test. | ||
| """ | ||
| counter = defaultdict(int) | ||
| return counter | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def _unique_id(request: pytest.FixtureRequest, test_call_counter) -> callable: | ||
| """Provide a function returning a unique ID of calling test and call number. | ||
|
|
||
| Example: ``iris.tests.unit.test_cube.TestCube.test_data.my_param.0`` | ||
|
|
||
| Used by :func:`iris.tests.graphics.check_graphic_caller` to ensure unique | ||
| image names. | ||
| """ | ||
| id_sequence = [request.module.__name__, request.node.originalname] | ||
| if request.cls is not None: | ||
| id_sequence.insert(-1, request.cls.__name__) | ||
| if hasattr(request.node, "callspec"): | ||
| id_sequence.append(request.node.callspec.id) | ||
| test_id = ".".join(id_sequence) | ||
|
|
||
| def generate_id(): | ||
| assertion_id = test_call_counter[test_id] | ||
| test_call_counter[test_id] += 1 | ||
| return f"{test_id}.{assertion_id}" | ||
|
|
||
| return generate_id | ||
|
|
||
|
|
||
| # Share this existing fixture from the expected location. | ||
| check_graphic_caller = iris.tests.graphics._check_graphic_caller |
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
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.