Fix remaining flake8 violations in tests/

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
This commit is contained in:
Chris Mayo 2020-05-28 20:29:13 +01:00
parent 165c51aeea
commit 87039913b2
13 changed files with 24 additions and 16 deletions

View file

@ -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:

View file

@ -68,7 +68,8 @@ class TestLogger(linkcheck.logger._Logger):
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)
@ -289,9 +290,9 @@ class LinkCheckTest(unittest.TestCase):
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):

View file

@ -91,7 +91,7 @@ def start_server(host, port):
ftp.login()
ftp.close()
break
except:
except Exception:
time.sleep(0.5)
return port

View file

@ -52,7 +52,7 @@ class StoppableHttpRequestHandler(SimpleHTTPRequestHandler):
# serve .xhtml files as application/xhtml+xml
StoppableHttpRequestHandler.extensions_map.update(
{".xhtml": "application/xhtml+xml",}
{".xhtml": "application/xhtml+xml"}
)
@ -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

View file

@ -81,7 +81,7 @@ def start_server(host, port, stop_event):
client.open(host, port)
client.write(b"exit\n")
break
except:
except Exception:
time.sleep(0.5)
return port, t

View file

@ -27,7 +27,7 @@ class TestHttpMisc(HttpServerTest):
def test_html_internet(self):
self.swf_test()
self.file_test("sitemap.xml")
def test_html(self):
self.file_test("sitemapindex.xml")

View file

@ -18,7 +18,6 @@ Test https.
"""
from OpenSSL import crypto
from tests import need_network
from .httpserver import HttpsServerTest, CookieRedirectHttpRequestHandler
from .. import get_file

View file

@ -31,6 +31,7 @@ NNTP_INFO = (
# Most free NNTP servers are slow, so don't waist a lot of time running those.
NNTP_TIMEOUT_SECS = 30
# disabled for now until some stable news server comes up
@pytest.mark.skip(reason="disabled for now until some stable news server comes up")
class TestNews(LinkCheckTest):

View file

@ -55,7 +55,7 @@ class TestClamav(unittest.TestCase):
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)

View file

@ -37,6 +37,7 @@ class TestLFUCache(unittest.TestCase):
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)

View file

@ -33,6 +33,7 @@ class TestDummy(unittest.TestCase):
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()

View file

@ -59,13 +59,13 @@ class TestStrFormat(unittest.TestCase):
# 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)
@ -133,7 +133,8 @@ class TestStrFormat(unittest.TestCase):
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):
return 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")

View file

@ -125,7 +125,10 @@ class TestUrl(unittest.TestCase):
# 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)