Permalink
Browse files

[htmlhead] Round out parser test coverage

  • Loading branch information...
lovett committed Oct 9, 2018
1 parent b7adea0 commit 3fe86b746cf2ec1f02716a39dab058873601c782
Showing with 24 additions and 11 deletions.
  1. +2 −2 Makefile
  2. +7 −8 parsers/htmlhead.py
  3. +15 −1 parsers/test_htmlhead.py
@@ -254,8 +254,8 @@ $(PARSER_PATHS): $(COVERAGE_DIR) dummy
# are only applied to changed files.
#
lint: dummy
flake8 $(APP_DIR) $(PLUGIN_DIR) medley.py
pylint --rcfile=.pylintrc $(APP_DIR) $(PLUGIN_DIR) medley.py
flake8 $(APP_DIR) $(PLUGIN_DIR) $(PARSER_DIR) medley.py
pylint --rcfile=.pylintrc $(APP_DIR) $(PLUGIN_DIR) $(PARSER_DIR) medley.py
vagrant-install: dummy
@@ -4,8 +4,13 @@
from collections import deque
class Parser(HTMLParser):
class Parser(HTMLParser): # pylint: disable=abstract-method
"""Convert an HTML document's head section to a dict.
The abstract-method pylint check is disabled because it insists on
having the error() method of ParserBase overridden, but that isn't
otherwise helpful here.
"""
stack = deque([], 50)
@@ -26,13 +31,6 @@ def reset(self):
self.finished = False
self.stack.clear()
def error(self, message):
"""Do-nothing override of default error handler.
This is pointless, but having it appeases pylint.
"""
pass
def parse(self, markup):
"""Parse an HTML string."""
self.result = []
@@ -63,6 +61,7 @@ def handle_endtag(self, tag):
if tag == "head":
self.finished = True
return
while self.stack and True:
collected_tag = self.stack.pop()
@@ -72,7 +72,21 @@ def test_only_head(self):
"""
final = self.parser.parse(initial)
print(final)
self.assertEqual(len(final), 1)
def test_malformed(self):
"""A malformed document is parsed successfully."""
initial = """
<html>
<head>
<invalid>
<title>hello world</title>
</head>
</html>
"""
final = self.parser.parse(initial)
self.assertEqual(len(final), 1)

0 comments on commit 3fe86b7

Please sign in to comment.