Commit 36ec27af authored by James R. Wilcox's avatar James R. Wilcox
Browse files

flake8 including 1 actual bug

parent 54c4eac7
[flake8]
ignore = E302,E305,E741,W504
max-line-length = 120
\ No newline at end of file
......@@ -6,66 +6,65 @@ import doctest
import os
import sys
import re
import io
sys.path.append(os.getcwd())
CURRENT_TESTS = {
"chapter1" : ["chapter1-base-tests.md",
"chapter1-exercise-http-1-1-tests.md",
"chapter1-exercise-file-urls-tests.md",
"chapter1-exercise-redirects-tests.md",
"chapter1-exercise-caching-tests.md",
],
"chapter2" : ["chapter2-base-tests.md",
"chapter2-exercise-line-breaks-tests.md",
"chapter2-exercise-resizing-tests.md",
"chapter2-exercise-mouse-wheel-tests.md",
"chapter2-exercise-zoom-tests.md",
],
"chapter3" : ["chapter3-base-tests.md",
"chapter3-exercise-centered-text-tests.md",
"chapter3-exercise-superscripts-tests.md",
"chapter3-exercise-soft-hyphens-tests.md",
"chapter3-exercise-small-caps-tests.md",
],
"chapter4" : ["chapter4-base-tests.md",
"chapter4-exercise-comments-tests.md",
"chapter4-exercise-paragraphs-tests.md",
"chapter4-exercise-scripts-tests.md",
#"chapter4-exercise-quoted-attributes-tests.md",
],
"chapter5" : ["chapter5-base-tests.md",
"chapter5-exercise-hidden-head-tests.md",
"chapter5-exercise-bullets-tests.md",
"chapter5-exercise-scrollbar-tests.md",
"chapter5-exercise-links-bar-tests.md",
],
"chapter6" : ["chapter6-base-tests.md",
"chapter6-exercise-fonts-tests.md",
"chapter6-exercise-width-height-tests.md",
"chapter6-exercise-class-selectors-tests.md",
"chapter6-exercise-shorthand-properties-tests.md",
],
"chapter7" : ["chapter7-base-tests.md",
"chapter7-exercise-backspace-tests.md",
"chapter7-exercise-middle-click-tests.md",
"chapter7-exercise-fragments-tests.md",
"chapter7-exercise-bookmarks-tests.md",
],
"chapter8" : ["chapter8-base-tests.md",
"chapter8-exercise-enter-key-tests.md",
"chapter8-exercise-check-boxes-tests.md",
"chapter8-exercise-tab-tests.md",
"chapter8-exercise-get-forms-tests.md",
],
"chapter9" : ["chapter9-base-tests.md",
"chapter9-exercise-create-element-tests.md",
"chapter9-exercise-node-children-tests.md",
"chapter9-exercise-ids-tests.md",
"chapter9-exercise-event-bubbling-tests.md",
],
"chapter10" : ["chapter10-base-tests.md",
"chapter1": ["chapter1-base-tests.md",
"chapter1-exercise-http-1-1-tests.md",
"chapter1-exercise-file-urls-tests.md",
"chapter1-exercise-redirects-tests.md",
"chapter1-exercise-caching-tests.md",
],
"chapter2": ["chapter2-base-tests.md",
"chapter2-exercise-line-breaks-tests.md",
"chapter2-exercise-resizing-tests.md",
"chapter2-exercise-mouse-wheel-tests.md",
"chapter2-exercise-zoom-tests.md",
],
"chapter3": ["chapter3-base-tests.md",
"chapter3-exercise-centered-text-tests.md",
"chapter3-exercise-superscripts-tests.md",
"chapter3-exercise-soft-hyphens-tests.md",
"chapter3-exercise-small-caps-tests.md",
],
"chapter4": ["chapter4-base-tests.md",
"chapter4-exercise-comments-tests.md",
"chapter4-exercise-paragraphs-tests.md",
"chapter4-exercise-scripts-tests.md",
"chapter4-exercise-quoted-attributes-tests.md",
],
"chapter5": ["chapter5-base-tests.md",
"chapter5-exercise-hidden-head-tests.md",
"chapter5-exercise-bullets-tests.md",
"chapter5-exercise-scrollbar-tests.md",
"chapter5-exercise-links-bar-tests.md",
],
"chapter6": ["chapter6-base-tests.md",
"chapter6-exercise-fonts-tests.md",
"chapter6-exercise-width-height-tests.md",
"chapter6-exercise-class-selectors-tests.md",
"chapter6-exercise-shorthand-properties-tests.md",
],
"chapter7": ["chapter7-base-tests.md",
"chapter7-exercise-backspace-tests.md",
"chapter7-exercise-middle-click-tests.md",
"chapter7-exercise-fragments-tests.md",
"chapter7-exercise-bookmarks-tests.md",
],
"chapter8": ["chapter8-base-tests.md",
"chapter8-exercise-enter-key-tests.md",
"chapter8-exercise-check-boxes-tests.md",
"chapter8-exercise-tab-tests.md",
"chapter8-exercise-get-forms-tests.md",
],
"chapter9": ["chapter9-base-tests.md",
"chapter9-exercise-create-element-tests.md",
"chapter9-exercise-node-children-tests.md",
"chapter9-exercise-ids-tests.md",
"chapter9-exercise-event-bubbling-tests.md",
],
"chapter10": ["chapter10-base-tests.md",
"chapter10-exercise-new-inputs-tests.md",
"chapter10-exercise-certificate-errors-tests.md",
"chapter10-exercise-script-access-tests.md",
......@@ -114,7 +113,7 @@ def patched_report_unexpected_exception(self, out, test, example, exc_info):
out(self._failure_header(test, example) +
self._checker.output_difference(example, got, self.optionflags) +
'Exception Raised:\n' + doctest._indent(doctest._exception_traceback(exc_info)))
old_parse = doctest.DocTestParser.parse
def patched_parse(self, string, name="<string>"):
......@@ -159,13 +158,13 @@ def patched_failure_header(self, test, example):
out.append('File "%s", line %s, in %s' %
(test.filename, lineno, test.name))
else:
out.append('Line %s, in %s' % (example.lineno+1, test.name))
out.append('Line %s, in %s' % (example.lineno + 1, test.name))
example_idx = test._parsed.index(example)
header_idx = example_idx
while header_idx > 0 \
and (isinstance(test._parsed[header_idx], doctest.Example)
or test._parsed[header_idx] == ''):
while (header_idx > 0 and
(isinstance(test._parsed[header_idx], doctest.Example) or
test._parsed[header_idx] == '')):
header_idx -= 1
s = ""
for i in range(header_idx, example_idx + 1):
......@@ -211,13 +210,13 @@ def main(argv):
mapped_results = run_doctests(tests)
total_state = "all passed"
print("\nSummarised results\n")
for name,(failure_count, test_count) in mapped_results.items():
for name, (failure_count, test_count) in mapped_results.items():
state = "passed"
if failure_count != 0:
state = "failed {:<2} out of {:<2} tests".format(failure_count, test_count)
total_state = "failed"
print("{:>42}: {}".format(name, state))
print("-"*52)
print("-" * 52)
print("{:>42}: {} ".format("Final", total_state))
return int(total_state == "failed")
......
......@@ -7,14 +7,14 @@ import io
import sys
import tkinter
import tkinter.font
import unittest
import email
import os
from unittest import mock
from ssl import SSLCertVerificationError
def normalize_display_list(dl):
dl = [(float(t[0]), float(t[1]), t[2].replace("\xad", ""), *t[3:]) for t in dl]
dl = [(float(t[0]), float(t[1]), t[2].replace("\xad", ""), *t[3:]) for t in dl]
return dl
class certifi:
......@@ -24,7 +24,6 @@ class certifi:
sys.modules["certifi"] = certifi()
from ssl import SSLCertVerificationError
def fake_badssl(hostname):
if hostname.endswith(".badssl.com"):
raise SSLCertVerificationError()
......@@ -52,7 +51,7 @@ class socket:
def connect(self, host_port):
self.host, self.port = host_port
self.connected = True
if self.ssl_hostname != None:
if self.ssl_hostname is not None:
assert self.ssl_hostname == self.host
fake_badssl(self.host)
self.scheme = "https"
......@@ -72,11 +71,12 @@ class socket:
key, val = tup
if key.lower() == "content-length":
content_length = val.strip()
assert content_length != None, "Content-Length not present in headers"
assert content_length is not None, "Content-Length not present in headers"
assert len(self.body) == int(content_length), len(self.body)
def makefile(self, mode, encoding, newline):
assert self.connected and self.host and self.port, "You cannot call makefile() on a socket until you call connect() and send()"
assert self.connected and self.host and self.port, \
"You cannot call makefile() on a socket until you call connect() and send()"
if self.port == 80 and self.scheme == "http":
url = self.scheme + "://" + self.host + self.path
elif self.port == 443 and self.scheme == "https":
......@@ -90,7 +90,8 @@ class socket:
"Incorrect GET form submisson")
return io.StringIO(response.replace(newline, "\n"), newline)
assert url in self.URLs, f"You are requesting a url that you shouldn't: {url}"
assert self.method == self.URLs[url][0], f"Expected a {self.URLs[url][0]} request but got a {self.method} request to {url}"
assert self.method == self.URLs[url][0], \
f"Expected a {self.URLs[url][0]} request but got a {self.method} request to {url}"
output = self.URLs[url][1]
if self.URLs[url][2]:
assert self.body == self.URLs[url][2], (self.body, self.URLs[url][2])
......@@ -106,8 +107,8 @@ class socket:
@classmethod
def respond(cls, url, response, method="GET", body=None):
if NO_CACHE:
respone = response.replace(b"\r\n\r\n",
b"\r\nCache-Control: no-store\r\n\r\n")
response = response.replace(b"\r\n\r\n",
b"\r\nCache-Control: no-store\r\n\r\n")
cls.URLs[url] = [method, response, body]
@classmethod
......@@ -150,7 +151,7 @@ class socket:
raw_command, raw_headers = raw_request.split('\r\n', 1)
message = email.message_from_file(io.StringIO(raw_headers))
headers = dict(message.items())
headers = {key.lower(): val for key,val in headers.items()}
headers = {key.lower(): val for key, val in headers.items()}
command, path, version = raw_command.split(" ", 2)
return command, path, version, headers
......@@ -194,7 +195,6 @@ class ssl:
return mock.patch("ssl.create_default_context", wraps=cls)
class SilentTk:
def bind(self, event, callback):
pass
......@@ -253,10 +253,10 @@ def check_bookmark_button(fill_color):
fill = parts[6].split("=")[1][1:-1]
if (755 < x1 < 775 and
40 < y1 < 60 and
780 < x2 < 800 and
80 < y2 < 100 and
fill == fill_color):
40 < y1 < 60 and
780 < x2 < 800 and
80 < y2 < 100 and
fill == fill_color):
return True
return False
......@@ -319,13 +319,11 @@ class SkipChromeCanvas:
print("create_text: x={} y={} text={}".format(
x, y, text))
def create_rectangle(self, x1, y1, x2, y2, width=None, fill=None, outline=None):
if y1 > 100 and fill != "blue":
print("create_rectangle: x1={} y1={} x2={} y2={} width={} fill={}".format(
x1, y1, x2, y2, width, repr(fill)))
def create_line(self, x1, y1, x2, y2, fill=None):
pass
......@@ -394,8 +392,8 @@ class MockFont:
return self.size * len(word.replace("\xad", ""))
def metrics(self, name=None):
all = {"ascent" : self.size * 0.75, "descent": self.size * 0.25,
"linespace": self.size}
all = {"ascent": self.size * 0.75, "descent": self.size * 0.25,
"linespace": self.size}
if name:
return all[name]
return all
......@@ -426,7 +424,7 @@ tkinter.font.Font = MockFont
def errors(f, *args, **kwargs):
try:
f(*args, **kwargs)
except Exception as e:
except Exception:
return True
else:
return False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment