-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix/stray tags #163
Fix/stray tags #163
Conversation
In principle this should work but I would say that this check would be more logical as a validator in the |
Also testing errors more closely to where they originate is always a good idea. |
Looks good to me in principle! |
Thanks @luciecastella for implementing the suggested changes. I would have two additional recommendations then it should be fine from my side.
...
CodeList.from_directory("variable", TEST_DATA_DIR / "stray_tag" / "variable") instead of using |
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.
Looks almost ready to me, good work @luciecastella.
One comment below and two more general thoughts:
test_stray_tag_fails
would probably fit better intest_codelist
than intest_testing
as it no longer usesassert_valid_structure
.- Maybe you could add a hint to the user in the error message how the issue can be resolved. Perhaps something along the lines of "Check if the tag was spelled correctly or if it wrongly does not exist".
Agree with @phackstock about adding a hint on how to resolve, but I suggest to shorten it to
|
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.
Good to be merged from my side.
Co-authored-by: Daniel Huppmann <[email protected]>
tests/test_codelist.py
Outdated
def test_stray_tag_fails(): | ||
"""Check that typos in a tag raises expected error""" | ||
|
||
match = "Unexpected {} in codelist : Primary Energy|{Feul}" |
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.
Shouldn't this test now fail?
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.
why?
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.
Ah! Ok sorry got it. I thought the match
looks for this string in the error, and it does not matter if there are more characters. but maybe not... Should I change it?
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.
OK no you're right, something is wrong, thank you! I'll look into that
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.
Just played around for a minute, it seems that the :
does something to the match-validation.
I suggest to remove the whitespace, so that the test passes as expected (by failing with the right error message).
match = "Unexpected {} in codelist : Primary Energy|{Feul}" | |
match = "Unexpected {} in codelist: Primary Energy|{Feul}" |
And I suggest that you look into this more closely tomorrow (but not related to this PR), for your own knowledge...
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.
The match is interpreted as a regular expression and the character messing up the match is the pipe |
which is evaluated as or. To evaluate it as a literal pipe character you'll have to prefix it with a slash \
.
match = "Unexpected {} in codelist : Primary Energy\|{Feul}"
should fail as expected and
match = "Unexpected {} in codelist : Primary Energy|{Feul}" | |
match = "Unexpected {} in codelist: Primary Energy\|{Feul}" |
should be evaluated correctly and make the test pass.
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.
Great thank you!!
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.
Indeed, the pipe in the string allows for any string to pass the test. We actually need a double \\
to make it work :)
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.
Thanks, looks great!
Closes #128
The program now checks if processed codes still contain '{'
For now, the check is done in
definition.py
and not intesting.py
as discussed in the Issue because it uses existing function calls and checking intesting.py
would imply more code lines (I think). @danielhuppmann @phackstock do you think it is fine like this or should I relocate the test?