-
Notifications
You must be signed in to change notification settings - Fork 90
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
Reduces code complexity in one part of weather_symbols.py. #1391
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1391 +/- ##
==========================================
- Coverage 96.34% 96.34% -0.01%
==========================================
Files 89 89
Lines 7579 7578 -1
==========================================
- Hits 7302 7301 -1
Misses 277 277
Continue to review full report at Codecov.
|
">=": "<", | ||
">": "<=", | ||
"OR": "AND", | ||
"": "", |
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 this one?
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 simpler conditions don't have a comparator (AND and OR), so we need the ability to return an empty string too. This could be an if test in the calling function instead.
"""Test that the _invert_comparator method raises an error when the condition | ||
cannot be inverted.""" | ||
plugin = WeatherSymbols() | ||
possible_inputs = ["==", "!=", "NOT", "XOR"] |
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.
Hmm - but you could have any of these conditions in your dictionary. (Although the test is valid.)
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.
My thinking is that if we add any of these to that dictionary, then this test will force us to update the unit-tests. Codecov does not check that every entry in a dictionary is touched, only that every line of code is touched.
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.
This looks like a nicer way of doing this, using a dictionary rather than lots of conditions, and tidies up the call somewhat.
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.
I've looked through these changes and they all look good to me! The tests all run through fine as well.
) * Reduces code complexity in one part of weather_symbols.py. * Refactors the dict definition so it is only performed once. * Adds unit test for new error message. * Removes == from list of invertible conditions, as it was wrong and isn't used anyway. * Proves == raises the error too * Improves doc-string
In an attempt to apply some Python training, I've refactored the "invert_condition" function in WeatherSymbols to remove an if..elif..elif..elif block. The code will no longer allow unrecognised comparators rather than returning them unchanged.
Testing: