Skip to content
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

Add prospector and fix some bugs #218

Merged
merged 27 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c64bfca
Get rid of mutable default arguments
gsnedders Dec 3, 2015
c1c16ce
Avoid noisiness from pylint and the parser's set patterns
gsnedders Dec 4, 2015
2c3b64b
add pep8/flake8 config to get something useful happening with them
gsnedders May 20, 2016
8238648
Fix all the files outside of html5lib to flake8 cleanly
gsnedders May 20, 2016
de6bcf2
Fix incorrectly hidden flake8 errors
gsnedders May 20, 2016
0bd31c4
Get rid of type()-based type-check
gsnedders May 20, 2016
d440a83
Silence pytest unused-variable warnings
gsnedders May 20, 2016
5c1d8e2
Remove duplicate entry from constants.replacementCharacters
gsnedders May 20, 2016
1b86ccb
Remove gratuitious argument in sanitizer
gsnedders May 20, 2016
82d623b
Silence redefined-variable-type
gsnedders May 20, 2016
a017b88
Silence unused-argument
gsnedders May 20, 2016
e5d395c
Silence wrong-import-position
gsnedders May 20, 2016
b64df28
Change which way around we overwrite this for clarity's sake
gsnedders May 20, 2016
df0b2ba
Remove unused import
gsnedders May 20, 2016
742715d
Fix invalid_unicode_re on platforms supporting lone surrogates
gsnedders May 20, 2016
cd74ec7
Fix comment
gsnedders May 20, 2016
15e126f
Silence eval-used
gsnedders May 20, 2016
bfc278a
Silence bare-except
gsnedders May 20, 2016
b46fcdf
Silence too-many-nested-blocks
gsnedders May 20, 2016
6945bc4
Silence not-callable
gsnedders May 20, 2016
0c290e0
Kill long-dead finalText code
gsnedders May 20, 2016
da099dc
Silence a buggily output non-parent-init-called
gsnedders May 20, 2016
97427de
Fix indentation
gsnedders May 20, 2016
2afe09b
Make this in practice unreachable code work on Py2
gsnedders May 20, 2016
c0df867
Silence arguments-differ
gsnedders May 20, 2016
5dce4f2
Silence protected-access
gsnedders May 20, 2016
a2b8c11
Add prospector/pylint config for the sake of Landscape.
gsnedders Dec 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix incorrectly hidden flake8 errors
  • Loading branch information
gsnedders committed May 20, 2016
commit de6bcf22e8171e06b0e07558b699075f1b970dd0
10 changes: 5 additions & 5 deletions html5lib/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
os.path.pardir,
os.path.pardir)))

from html5lib import treebuilders, treewalkers, treeadapters
from html5lib import treebuilders, treewalkers, treeadapters # noqa
del base_path

# Build a dict of available trees
Expand All @@ -26,14 +26,14 @@
}

# ElementTree impls
import xml.etree.ElementTree as ElementTree
import xml.etree.ElementTree as ElementTree # noqa
treeTypes['ElementTree'] = {
"builder": treebuilders.getTreeBuilder("etree", ElementTree, fullTree=True),
"walker": treewalkers.getTreeWalker("etree", ElementTree)
}

try:
import xml.etree.cElementTree as cElementTree
import xml.etree.cElementTree as cElementTree # noqa
except ImportError:
treeTypes['cElementTree'] = None
else:
Expand All @@ -47,7 +47,7 @@
}

try:
import lxml.etree as lxml # flake8: noqa
import lxml.etree as lxml # noqa
except ImportError:
treeTypes['lxml'] = None
else:
Expand All @@ -58,7 +58,7 @@

# Genshi impls
try:
import genshi # flake8: noqa
import genshi # noqa
except ImportError:
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions html5lib/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def test_encoding():

try:
try:
import charade # flake8: noqa
import charade # noqa
except ImportError:
import chardet # flake8: noqa
import chardet # noqa
except ImportError:
print("charade/chardet not found, skipping chardet tests")
else:
def test_chardet():
with open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt"), "rb") as fp:
with open(os.path.join(test_dir, "encoding", "chardet", "test_big5.txt"), "rb") as fp:
encoding = inputstream.HTMLInputStream(fp.read()).charEncoding
assert encoding[0].name == "big5"
20 changes: 9 additions & 11 deletions html5lib/tests/test_parser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import io

import pytest
from . import support # noqa

from . import support # flake8: noqa
from html5lib import html5parser
from html5lib.constants import namespaces
from html5lib import parse

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

def test_namespace_html_elements_0_dom():
doc = parse("<html></html>",
treebuilder="dom",
namespaceHTMLElements=True)
treebuilder="dom",
namespaceHTMLElements=True)
assert doc.childNodes[0].namespaceURI == namespaces["html"]


def test_namespace_html_elements_1_dom():
doc = parse("<html></html>",
treebuilder="dom",
namespaceHTMLElements=False)
treebuilder="dom",
namespaceHTMLElements=False)
assert doc.childNodes[0].namespaceURI is None


def test_namespace_html_elements_0_etree():
doc = parse("<html></html>",
treebuilder="etree",
namespaceHTMLElements=True)
treebuilder="etree",
namespaceHTMLElements=True)
assert doc.tag == "{%s}html" % (namespaces["html"],)


def test_namespace_html_elements_1_etree():
doc = parse("<html></html>",
treebuilder="etree",
namespaceHTMLElements=False)
treebuilder="etree",
namespaceHTMLElements=False)
assert doc.tag == "html"


Expand Down
28 changes: 26 additions & 2 deletions html5lib/tests/test_stream.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from __future__ import absolute_import, division, unicode_literals

from . import support # flake8: noqa
from . import support # noqa

import codecs
from io import BytesIO
import socket

import six
from six.moves import http_client, urllib

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


def test_basic():
s = b"abc"
fp = BufferedStream(BytesIO(s))
read = fp.read(10)
assert read == s


def test_read_length():
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
Expand All @@ -28,17 +30,23 @@ def test_read_length():
read4 = fp.read(4)
assert read4 == b""


def test_tell():
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert read1 == b"a"
assert fp.tell() == 1
read2 = fp.read(2)
assert read2 == b"bc"
assert fp.tell() == 3
read3 = fp.read(3)
assert read3 == b"def"
assert fp.tell() == 6
read4 = fp.read(4)
assert read4 == b""
assert fp.tell() == 6


def test_seek():
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
Expand All @@ -55,20 +63,26 @@ def test_seek():
read5 = fp.read(2)
assert read5 == b"ef"


def test_seek_tell():
fp = BufferedStream(BytesIO(b"abcdef"))
read1 = fp.read(1)
assert read1 == b"a"
assert fp.tell() == 1
fp.seek(0)
read2 = fp.read(1)
assert read2 == b"a"
assert fp.tell() == 1
read3 = fp.read(2)
assert read3 == b"bc"
assert fp.tell() == 3
fp.seek(2)
read4 = fp.read(2)
assert read4 == b"cd"
assert fp.tell() == 4
fp.seek(4)
read5 = fp.read(2)
assert read5 == b"ef"
assert fp.tell() == 6


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


def test_char_utf8():
stream = HTMLInputStream('\u2018'.encode('utf-8'), encoding='utf-8')
assert stream.charEncoding[0].name == 'utf-8'
assert stream.char() == '\u2018'


def test_char_win1252():
stream = HTMLInputStream("\xa9\xf1\u2019".encode('windows-1252'))
assert stream.charEncoding[0].name == 'windows-1252'
assert stream.char() == "\xa9"
assert stream.char() == "\xf1"
assert stream.char() == "\u2019"


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


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


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


def test_newlines2():
size = HTMLUnicodeInputStream._defaultChunkSize
stream = HTMLInputStream("\r" * size + "\n")
assert stream.charsUntil('x') == "\n" * size


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


def test_position2():
stream = HTMLUnicodeInputStreamShortChunk("abc\nd")
assert stream.position() == (1, 0)
Expand All @@ -154,6 +176,7 @@ def test_position2():
assert stream.char() == "d"
assert stream.position() == (2, 1)


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


def test_python_issue_20007_b():
"""
Make sure we have a work-around for Python bug #20007
Expand Down
4 changes: 2 additions & 2 deletions html5lib/tests/test_treeadapters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, unicode_literals

from . import support # flake8: noqa
from . import support # noqa

import html5lib
from html5lib.treeadapters import sax
Expand All @@ -25,7 +25,7 @@ def test_to_sax():
('endElementNS', ('http:https://www.w3.org/1999/xhtml', 'title'), 'title'),
('characters', '\n '),
('endElementNS', ('http:https://www.w3.org/1999/xhtml', 'head'), 'head'),
('startElementNS', ('http:https://www.w3.org/1999/xhtml', 'body'), 'body', {}),
('startElementNS', ('http:https://www.w3.org/1999/xhtml', 'body'), 'body', {}),
('startElementNS', ('http:https://www.w3.org/1999/xhtml', 'a'), 'a', {(None, 'href'): '/'}),
('startElementNS', ('http:https://www.w3.org/1999/xhtml', 'b'), 'b', {}),
('startElementNS', ('http:https://www.w3.org/1999/xhtml', 'p'), 'p', {}),
Expand Down
6 changes: 3 additions & 3 deletions html5lib/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, division, unicode_literals

try:
chr = unichr # flake8: noqa
chr = unichr # noqa
except NameError:
pass

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

charStack = [self.stream.char()]
if (charStack[0] in spaceCharacters or charStack[0] in (EOF, "<", "&")
or (allowedChar is not None and allowedChar == charStack[0])):
if (charStack[0] in spaceCharacters or charStack[0] in (EOF, "<", "&") or
(allowedChar is not None and allowedChar == charStack[0])):
self.stream.unget(charStack[0])

elif charStack[0] == "#":
Expand Down
2 changes: 1 addition & 1 deletion html5lib/treeadapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__all__ = ["sax"]

try:
from . import genshi # flake8: noqa
from . import genshi # noqa
except ImportError:
pass
else:
Expand Down