-
Notifications
You must be signed in to change notification settings - Fork 27
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ venv/ | |
__pycache__/ | ||
*.stderr* | ||
docs/_* | ||
.hypothesis/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ linting = [ | |
"yamllint", | ||
] | ||
tests = [ | ||
"hypothesis", | ||
"pytest", | ||
"pytest-cov", | ||
] | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||||||||
"""Data-generating strategies for property-based testing.""" | ||||||||||
import hypothesis.strategies as st | ||||||||||
|
||||||||||
# Incomplete list of allowed spatial reference systems to generate data | ||||||||||
# - EPSG 4326 | ||||||||||
# - EPSG 3857 | ||||||||||
# ...? | ||||||||||
|
||||||||||
|
||||||||||
# EPSG:4326 primitives | ||||||||||
latitudes = st.floats( | ||||||||||
min_value=-90.0, | ||||||||||
max_value=90.0, | ||||||||||
allow_nan=False, | ||||||||||
allow_infinity=False, | ||||||||||
) | ||||||||||
longitudes = st.floats( | ||||||||||
min_value=-180.0, | ||||||||||
max_value=180.0, | ||||||||||
allow_nan=False, | ||||||||||
allow_infinity=False, | ||||||||||
) | ||||||||||
elevations = st.floats(allow_nan=False, allow_infinity=False) | ||||||||||
|
||||||||||
|
||||||||||
# Point2D | ||||||||||
@st.composite | ||||||||||
def points_2d(draw, srs="EPSG:4326"): | ||||||||||
if srs == "EPSG:4326": | ||||||||||
return draw(st.tuples(latitudes, longitudes)) | ||||||||||
raise NotImplementedError | ||||||||||
|
||||||||||
|
||||||||||
# Point3D | ||||||||||
@st.composite | ||||||||||
def points_3d(draw, srs="EPSG:4326"): | ||||||||||
if srs == "EPSG:4326": | ||||||||||
return draw(st.tuples(latitudes, longitudes, elevations)) | ||||||||||
raise NotImplementedError | ||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||
|
||||||||||
|
||||||||||
# PointType | ||||||||||
@st.composite | ||||||||||
def points(draw, srs="EPSG:4326"): | ||||||||||
if srs == "EPSG:4326": | ||||||||||
return draw(st.one_of(points_2d(), points_3d())) | ||||||||||
raise NotImplementedError | ||||||||||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||
|
||||||||||
|
||||||||||
# LineType | ||||||||||
|
||||||||||
# Geometries |
There was a problem hiding this comment.
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.