-
Notifications
You must be signed in to change notification settings - Fork 11
Add $geometry tests #220
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
Open
PatersonProjects
wants to merge
9
commits into
documentdb:main
Choose a base branch
from
PatersonProjects:geometry_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add $geometry tests #220
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf12f24
Converted tests to use QueryTestCase
PatersonProjects 5e7e832
Added missing coverage, removed duplicates, reorganized tests for cla…
PatersonProjects 7fb1a4a
Edited test msg
PatersonProjects dd3a3bc
Added extra coverage
PatersonProjects 0b2f770
Merge branch 'main' into geometry_tests
PatersonProjects c04699c
PR Comments, second wave of changes
PatersonProjects 82f7094
Merge branch 'main' into geometry_tests
PatersonProjects faacff6
Addressing PR comments
PatersonProjects 9304f77
Removed out of scope tests, replaced geowithin with geointersects
PatersonProjects 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
Empty file.
107 changes: 107 additions & 0 deletions
107
...sts/core/operator/query/geospatial/specifiers/geometry/test_geometry_argument_handling.py
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 @@ | ||
| """Tests for $geometry valid argument handling — | ||
| valid structures, field ordering, and CRS.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.operator.query.utils.query_test_case import ( | ||
| QueryTestCase, | ||
| ) | ||
| from documentdb_tests.framework.assertions import assertSuccess | ||
| from documentdb_tests.framework.executor import execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
|
|
||
| STRICT_CRS = { | ||
| "type": "name", | ||
| "properties": {"name": "urn:x-mongodb:crs:strictwinding:EPSG:4326"}, | ||
| } | ||
|
|
||
| VALID_GEOMETRY_TESTS: list[QueryTestCase] = [ | ||
| QueryTestCase( | ||
| id="valid_point", | ||
| filter={"loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}, | ||
| doc=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| msg="Should accept valid Point $geometry", | ||
| ), | ||
| QueryTestCase( | ||
| id="extra_field_in_geometry", | ||
| filter={ | ||
| "loc": { | ||
| "$geoIntersects": { | ||
| "$geometry": {"type": "Point", "coordinates": [0, 0], "extra": 1} | ||
| } | ||
| } | ||
| }, | ||
| doc=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| msg="Should ignore extra fields in $geometry", | ||
| ), | ||
| QueryTestCase( | ||
| id="coordinates_before_type", | ||
| filter={"loc": {"$geoIntersects": {"$geometry": {"coordinates": [0, 0], "type": "Point"}}}}, | ||
| doc=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| msg="Should accept coordinates before type (field order doesn't matter)", | ||
| ), | ||
| QueryTestCase( | ||
| id="array_value_as_legacy_coordinates", | ||
| filter={"loc": {"$geoIntersects": {"$geometry": [0, 0]}}}, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [50, 50]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| msg="$geometry: array value should be treated as a legacy coordinate pair", | ||
| ), | ||
| QueryTestCase( | ||
| id="multiple_extra_fields", | ||
| filter={ | ||
| "loc": { | ||
| "$geoIntersects": { | ||
| "$geometry": { | ||
| "type": "Point", | ||
| "coordinates": [1, 1], | ||
| "bbox": [-1, -1, 1, 1], | ||
| "id": "test", | ||
| "properties": {"name": "foo"}, | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [1, 1]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [50, 50]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [1, 1]}}], | ||
| msg="Should ignore multiple extra fields (bbox, id, properties) in $geometry", | ||
| ), | ||
| QueryTestCase( | ||
| id="crs_with_geoIntersects", | ||
| filter={ | ||
| "loc": { | ||
| "$geoIntersects": { | ||
| "$geometry": { | ||
| "type": "Polygon", | ||
| "coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], | ||
| "crs": STRICT_CRS, | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0.5, 0.5]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [5, 5]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0.5, 0.5]}}], | ||
| msg="Should accept custom CRS with $geoIntersects", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(VALID_GEOMETRY_TESTS)) | ||
| def test_geometry_argument_handling(collection, test): | ||
| """Verifies $geometry accepts valid GeoJSON structures.""" | ||
| collection.create_index([("loc", "2dsphere")]) | ||
| collection.insert_many(test.doc) | ||
| result = execute_command(collection, {"find": collection.name, "filter": test.filter}) | ||
| assertSuccess(result, test.expected, msg=test.msg) | ||
138 changes: 138 additions & 0 deletions
138
...core/operator/query/geospatial/specifiers/geometry/test_geometry_coordinate_boundaries.py
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,138 @@ | ||
| """Tests for $geometry valid coordinate boundary values — longitude/latitude limits, | ||
| poles, longitude non-equivalence at antimeridian, pole longitude equivalence, | ||
| origin, negative coordinates, and high-precision coordinates.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.operator.query.utils.query_test_case import ( | ||
| QueryTestCase, | ||
| ) | ||
| from documentdb_tests.framework.assertions import assertSuccess | ||
| from documentdb_tests.framework.executor import execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
|
|
||
| VALID_BOUNDARY_TESTS: list[QueryTestCase] = [ | ||
| QueryTestCase( | ||
| id="longitude_negative_180", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [-180, 0]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [-180, 0]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [-180, 0]}}], | ||
| msg="Should accept longitude = -180", | ||
| ), | ||
| QueryTestCase( | ||
| id="longitude_positive_180", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [180, 0]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [180, 0]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [180, 0]}}], | ||
| msg="Should accept longitude = 180", | ||
| ), | ||
| QueryTestCase( | ||
| id="latitude_negative_90", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [0, -90]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0, -90]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, -90]}}], | ||
| msg="Should accept latitude = -90", | ||
| ), | ||
| QueryTestCase( | ||
| id="origin_zero_zero", | ||
| filter={"loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [0, 0]}}}}, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [45, 45]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [0, 0]}}], | ||
| msg="Should accept coordinates at origin (0, 0)", | ||
| ), | ||
| QueryTestCase( | ||
| id="negative_coordinates", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [-45, -45]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [-45, -45]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [45, 45]}}, | ||
| ], | ||
| expected=[{"_id": 1, "loc": {"type": "Point", "coordinates": [-45, -45]}}], | ||
| msg="Should accept negative longitude and latitude", | ||
| ), | ||
| QueryTestCase( | ||
| id="lng_180_does_not_match_negative_180", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [180, 0]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [-180, 0]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [180, 0]}}, | ||
| ], | ||
| expected=[{"_id": 2, "loc": {"type": "Point", "coordinates": [180, 0]}}], | ||
| msg="Longitude 180 and -180 should not be treated as equivalent (strict numeric)", | ||
| ), | ||
| QueryTestCase( | ||
| id="north_pole_any_longitude", | ||
| filter={ | ||
| "loc": {"$geoIntersects": {"$geometry": {"type": "Point", "coordinates": [0, 90]}}} | ||
| }, | ||
| doc=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0, 90]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [180, 90]}}, | ||
| {"_id": 3, "loc": {"type": "Point", "coordinates": [-90, 90]}}, | ||
| {"_id": 4, "loc": {"type": "Point", "coordinates": [0, 0]}}, | ||
| ], | ||
| expected=[ | ||
| {"_id": 1, "loc": {"type": "Point", "coordinates": [0, 90]}}, | ||
| {"_id": 2, "loc": {"type": "Point", "coordinates": [180, 90]}}, | ||
| {"_id": 3, "loc": {"type": "Point", "coordinates": [-90, 90]}}, | ||
| ], | ||
| msg="At the North Pole (lat=90), longitude is irrelevant — all pole points should match", | ||
| ), | ||
| QueryTestCase( | ||
| id="high_precision_coordinates", | ||
| filter={ | ||
| "loc": { | ||
| "$geoIntersects": { | ||
| "$geometry": { | ||
| "type": "Point", | ||
| "coordinates": [1.123456789012345, 2.123456789012345], | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| doc=[ | ||
| { | ||
| "_id": 1, | ||
| "loc": {"type": "Point", "coordinates": [1.123456789012345, 2.123456789012345]}, | ||
| }, | ||
| ], | ||
| expected=[ | ||
| { | ||
| "_id": 1, | ||
| "loc": {"type": "Point", "coordinates": [1.123456789012345, 2.123456789012345]}, | ||
| }, | ||
| ], | ||
| msg="Should accept high-precision coordinates (15+ decimal places)", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(VALID_BOUNDARY_TESTS)) | ||
| def test_geometry_coordinate_boundaries(collection, test): | ||
| """Verifies $geometry accepts coordinates at valid boundary values.""" | ||
| collection.create_index([("loc", "2dsphere")]) | ||
| collection.insert_many(test.doc) | ||
| result = execute_command(collection, {"find": collection.name, "filter": test.filter}) | ||
| assertSuccess(result, test.expected, msg=test.msg, ignore_doc_order=True) |
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.