mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-01 03:24:43 +00:00
Move HtmlPrinter and HtmlPrettyPrinter into tests
This commit is contained in:
parent
ce1d669329
commit
1255119ca8
4 changed files with 10 additions and 55 deletions
|
|
@ -91,8 +91,6 @@ Additionally, there are error and warning callbacks:
|
|||
|
||||
EXAMPLE
|
||||
|
||||
# This handler prints out the parsed HTML.
|
||||
handler = HtmlParser.htmllib.HtmlPrettyPrinter()
|
||||
# Create a new HTML parser object with the handler as parameter.
|
||||
parser = HtmlParser.htmlsax.parser(handler)
|
||||
# Feed data.
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2011-2014 Bastian Kleineidam
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
"""
|
||||
Parse HTML given as file parameter or piped to stdin.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.getcwd())
|
||||
import linkcheck.HtmlParser.htmlsax
|
||||
import linkcheck.HtmlParser.htmllib
|
||||
|
||||
|
||||
def main (text):
|
||||
parser = linkcheck.HtmlParser.htmlsax.parser()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrinter()
|
||||
parser.handler = handler
|
||||
# debug lexer
|
||||
#parser.debug(1)
|
||||
parser.feed(text)
|
||||
parser.flush()
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) <= 1:
|
||||
text = sys.stdin.read()
|
||||
else:
|
||||
filename = sys.argv[1]
|
||||
with open(filename) as fp:
|
||||
text = fp.read()
|
||||
main(text)
|
||||
|
|
@ -19,7 +19,7 @@ Test html parsing.
|
|||
"""
|
||||
|
||||
import linkcheck.HtmlParser.htmlsax
|
||||
import linkcheck.HtmlParser.htmllib
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
|
|
@ -28,6 +28,7 @@ import unittest
|
|||
|
||||
from parameterized import parameterized
|
||||
|
||||
from .htmllib import HtmlPrinter, HtmlPrettyPrinter
|
||||
|
||||
# list of tuples
|
||||
# (<test pattern>, <expected parse output>)
|
||||
|
|
@ -215,7 +216,7 @@ class TestParser (unittest.TestCase):
|
|||
def test_parse (self, _in, _out):
|
||||
# Parse all test patterns in one go.
|
||||
out = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out)
|
||||
handler = HtmlPrettyPrinter(out)
|
||||
self.htmlparser.handler = handler
|
||||
self.htmlparser.feed(_in)
|
||||
self.check_results(self.htmlparser, _in, _out, out)
|
||||
|
|
@ -235,7 +236,7 @@ class TestParser (unittest.TestCase):
|
|||
def test_feed (self, _in, _out):
|
||||
# Parse all test patterns sequentially.
|
||||
out = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out)
|
||||
handler = HtmlPrettyPrinter(out)
|
||||
self.htmlparser.handler = handler
|
||||
for c in _in:
|
||||
self.htmlparser.feed(c)
|
||||
|
|
@ -246,9 +247,9 @@ class TestParser (unittest.TestCase):
|
|||
# Parse all test patterns on two parsers interwoven.
|
||||
out = StringIO()
|
||||
out2 = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out)
|
||||
handler = HtmlPrettyPrinter(out)
|
||||
self.htmlparser.handler = handler
|
||||
handler2 = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out2)
|
||||
handler2 = HtmlPrettyPrinter(out2)
|
||||
self.htmlparser2.handler = handler2
|
||||
for c in _in:
|
||||
self.htmlparser.feed(c)
|
||||
|
|
@ -260,9 +261,9 @@ class TestParser (unittest.TestCase):
|
|||
def test_handler (self, _in, _out):
|
||||
out = StringIO()
|
||||
out2 = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrinter(out)
|
||||
handler = HtmlPrinter(out)
|
||||
self.htmlparser.handler = handler
|
||||
handler2 = linkcheck.HtmlParser.htmllib.HtmlPrinter(out2)
|
||||
handler2 = HtmlPrinter(out2)
|
||||
self.htmlparser2.handler = handler2
|
||||
for c in _in:
|
||||
self.htmlparser.feed(c)
|
||||
|
|
@ -273,7 +274,7 @@ class TestParser (unittest.TestCase):
|
|||
def test_flush (self, _in, _out):
|
||||
# Test parser flushing.
|
||||
out = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out)
|
||||
handler = HtmlPrettyPrinter(out)
|
||||
self.htmlparser.handler = handler
|
||||
self.htmlparser.feed(_in)
|
||||
self.check_results(self.htmlparser, _in, _out, out)
|
||||
|
|
@ -306,7 +307,7 @@ class TestParser (unittest.TestCase):
|
|||
parser = linkcheck.HtmlParser.htmlsax.parser()
|
||||
self.assertEqual(parser.encoding, None)
|
||||
out = StringIO()
|
||||
handler = linkcheck.HtmlParser.htmllib.HtmlPrettyPrinter(out)
|
||||
handler = HtmlPrettyPrinter(out)
|
||||
parser.handler = handler
|
||||
parser.feed(html)
|
||||
parser.flush()
|
||||
|
|
|
|||
Loading…
Reference in a new issue