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

test: initial commit adding hypothesis property testing library #186

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

bpshaver
Copy link
Contributor

@bpshaver bpshaver commented Nov 5, 2023

Adding the Hypothesis cache dir to .gitignore
Grammar fixes in geometry.py
Hypothesis dep in pyproject.toml without version peg Initial strategies in conftest.py. This is the only file name I could use that didn't cause an issue with the name-tests-test pre-commit hook. 'strategies.py' would be better because strictly speaking these aren't fixtures. An example test for encode/decode invariance.

Adding the Hypothesis cache dir to .gitignore
Grammar fixes in geometry.py
Hypothesis dep in pyproject.toml without version peg
Initial strategies in conftest.py. This is the only file name I could use that didn't cause an issue with the name-tests-test pre-commit hook. 'strategies.py' would be better because strictly speaking these aren't fixtures.
An example test for encode/decode invariance.

WatermelonAI Summary

AI Summary deactivated by bpshaver

GitHub PRs

No results found in Jira Tickets :(

No results found in Confluence Docs :(

No results found in Slack Threads :(

No results found in Notion Pages :(

No results found in Linear Tickets :(

No results found in Asana Tasks :(

pygeoif is an open repo and Watermelon will serve it for free.
🍉🫶
Why not invite more people to your team?

@bpshaver bpshaver marked this pull request as draft November 5, 2023 23:34
Copy link

what-the-diff bot commented Nov 5, 2023

PR Summary

  • Update .gitignore File
    We've updated the .gitignore file to include .hypothesis, which will ensure that certain data won't be committed to the repository.

  • Improved Documentation
    Updates were made to the text descriptions ('docstrings') for the convex_hull method, as well as is_empty method for Point and LineString geometries. This will provide clearer guidelines and understanding for users and developers about these functionalities.

  • Update to pyproject.toml File
    This Pull Request adds hypothesis to the list of tools needed for the tests in the pyproject.toml file. This shows that hypothesis testing framework will be used in our testing process.

  • Addition of conftest.py to Tests
    A new conftest.py file was added to the tests directory. It includes strategies for generating test data, enhancing the scope and variety of our testing ecosystem.

  • Enhancements to test_point.py Test
    We've made some improvements to our test_point.py test. A new test function, test_repr_eval_hypothesis_epsg_4326, was added that uses the given decorator from hypothesis to generate test data. This function tests the repr and eval methods of Point geometry, enhancing the robustness of our test suite.

@bpshaver bpshaver mentioned this pull request Nov 5, 2023
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (ff2e39c) 100.00% compared to head (84ed536) 99.87%.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           179-add-hypothesis-tests     #186      +/-   ##
============================================================
- Coverage                    100.00%   99.87%   -0.13%     
============================================================
  Files                            21       22       +1     
  Lines                          2412     2437      +25     
============================================================
+ Hits                           2412     2434      +22     
- Misses                            0        3       +3     
Files Coverage Δ
pygeoif/geometry.py 100.00% <ø> (ø)
tests/test_point.py 100.00% <100.00%> (ø)
tests/conftest.py 84.21% <84.21%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cleder
Copy link
Owner

cleder commented Nov 6, 2023

I would prefer another file layout and not putting the strategies in conftests and keeping the hypothesis tests separate from the classic unit tests:

  • tests
    • test_point.py
    • test_linestring.py
    • ...
    • hypothesis
      • __init__.py
      • strategies.py
      • test_geometries.py
      • test_multigeometries.py
      • test_faetures.py
      • ...

The SRS could be defined as a dataclass like

@dataclass(frozen=True)
class Srs:
    name: str
    min_xyz : Tuple[float, float, Optional[float]]
    max_xyz : Tuple[float, float, Optional[float]]     

an instance of an srs can optionally be passed into the points, points_2d, points_3d strategies, if none is provided there would be no max_value, min_valueset for the st.floats

def points_3d(draw, srs: Optional[Srs]):
       ...

and

def points_2d(draw, srs: Optional[Srs] = None):
     easting = (None, None)
     northing = (None, None)
     elevation = (None, None)
     if srs:
         easting = (srs.min_xyz[0], srs.max_xyz[0]
         ...
epsg4326 = Srs(name="EPSG:4326", min_xyz =(-90, 0, None), max_xyz=(90, 180, None)

Hope that helps 👍 nice work

WatermelonAI Summary

AI Summary deactivated by bpshaver

GitHub PRs

No results found in Jira Tickets :(

No results found in Confluence Docs :(

No results found in Slack Threads :(

No results found in Notion Pages :(

No results found in Linear Tickets :(

No results found in Asana Tasks :(

pygeoif is an open repo and Watermelon will serve it for free.
🍉🫶

@cleder cleder changed the base branch from develop to 179-add-hypothesis-tests November 11, 2023 13:43
@cleder
Copy link
Owner

cleder commented Nov 13, 2023

You can add an 'exclude' to the name-tests-test pre-commit hook in .pre-commit-config.yaml

      - id: name-tests-test
        exclude: ^tests/hypothesis/strategies.py$

@cleder
Copy link
Owner

cleder commented Nov 30, 2023

Are you still working on this?

@bpshaver
Copy link
Contributor Author

Hi, sorry. Will try and get to this tomorrow. But if you want to press on ahead I won't be offended if you remove me from this issue.

@cleder
Copy link
Owner

cleder commented Dec 1, 2023

No, no worries, we all got a (private) life apart from coding, but I thought I'd better ask, as abandoning an issue is not uncommon.
I did not want to put pressure on you, just wanted clarification if it is still of interest

@cleder
Copy link
Owner

cleder commented Dec 9, 2023

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

Title

Integrate Hypothesis Testing Library and Improve Grammar in Comments


Type

Tests, Enhancement


Description

This PR integrates the Hypothesis property-based testing library into the project and adds new test strategies in the 'conftest.py' file. It also improves the grammar in the comments of the 'geometry.py' file. Additionally, a new test case using Hypothesis has been added in 'test_point.py'. The Hypothesis library has been added as a dependency in 'pyproject.toml'.


PR changes walkthrough

Relevant files                                                                                                                                 
Documentation
1 files
geometry.py                                                                                                 
    pygeoif/geometry.py

    Grammar in comments has been improved, specifically changing
    'less' to 'fewer' in three places.
+3/-3
Tests
2 files
conftest.py                                                                                                 
    tests/conftest.py

    New data-generating strategies for property-based testing
    have been added. These strategies generate data for
    latitudes, longitudes, elevations, 2D points, 3D points, and
    generic points.
+52/-0
test_point.py                                                                                             
    tests/test_point.py

    A new test case using Hypothesis has been added to test the
    representation and evaluation of points.
+9/-0
Dependencies
1 files
pyproject.toml                                                                                           
    pyproject.toml

    The Hypothesis library has been added as a dependency.
+1/-0
___ ## User description Adding the Hypothesis cache dir to .gitignore Grammar fixes in geometry.py Hypothesis dep in pyproject.toml without version peg Initial strategies in conftest.py. This is the only file name I could use that didn't cause an issue with the name-tests-test pre-commit hook. 'strategies.py' would be better because strictly speaking these aren't fixtures. An example test for encode/decode invariance.

@cleder
Copy link
Owner

cleder commented Dec 9, 2023

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Adding Hypothesis property testing library and modifying some grammar in the code.
  • 📝 PR summary: This PR introduces the Hypothesis property testing library into the project, adds it as a dependency in pyproject.toml, and includes some initial strategies for testing in conftest.py. Additionally, it modifies some grammar in the geometry.py file.
  • 📌 Type of PR: Tests
  • 🧪 Relevant tests added: Yes
  • ⏱️ Estimated effort to review [1-5]: 2, because the PR is relatively small and straightforward, mainly adding a new testing library and some initial testing strategies. The changes to the existing code are minor and mostly related to grammar.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are clear. The addition of the Hypothesis library for property testing is a good move for improving the robustness of the tests. However, it would be beneficial to include more comments in the conftest.py file to explain the purpose and usage of the strategies.

  • 🤖 Code feedback:
    • relevant file: tests/conftest.py
      suggestion: Consider adding more comments to explain the purpose and usage of the strategies. This will make it easier for other developers to understand and use them in the future. [medium]
      relevant line: """Data-generating strategies for property-based testing."""

    • relevant file: pygeoif/geometry.py
      suggestion: The grammar changes are correct, but it would be helpful to include a brief comment explaining why the change was made, for the sake of clarity. [medium]
      relevant line: is fewer than three.

How to use

Instructions

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review: Request a review of your Pull Request.
/describe: Update the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
/ask <QUESTION>: Ask a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.
/add_docs: Generate docstring for new components introduced in the PR.
/generate_labels: Generate labels for the PR based on the PR's contents.
see the tools guide for more details.

To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, add a /config comment.

@cleder
Copy link
Owner

cleder commented Dec 9, 2023

@CodiumAI-Agent /improve

Comment on lines +29 to +31
if srs == "EPSG:4326":
return draw(st.tuples(latitudes, longitudes))
raise NotImplementedError

Choose a reason for hiding this comment

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

Suggestion: Wrap the validation logic inside a function for better reusability and readability.

Suggested change
if srs == "EPSG:4326":
return draw(st.tuples(latitudes, longitudes))
raise NotImplementedError
def validate_srs(srs, draw, strategy):
if srs == "EPSG:4326":
return draw(strategy)
raise NotImplementedError
validate_srs(srs, draw, st.tuples(latitudes, longitudes))

Comment on lines +37 to +39
if srs == "EPSG:4326":
return draw(st.tuples(latitudes, longitudes, elevations))
raise NotImplementedError

Choose a reason for hiding this comment

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

Suggestion: The validation logic is repeated in multiple places. Consider creating a helper function to avoid repetition.

Suggested change
if srs == "EPSG:4326":
return draw(st.tuples(latitudes, longitudes, elevations))
raise NotImplementedError
validate_srs(srs, draw, st.tuples(latitudes, longitudes, elevations))

Comment on lines +45 to +47
if srs == "EPSG:4326":
return draw(st.one_of(points_2d(), points_3d()))
raise NotImplementedError

Choose a reason for hiding this comment

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

Suggestion: The validation logic is repeated. Consider creating a helper function to avoid repetition.

Suggested change
if srs == "EPSG:4326":
return draw(st.one_of(points_2d(), points_3d()))
raise NotImplementedError
validate_srs(srs, draw, st.one_of(points_2d(), points_3d()))

@cleder cleder merged commit 84ed536 into cleder:179-add-hypothesis-tests Mar 20, 2024
21 of 24 checks passed
@cleder
Copy link
Owner

cleder commented Mar 26, 2024

you may be interested in #219 or #220 ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants