Skip to content

Commit

Permalink
Fix remaining flake8 violations in tests/
Browse files Browse the repository at this point in the history
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_https.py:21:1: F401 'tests.need_network' imported but unused
  • Loading branch information
cjmayo committed May 28, 2020
1 parent b4c0a70 commit 4f55939
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion setup.cfg
Expand Up @@ -38,7 +38,8 @@ per-file-ignores =
linkcheck/htmlutil/htmlsoup.py: E402
linkcheck/parser/__init__.py: E402
tests/__init__.py: F401

# E501: line too long
tests/test_ftpparse.py: E501
extend-ignore =
# https://pep8.readthedocs.org/en/latest/intro.html#error-codes
# these are ignored by default:
Expand Down
9 changes: 5 additions & 4 deletions tests/checker/__init__.py
Expand Up @@ -68,7 +68,8 @@ def __init__(self, **kwargs):
self.diff = []

def normalize(self, result_log):
# XXX we assume that each log entry has a URL key, maybe we should add an assert into log_url() to that effect?
# XXX we assume that each log entry has a URL key,
# maybe we should add an assert into log_url() to that effect?
# Ensure that log entries are sorted by URL key:
# - join the result_log items together
# - split into entries (starting with a URL key)
Expand Down Expand Up @@ -289,9 +290,9 @@ def direct(
linkcheck.director.check_urls(aggregate)
diff = aggregate.config["logger"].diff
if diff:
l = ["Differences found testing %s" % url]
l.extend(x.rstrip() for x in diff[2:])
self.fail(os.linesep.join(l))
d = ["Differences found testing %s" % url]
d.extend(x.rstrip() for x in diff[2:])
self.fail(os.linesep.join(d))


class MailTest(LinkCheckTest):
Expand Down
2 changes: 1 addition & 1 deletion tests/checker/ftpserver.py
Expand Up @@ -91,7 +91,7 @@ def line_logger(self, msg):
ftp.login()
ftp.close()
break
except:
except Exception:
time.sleep(0.5)
return port

Expand Down
4 changes: 2 additions & 2 deletions tests/checker/httpserver.py
Expand Up @@ -52,7 +52,7 @@ def log_message(self, format, *args):

# serve .xhtml files as application/xhtml+xml
StoppableHttpRequestHandler.extensions_map.update(
{".xhtml": "application/xhtml+xml",}
{".xhtml": "application/xhtml+xml"}
)


Expand Down Expand Up @@ -221,7 +221,7 @@ def start_server(handler, https=False):
conn.request("GET", "/")
conn.getresponse()
break
except:
except Exception:
time.sleep(0.5)
return port

Expand Down
2 changes: 1 addition & 1 deletion tests/checker/telnetserver.py
Expand Up @@ -81,7 +81,7 @@ def on_connect(client):
client.open(host, port)
client.write(b"exit\n")
break
except:
except Exception:
time.sleep(0.5)
return port, t

Expand Down
1 change: 0 additions & 1 deletion tests/checker/test_https.py
Expand Up @@ -18,7 +18,6 @@
"""
from OpenSSL import crypto

from tests import need_network
from .httpserver import HttpsServerTest, CookieRedirectHttpRequestHandler
from .. import get_file

Expand Down
2 changes: 1 addition & 1 deletion tests/test_clamav.py
Expand Up @@ -55,7 +55,7 @@ def testInfected(self):
acceptable_responses = (
["stream: ClamAV-Test-File(2d1206194bd704385e37000be6113f73:781) FOUND\n"],
[
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n"
"stream: Clamav.Test.File-6(aa15bcf478d165efd2065190eb473bcb:544) FOUND\n"
],
)
self.assertIn(infected, acceptable_responses)
Expand Down
1 change: 1 addition & 0 deletions tests/test_containers.py
Expand Up @@ -37,6 +37,7 @@ def test_num_uses(self):
self.assertEqual(self.d.uses("a"), 0)
dummy = self.d["a"]
self.assertEqual(self.d.uses("a"), 1)
del dummy

def test_values(self):
self.assertTrue(not self.d)
Expand Down
1 change: 1 addition & 0 deletions tests/test_dummy.py
Expand Up @@ -33,6 +33,7 @@ def test_creation(self):
dummy = linkcheck.dummy.Dummy("1", "2")
dummy = linkcheck.dummy.Dummy(a=1, b=2)
dummy = linkcheck.dummy.Dummy("1", a=None, b=2)
del dummy

def test_attributes(self):
dummy = linkcheck.dummy.Dummy()
Expand Down
7 changes: 4 additions & 3 deletions tests/test_strformat.py
Expand Up @@ -59,13 +59,13 @@ def test_wrap(self):
# testing width <= 0
self.assertEqual(wrap(s, -1), s)
self.assertEqual(wrap(s, 0), s)
l = len(os.linesep)
n = len(os.linesep)
gap = " "
s2 = "11%(gap)s22%(sep)s33%(gap)s44%(sep)s55" % {"sep": os.linesep, "gap": gap}
# splitting lines
self.assertEqual(wrap(s2, 2), s)
# combining lines
self.assertEqual(wrap(s, 4 + l), s2)
self.assertEqual(wrap(s, 4 + n), s2)
# misc
self.assertEqual(wrap(s, -1), s)
self.assertEqual(wrap(s, 0), s)
Expand Down Expand Up @@ -133,7 +133,8 @@ def test_duration(self):
self.assertEqual(duration(60 * 60 * 24), "24:00:00")

def test_duration_long(self):
duration = lambda s: linkcheck.strformat.strduration_long(s, do_translate=False)
def duration(s):
linkcheck.strformat.strduration_long(s, do_translate=False)
self.assertEqual(duration(-0.5), "-0.50 seconds")
self.assertEqual(duration(0), "0.00 seconds")
self.assertEqual(duration(0.9), "0.90 seconds")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_url.py
Expand Up @@ -125,7 +125,10 @@ def test_norm_quote(self):
# the no-quote chars
url = "http://example.com/a*+-();b"
self.urlnormtest(url, url)
url = "http://linkchecker.git.sourceforge.net/git/gitweb.cgi?p=linkchecker/linkchecker;a=blob;f=doc/changelog.txt;hb=HEAD"
url = (
"http://linkchecker.git.sourceforge.net/git/gitweb.cgi"
"?p=linkchecker/linkchecker;a=blob;f=doc/changelog.txt;hb=HEAD"
)
self.urlnormtest(url, url)
url = "http://www.company.com/path/doc.html?url=/path2/doc2.html?foo=bar"
self.urlnormtest(url, url)
Expand Down

0 comments on commit 4f55939

Please sign in to comment.