-
Notifications
You must be signed in to change notification settings - Fork 3
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
DAS-1892 - Add pycodestyle check to automated test suite. #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
coverage ~= 5.5 | ||
ipython ~= 8.0.1 | ||
jsonschema ~= 4.17.3 | ||
pycodestyle ~= 2.11.0 | ||
pylint >= 2.5.0 | ||
unittest-xml-reporting ~= 3.0.4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pathlib import Path | ||
from unittest import TestCase | ||
|
||
from pycodestyle import StyleGuide | ||
|
||
|
||
class TestCodeFormat(TestCase): | ||
""" This test class should ensure all earthdata-varinfo Python code adheres | ||
to standard Python code styling. | ||
|
||
Ignored errors and warnings: | ||
|
||
* E501: Line length, which defaults to 80 characters. This is a | ||
preferred feature of the code, but not always easily achieved. | ||
* W503: Break before binary operator. Have to ignore one of W503 or | ||
W504 to allow for breaking of some long lines. PEP8 suggests | ||
breaking the line before a binary operator is more "Pythonic". | ||
|
||
""" | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.python_files = Path('varinfo').rglob('*.py') | ||
|
||
def test_pycodestyle_adherence(self): | ||
""" Ensure all code in the `varinfo` directory adheres to PEP8 defined | ||
standards. | ||
|
||
""" | ||
style_guide = StyleGuide(ignore=['E501', 'W503']) | ||
results = style_guide.check_files(self.python_files) | ||
self.assertEqual(results.total_errors, 0, 'Found code style issues.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,8 +125,8 @@ class object. | |
mission_matches = re.match(mission, self.mission) is not None | ||
|
||
short_name_matches = ( | ||
short_name is None or | ||
re.match(short_name, self.short_name) is not None | ||
short_name is None | ||
or re.match(short_name, self.short_name) is not None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two changes in this file and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice! So to test if our code adheres to style requirements we would do something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The style check is now folded into the main test suite, so if you run If you wanted to run it separately, though, you could use |
||
) | ||
|
||
return mission_matches and short_name_matches | ||
|
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.
Not a nit or suggestion but what's this binary operator business about haha?
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.
Here's the biblical reference.
An example if this is whether you should have:
Or:
Ultimately the answer is that either are okay, so long as the code is consistently one or the other, with PEP008 stating a mild preference for the first option.
pycodestyle
is automatically configured to warn against both options, which is unhelpful, so the test ignores the checking of the one that is considered slightly preferred.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.
So either is okay (slight preference for the first) but you should keep it consistent and you turned off the check in
pycodestyle
for this?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.
Yeah - either is okay, but we should choose one and use it throughout the project. Then I turned off the warning for the one we went with. So that second example will still trigger a warning, but the first one won't.