-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add collection mapping methods (#110)
* add collection mapping methods
- Loading branch information
Phil Varner
authored
Apr 19, 2024
1 parent
b64c612
commit 8d6dc7d
Showing
5 changed files
with
111 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,52 @@ | ||
from stactask.utils import find_collection, stac_jsonpath_match | ||
|
||
|
||
def test_stac_jsonpath_match() -> None: | ||
assert stac_jsonpath_match({"id": "1"}, "$[?(@.id =~ '.*')]") | ||
assert stac_jsonpath_match({"id": "1"}, "$[?(@.id == '1')]") | ||
assert not stac_jsonpath_match( | ||
{"properties": {"s2:processing_baseline": "04.00"}}, | ||
"$[?(@.properties.['s2:processing_baseline'] >= '05.00')]", | ||
) | ||
assert stac_jsonpath_match( | ||
{"properties": {"s2:processing_baseline": "05.00"}}, | ||
"$[?(@.properties.['s2:processing_baseline'] >= '05.00')]", | ||
) | ||
assert stac_jsonpath_match( | ||
{"properties": {"s2:processing_baseline": "04.00"}}, | ||
"$[?(@.properties.['s2:processing_baseline'] =~ '^04')]", | ||
) | ||
assert not stac_jsonpath_match( | ||
{"properties": {"s2:processing_baseline": "05.00"}}, | ||
"$[?(@.properties.['s2:processing_baseline'] =~ '^04')]", | ||
) | ||
|
||
|
||
def test_find_collection() -> None: | ||
assert find_collection({"a": "$[?(@.id =~ '.*')]"}, {"id": "1"}) == "a" | ||
assert ( | ||
find_collection( | ||
{"a": "$[?(@.id == '1')]", "b": "$[?(@.id == '2')]"}, {"id": "2"} | ||
) | ||
== "b" | ||
) | ||
assert ( | ||
find_collection( | ||
{ | ||
"sentinel-2-c1-l2a": "$[?(@.properties.['s2:processing_baseline'] >= '05.00')]", # noqa: E501 | ||
"sentinel-2-l2a-baseline-04": "$[?(@.properties.['s2:processing_baseline'] =~ '^04')]", # noqa: E501 | ||
}, | ||
{"properties": {"s2:processing_baseline": "04.00"}}, | ||
) | ||
== "sentinel-2-l2a-baseline-04" | ||
) | ||
assert ( | ||
find_collection( | ||
{ | ||
"sentinel-2-c1-l2a": "$[?(@.properties.['s2:processing_baseline'] >= '05.00')]", # noqa: E501 | ||
"sentinel-2-l2a-baseline-04": "$[?(@.properties.['s2:processing_baseline'] =~ '^04')]", # noqa: E501 | ||
}, | ||
{"properties": {"s2:processing_baseline": "05.00"}}, | ||
) | ||
== "sentinel-2-c1-l2a" | ||
) |