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
Resolve flake8 violations in tests/ #428
Conversation
tests/test_clamav.py:58:89: E501 line too long (90 > 88 characters) tests/test_containers.py:38:9: F841 local variable 'dummy' is assigned to but never used tests/test_dummy.py:35:9: F841 local variable 'dummy' is assigned to but never used tests/test_ftpparse.py:94:89: E501 line too long (96 > 88 characters) tests/test_url.py:128:89: E501 line too long (130 > 88 characters) tests/test_strformat.py:62:9: E741 ambiguous variable name 'l' tests/test_strformat.py:136:9: E731 do not assign a lambda expression, use a def tests/checker/ftpserver.py:94:9: E722 do not use bare 'except' tests/checker/httpserver.py:55:39: E231 missing whitespace after ',' tests/checker/httpserver.py:224:9: E722 do not use bare 'except' tests/checker/telnetserver.py:84:9: E722 do not use bare 'except' tests/checker/__init__.py:71:89: E501 line too long (119 > 88 characters) tests/checker/__init__.py:292:13: E741 ambiguous variable name 'l' tests/checker/test_http_misc.py:30:1: W293 blank line contains whitespace tests/checker/test_https.py:21:1: F401 'tests.need_network' imported but unused tests/checker/test_news.py:35:1: E302 expected 2 blank lines, found 1
maybe this should also enforce black or at least pep8 in CI since we seem to have completely converted the codebase... |
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.
What do you know, I did get to the end! And before breakfast!
Most of the changes are great, some need little tweaks.
tests/cache/test_urlqueue.py
Outdated
aggregate=Aggregate( | ||
result_cache=self.result_cache, | ||
), | ||
aggregate=Aggregate(result_cache=self.result_cache,), |
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.
Black is wonderful, but it does make bad decisions sometimes.
aggregate=Aggregate(result_cache=self.result_cache,), | |
aggregate=Aggregate(result_cache=self.result_cache), |
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.
Done.
tests/cache/test_urlqueue.py
Outdated
aggregate=Aggregate( | ||
result_cache=self.result_cache, | ||
), | ||
aggregate=Aggregate(result_cache=self.result_cache,), |
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.
There are many unnecessary trailing commas like 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.
Well, "many" ~= 6 or 7, in this file, all about Aggregate(...,)
, so should be easy to search-and-replace fix.
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.
git grep ',)'
confirms that there are Aggregates here and one dict literal in
tests/checker/test_httpbin.py: entry = dict(user=user, password=password, pattern=re.compile(r".*"),)
that have the bad trailing comma right in front of the closing parenthesis. All other trailing commas like this are in 1-tuples, where they belong.
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.
Another manual check to add to the process.
tests/checker/__init__.py
Outdated
[ | ||
"url %s" % x.strip() | ||
for x in re.split( | ||
r"^url .*?", |
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.
One advantage to black making the code readable: I can actually read it now, and see that this is equivalent to re.split("^url ", ...)
. The non-greedy .*? never needs to match anything and so always matches the empty string.
r"^url .*?", | |
r"^url ", |
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.
Done.
self.result.append("baseurl %s" % url_data.base_ref) | ||
if self.has_part('info'): | ||
if self.has_part("info"): |
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 hate the noise Black creates by changing the quote characters on all the strings. And they make the diff so huge. I'm sure I'll give up somewhere in the middle.
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 also find this change annoying, because i usually type single quotes because they are faster (one keystroke instead of shift+keystroke) on my keyboard.
the black docs have a section on this:
https://black.readthedocs.io/en/stable/the_black_code_style.html#strings
their argument ias that double-quotes are less ambiguous and that you can always type single quotes and let black fix the formatting if you don't like to type double-quotes, which is reasonable.
That said, there's an escape hatch in black for this:
If you are adopting Black in a large project with pre-existing string conventions (like the popular “single quotes for data, double quotes for human-readable strings”), you can pass
--skip-string-normalization
on the command line. This is meant as an adoption helper, avoid using this for new projects.
Do we want to do 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.
Yes please, anything for a smaller diff.
(I won't mind if there's a subsequent PR that does only quote changes, separately, if anyone wants to do that. Personally, I'm not yet convinced by Black's arguments about quotes.)
if hasattr(self, 'port'): | ||
d['port'] = self.port | ||
if hasattr(self, "port"): | ||
d["port"] = self.port | ||
# all result files are encoded in utf-8 | ||
with codecs.open(resultfile, "r", "utf-8") as f: |
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.
Noticed in passing, not part of this PR, but: with the Python 2 drop we can replace codecs.open(..., "UTF-8")
with just open(..., encoding="UTF-8")
.
tests/checker/test_loginurl.py
Outdated
"user": user, | ||
"password": password, | ||
"pattern": re.compile("^http://localhost.*"), | ||
} |
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.
} | |
}, |
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.
Done.
tests/checker/test_news.py
Outdated
NNTP_INFO = "200 news.uni-stuttgart.de InterNetNews NNRP server " \ | ||
"INN 2.5.2 ready (no posting)" | ||
NNTP_INFO = ( | ||
"200 news.uni-stuttgart.de InterNetNews NNRP server " "INN 2.5.2 ready (no posting)" |
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.
"200 news.uni-stuttgart.de InterNetNews NNRP server " "INN 2.5.2 ready (no posting)" | |
"200 news.uni-stuttgart.de InterNetNews NNRP server INN 2.5.2 ready (no posting)" |
If this is not a Black bug, it should be!
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.
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.
Done.
tests/test_clamav.py
Outdated
["stream: ClamAV-Test-File(2d1206194bd704385e37000be6113f73:781) FOUND\n"], | ||
[ | ||
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n" | ||
], |
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.
Ugh, this is why I don't like automatic formatters. They get things right in 99% of the cases, and then throw out something like this.
["stream: ClamAV-Test-File(2d1206194bd704385e37000be6113f73:781) FOUND\n"], | |
[ | |
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n" | |
], | |
[ | |
"stream: ClamAV-Test-File(2d1206194bd704385e37000be6113f73:781) FOUND\n" | |
], | |
[ | |
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n" | |
], |
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.
Done
self.assertFalse(b"\xc2\xb7" in line, | ||
"Broken GTranslator copy/paste in %r:\n%r" % (f, line)) | ||
self.assertFalse( | ||
b"\xc2\xb7" in line, |
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.
Unrelated to this PR, but perhaps we should be checking for Unicode \N{MIDDLE DOT}
in decoded text, not the UTF-8 encoding of it in byte strings.
tests/test_url.py
Outdated
self.urlnormtest(url, url) | ||
url = "http://redirect.alexa.com/redirect?"\ | ||
"http://www.offeroptimizer.com" | ||
url = "http://redirect.alexa.com/redirect?" "http://www.offeroptimizer.com" |
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.
url = "http://redirect.alexa.com/redirect?" "http://www.offeroptimizer.com" | |
url = "http://redirect.alexa.com/redirect?http://www.offeroptimizer.com" |
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.
git grep '" "'
tells me I missed another one like this, in this file:
url = "http://server/..%5c..%5c..%5c..%5c..%5c..%5c..%5c.." "%5ccskin.zip"
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.
Done.
Let's not, at least not until Black gets the known bugs fixed and released.
tox -e flake8 complains a lot about code in linkcheck/. I've also noticed that tox -e flake8 complains about code in |
Added commits in response to the review comments. |
Run black and fix the remaining violations.