8000 Fix incorrectly hidden flake8 errors · html5lib/html5lib-python@de6bcf2 · GitHub
[go: up one dir, main page]

Skip to content

Commit de6bcf2

Browse files
committed
Fix incorrectly hidden flake8 errors
1 parent 8238648 commit de6bcf2

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

html5lib/tests/support.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
os.path.pardir,
1414
os.path.pardir)))
1515

16-
from html5lib import treebuilders, treewalkers, treeadapters
16+
from html5lib import treebuilders, treewalkers, treeadapters # noqa
1717
del base_path
1818

1919
# Build a dict of available trees
@@ -26,14 +26,14 @@
2626
}
2727

2828
# ElementTree impls
29-
import xml.etree.ElementTree as ElementTree
29+
import xml.etree.ElementTree as ElementTree # noqa
3030
treeTypes['ElementTree'] = {
3131
"builder": treebuilders.getTreeBuilder("etree", ElementTree, fullTree=True),
3232
"walker": treewalkers.getTreeWalker("etree", ElementTree)
3333
}
3434

3535
try:
36-
import xml.etree.cElementTree as cElementTree
36+
import xml.etree.cElementTree as cElementTree # noqa
3737
except ImportError:
3838
treeTypes['cElementTree'] = None
3939
else:
@@ -47,7 +47,7 @@
4747
}
4848

4949
try:
50-
import lxml.etree as lxml # flake8: noqa
50+
import lxml.etree as lxml # noqa
5151
except ImportError:
5252
treeTypes['lxml'] = None
5353
else:
@@ -58,7 +58,7 @@
5858

5959
# Genshi impls
6060
try:
61-
import genshi # flake8: noqa
61+
import genshi # noqa
6262
except ImportError:
6363
pass
6464
else:

html5lib/tests/test_encoding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def test_encoding():
5757

5858
try:
5959
try:
60-
import charade # flake8: noqa
60+
import charade # noqa
6161
except ImportError:
62-
import chardet # flake8: noqa
62+
import chardet # noqa
6363
except ImportError:
6464
print("charade/chardet not found, skipping chardet tests")
6565
else:
6666
def test_chardet():
67-
with open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb") as fp:
67+
with open(os.path.join(test_dir, "encoding", "chardet", "test_big5.txt"), "rb") as fp:
6868
encoding = inputstream.HTMLInputStream(fp.read()).charEncoding
6969
assert encoding[0].name == "big5"

html5lib/tests/test_parser2.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import io
44

5-
import pytest
5+
from . import support # noqa
66

7-
from . import support # flake8: noqa
8-
from html5lib import html5parser
97
from html5lib.constants import namespaces
108
from html5lib import parse
119

@@ -23,29 +21,29 @@ def test_line_counter():
2321

2422
def test_namespace_html_elements_0_dom():
2523
doc = parse("<html></html>",
26-
treebuilder="dom",
27-
namespaceHTMLElements=True)
24+
treebuilder="dom",
25+
namespaceHTMLElements=True)
2826
assert doc.childNodes[0].namespaceURI == namespaces["html"]
2927

3028

3129
def test_namespace_html_elements_1_dom():
3230
doc = parse("<html></html>",
33-
treebuilder="dom",
34-
namespaceHTMLElements=False)
31+
treebuilder="dom",
32+
namespaceHTMLElements=False)
3533
assert doc.childNodes[0].namespaceURI is None
3634

3735

3836
def test_namespace_html_elements_0_etree():
3937
doc = parse("<html></html>",
40-
treebuilder="etree",
41-
namespaceHTMLElements=True)
38+
treebuilder="etree",
39+
namespaceHTMLElements=True)
4240
assert doc.tag == "{%s}html" % (namespaces["html"],)
4341

4442

4543
def test_namespace_html_elements_1_etree():
4644
doc = parse("<html></html>",
47-
treebuilder="etree",
48-
namespaceHTMLElements=False)
45+
treebuilder="etree",
46+
namespaceHTMLElements=False)
4947
assert doc.tag == "html"
5048

5149

html5lib/tests/test_stream.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from . import support # flake8: noqa
3+
from . import support # noqa
4+
45
import codecs
56
from io import BytesIO
6-
import socket
77

88
import six
99
from six.moves import http_client, urllib
1010

1111
from html5lib.inputstream import (BufferedStream, HTMLInputStream,
1212
HTMLUnicodeInputStream, HTMLBinaryInputStream)
1313

14+
1415
def test_basic():
1516
s = b"abc"
1617
fp = BufferedStream(BytesIO(s))
1718
read = fp.read(10)
1819
assert read == s
1920

21+
2022
def test_read_length():
2123
fp = BufferedStream(BytesIO(b"abcdef"))
2224
read1 = fp.read(1)
@@ -28,17 +30,23 @@ def test_read_length():
2830
read4 = fp.read(4)
2931
assert read4 == b""
3032

33+
3134
def test_tell():
3235
fp = BufferedStream(BytesIO(b"abcdef"))
3336
read1 = fp.read(1)
37+
assert read1 == b"a"
3438
assert fp.tell() == 1
3539
read2 = fp.read(2)
40+
assert read2 == b"bc"
3641
assert fp.tell() == 3
3742
read3 = fp.read(3)
43+
assert read3 == b"def"
3844
assert fp.tell() == 6
3945
read4 = fp.read(4)
46+
assert read4 == b""
4047
assert fp.tell() == 6
4148

49+
4250
def test_seek():
4351
fp = BufferedStream(BytesIO(b"abcdef"))
4452
read1 = fp.read(1)
@@ -55,20 +63,26 @@ def test_seek():
5563
read5 = fp.read(2)
5664
assert read5 == b"ef"
5765

66+
5867
def test_seek_tell():
5968
fp = BufferedStream(BytesIO(b"abcdef"))
6069
read1 = fp.read(1)
70+
assert read1 == b"a"
6171
assert fp.tell() == 1
6272
fp.seek(0)
6373
read2 = fp.read(1)
74+
assert read2 == b"a"
6475
assert fp.tell() == 1
6576
read3 = fp.read(2)
77+
assert read3 == b"bc"
6678
assert fp.tell() == 3
6779
fp.seek(2)
6880
read4 = fp.read(2)
81+
assert read4 == b"cd"
6982
assert fp.tell() == 4
7083
fp.seek(4)
7184
read5 = fp.read(2)
85+
assert read5 == b"ef"
7286
assert fp.tell() == 6
7387

7488

@@ -85,28 +99,33 @@ def test_char_ascii():
8599
assert stream.charEncoding[0].name == 'windows-1252'
86100
assert stream.char() == "'"
87101

102+
88103
def test_char_utf8():
89104
stream = HTMLInputStream('\u2018'.encode('utf-8'), encoding='utf-8')
90105
assert stream.charEncoding[0].name == 'utf-8'
91106
assert stream.char() == '\u2018'
92107

108+
93109
def test_char_win1252():
94110
stream = HTMLInputStream("\xa9\xf1\u2019".encode('windows-1252'))
95111
assert stream.charEncoding[0].name == 'windows-1252'
96112
assert stream.char() == "\xa9"
97113
assert stream.char() == "\xf1"
98114
assert stream.char() == "\u2019"
99115

116+
100117
def test_bom():
101118
stream = HTMLInputStream(codecs.BOM_UTF8 + b"'")
102119
assert stream.charEncoding[0].name == 'utf-8'
103120
assert stream.char() == "'"
104121

122+
105123
def test_utf_16():
106124
stream = HTMLInputStream((' ' * 1025).encode('utf-16'))
107125
assert stream.charEncoding[0].name in ['utf-16le', 'utf-16be']
108126
assert len(stream.charsUntil(' ', True)) == 1025
109127

128+
110129
def test_newlines():
111130
stream = HTMLBinaryInputStreamShortChunk(codecs.BOM_UTF8 + b"a\nbb\r\nccc\rddddxe")
112131
assert stream.position() == (1, 0)
@@ -117,11 +136,13 @@ def test_newlines():
117136
assert stream.charsUntil('e') == "x"
118137
assert stream.position() == (4, 5)
119138

139+
120140
def test_newlines2():
121141
size = HTMLUnicodeInputStream._defaultChunkSize
122142
stream = HTMLInputStream("\r" * size + "\n")
123143
assert stream.charsUntil('x') == "\n" * size
124144

145+
125146
def test_position():
126147
stream = HTMLBinaryInputStreamShortChunk(codecs.BOM_UTF8 + b"a\nbb\nccc\nddde\nf\ngh")
127148
assert stream.position() == (1, 0)
@@ -140,6 +161,7 @@ def test_position():
140161
assert stream.charsUntil('h') == "e\nf\ng"
141162
assert stream.position() == (6, 1)
142163

164+
143165
def test_position2():
144166
stream = HTMLUnicodeInputStreamShortChunk("abc\nd")
145167
assert stream.position() == (1, 0)
@@ -154,6 +176,7 @@ def test_position2():
154176
assert stream.char() == "d"
155177
assert stream.position() == (2, 1)
156178

179+
157180
def test_python_issue_20007():
158181
"""
159182
Make sure we have a work-around for Python bug #20007
@@ -168,6 +191,7 @@ def makefile(self, _mode, _bufsize=None):
168191
stream = HTMLInputStream(source)
169192
assert stream.charsUntil(" ") == "Text"
170193

194+
171195
def test_python_issue_20007_b():
172196
"""
173197
Make sure we have a work-around for Python bug #20007

html5lib/tests/test_treeadapters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from . import support # flake8: noqa
3+
from . import support # noqa
44

55
import html5lib
66
from html5lib.treeadapters import sax
@@ -25,7 +25,7 @@ def test_to_sax():
2525
('endElementNS', ('http://www.w3.org/1999/xhtml', 'title'), 'title'),
2626
('characters', '\n '),
2727
('endElementNS', ('http://www.w3.org/1999/xhtml', 'head'), 'head'),
28-
('startElementNS', ('http://www.w3.org/1999/xhtml', 'body'), 'body', {}),
28+
('startElementNS', ('http://www.w3.org/1999/xhtml', 'body'), 'body', {}),
2929
('startElementNS', ('http://www.w3.org/1999/xhtml', 'a'), 'a', {(None, 'href'): '/'}),
3030
('startElementNS', ('http://www.w3.org/1999/xhtml', 'b'), 'b', {}),
3131
('startElementNS', ('http://www.w3.org/1999/xhtml', 'p'), 'p', {}),

html5lib/tokenizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import, division, unicode_literals
22

33
try:
4-
chr = unichr # flake8: noqa
4+
chr = unichr # noqa
55
except NameError:
66
pass
77

@@ -147,8 +147,8 @@ def consumeEntity(self, allowedChar=None, fromAttribute=False):
147147
output = "&"
148148

149149
charStack = [self.stream.char()]
150-
if (charStack[0] in spaceCharacters or charStack[0] in (EOF, "<", "&")
151-
or (allowedChar is not None and allowedChar == charStack[0])):
150+
if (charStack[0] in spaceCharacters or charStack[0] in (EOF, "<", "&") or
151+
(allowedChar is not None and allowedChar == charStack[0])):
152152
self.stream.unget(charStack[0])
153153

154154
elif charStack[0] == "#":

html5lib/treeadapters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
__all__ = ["sax"]
66

77
try:
8-
from . import genshi # flake8: noqa
8+
from . import genshi # noqa
99
except ImportError:
1010
pass
1111
else:

0 commit comments

Comments
 (0)
0