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

Extend stray tag check #411

Merged
merged 5 commits into from
Oct 9, 2024

Conversation

dc-almeida
Copy link
Collaborator

Partial resolution of #401.
Expands on stray tag check in code names, adding checks for brackets for all code attributes.
Recursively checks list and dict attributes for strings.
Tests expanded.

@dc-almeida dc-almeida self-assigned this Oct 9, 2024
@dc-almeida dc-almeida marked this pull request as ready for review October 9, 2024 11:16
@dc-almeida dc-almeida added the enhancement New feature or request label Oct 9, 2024
Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

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

Nice, see a suggestion for cleaner test-code inline.

Also, I suggest to also add a test-case where a stray tag is in a attribute-string, like

- Primary Energy:
     definition: Total primary energy { consumption
     unit: EJ/yr

tests/data/codelist/stray_tag/char_in_str/variables.yaml Outdated Show resolved Hide resolved
tests/test_codelist.py Show resolved Hide resolved
@dc-almeida
Copy link
Collaborator Author

Nice, see a suggestion for cleaner test-code inline.

Also, I suggest to also add a test-case where a stray tag is in a attribute-string, like

- Primary Energy:
     definition: Total primary energy { consumption
     unit: EJ/yr

Initially I had added one, but removed it since the original test does so by checking for the stray tag in the code name. Can easliy add another more explicit one.

Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

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

One more little suggestionfor better error messages, then good to be merged.

if isinstance(value, str):
if any(char in value for char in forbidden):
raise ValueError(
f"Unexpected bracket in codelist: {code.name}."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"Unexpected bracket in codelist: {code.name}."
f"Unexpected bracket in {self.name} '{code.name}'."

@pytest.mark.parametrize(
"subfolder, match",
[
("char_in_str", r"Unexpected bracket in codelist: Primary Energy\|{Feul}"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
("char_in_str", r"Unexpected bracket in codelist: Primary Energy\|{Feul}"),
("char_in_str", r"Unexpected bracket in variable 'Primary Energy\|{Feul}'"),

"subfolder, match",
[
("char_in_str", r"Unexpected bracket in codelist: Primary Energy\|{Feul}"),
("char_in_list", r"Unexpected bracket in codelist: Share\|Coal"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
("char_in_list", r"Unexpected bracket in codelist: Share\|Coal"),
("char_in_list", r"Unexpected bracket in variable 'Share\|Coal'"),

[
("char_in_str", r"Unexpected bracket in codelist: Primary Energy\|{Feul}"),
("char_in_list", r"Unexpected bracket in codelist: Share\|Coal"),
("char_in_dict", r"Unexpected bracket in codelist: Primary Energy"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
("char_in_dict", r"Unexpected bracket in codelist: Primary Energy"),
("char_in_dict", r"Unexpected bracket in variable 'Primary Energy'"),

@dc-almeida dc-almeida merged commit e64ed34 into IAMconsortium:main Oct 9, 2024
10 checks passed
@dc-almeida dc-almeida deleted the extend-stray-tag-check branch December 17, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants