Skip to content
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

tests: add first approval tests #453

Merged
merged 6 commits into from
Jun 5, 2024
Merged

tests: add first approval tests #453

merged 6 commits into from
Jun 5, 2024

Conversation

matthiasschaub
Copy link
Collaborator

@matthiasschaub matthiasschaub commented May 2, 2024

  • for area calculation choose CRS valid world-wide not just UTM
  • Choose threshold for area ratio
  • Make approval tests work with parametrized fixtures

Leads to test duplication. Will be fixed in another PR. -> #456

@matthiasschaub matthiasschaub marked this pull request as draft May 2, 2024 13:37
if not Path(approved_path).exists() or Path(approved_path).stat().st_size == 0:
return False

# TODO: find optimal UTM for every feature or different projection
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8857 seems to be an okay projection

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I am going to use it.

Comment on lines +14 to +12
def vector_path(tmp_path_factory, uuid_digitize) -> bytes:
return tmp_path_factory.getbasetemp() / uuid_digitize / "vector.geojson"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does tmp_path_factory come from? Do I just not see it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its pytest magic. Its a global fixture defined by pytest. No import needed.

(The other fixtures are also not imported but defined by us in conftest.py which is discovered and parsed by pytest magic as well)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_path_factory gives as a tmp dir unique to the current test run

@matthiasschaub
Copy link
Collaborator Author

For parametrized fixtures in a tests following error gets raised after the first test run (first parameter):

    def test_smt_approver(sketch_map_marked_path, vector_path):
        options = (
            Options()
            .with_reporter(SketchMapToolReporter(sketch_map=sketch_map_marked_path))
            .with_comparator(GeoJSONComparator())
        )
        with open(vector_path, "rb") as f:
>           verify_binary(f.read(), ".geojson", options=options)
E           approvaltests.approval_exception.ApprovalException: We noticed that you called verify more than once in the same test. 
E           This is the second call to verify:
E               approved_file: /home/matthias/work/smt/tests/integration/test_approval.test_smt_approver.approved.geojson
E           
E           By default, ApprovalTests only allows one verify() call per test.
E           To find out more, visit: 
E           https://github.com/approvals/ApprovalTests.Python/blob/main/docs/how_to/multiple_approvals_per_test.md
E           
E           # Possible Fixes
E           1. Separate your test into two tests
E           2. In your verify call, add `options=NamerFactory.with_parameters("your_paramater")`
E           3. In your test, call `approvals.settings().allow_multiple_verify_calls_for_this_method()`

@matthiasschaub matthiasschaub changed the title Approval tests tests: add first approval tests May 23, 2024
@matthiasschaub matthiasschaub marked this pull request as ready for review May 23, 2024 09:11
@matthiasschaub matthiasschaub requested a review from koebi May 23, 2024 09:11
@matthiasschaub matthiasschaub merged commit 649d6ad into main Jun 5, 2024
1 check passed
@matthiasschaub matthiasschaub deleted the approval-tests branch June 5, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants