Skip to content

Conversation

ninsbl
Copy link
Member

@ninsbl ninsbl commented Sep 2, 2025

This PR appends semantic labels to the basename when expression is given for extraction of raster maps and handles fully qualified STRDS names more reliably. It also adds a pytest based testcase.

Fixes #6254

@ninsbl ninsbl requested review from echoix and wenzeslaus September 2, 2025 19:34
@ninsbl ninsbl added bug Something isn't working temporal Related to temporal data processing Python Related code is in Python libraries labels Sep 2, 2025
@ninsbl ninsbl added this to the 8.4.2 milestone Sep 2, 2025
Comment on lines +167 to +170
for k, v in expected_info.items():
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
Copy link
Member

Choose a reason for hiding this comment

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

Was the default behavior of pytest not enough for dictionaries when developing your tests?

(Like for a bad value, missing, and extra keys)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to check only a subset of the metadata keys. And unfortunately, it did not print out the key when I compared values are as expected. Are you aware of any build-in methods in pytest that would allow to test if a dictionary is covered by another (regardless of the order of keys and the like...)? I would be happy to adjust and drop the loop...

@github-actions github-actions bot added module tests Related to Test Suite labels Sep 2, 2025
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

I didn't check this 100%, but generally it looks good.

Comment on lines 118 to 120
# Make sure STRDS is in the expression referenced with fully qualified name
if sp.base.get_map_id() not in expression:
expression = expression.replace(sp.base.get_name(), sp.base.get_map_id())
Copy link
Member

Choose a reason for hiding this comment

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

You could confuse this by including one full name (id) and one name only like "abc@test1 + abc". I'm not sure how much it makes sense with how the inputs are handled. Based on the tests, it seems it does.

Related to that, you can have two "abc" in different mapsets. I don't know how that would be handled here, but maybe that's a separate issue from the one at hand.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Good catch. In 193207a I tried a different method using re.

verbose=True,
overwrite=True,
)
assert gisenv["MAPSET"] == "perc"
Copy link
Member

Choose a reason for hiding this comment

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

I lack explanation why this is tested. It is okay to test pre- and post-conditions. In this case, it looks wrong that this is tested at the end, while the values are acquired at the beginning (and not modified by anything).

verbose=True,
overwrite=True,
)
strds_info = gs.parse_key_val(tools.t_info(input=result, flags="g").text)
Copy link
Member

Choose a reason for hiding this comment

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

Does the following work for you or not?

Suggested change
strds_info = gs.parse_key_val(tools.t_info(input=result, flags="g").text)
strds_info = tools.t_info(input=result, flags="g").keyval

It will make a mix of strings and numbers instead of strings only.

Comment on lines +131 to +133
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
assert strds_info[k] == v, (
f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
)

Comment on lines +166 to +168
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
assert strds_info[k] == v, (
f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
)

Comment on lines +201 to +203
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
assert (
strds_info[k] == v
), f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
assert strds_info[k] == v, (
f"Expected value for key '{k}' is {v}. Got: {strds_info[k]}"
)

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

Labels

bug Something isn't working libraries module Python Related code is in Python temporal Related to temporal data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] t.rast.extract: expression fails with fully qualified STRDS name if STRDS and mapset name are identical

3 participants