2
See tv/resources/testdata/stripperdata/ for test files.
4
Files ending with ``.in`` are input files. These should be in utf-8
5
coding and the entire file is used as input.
7
Files ending with ``.expected`` are expected output files. These
8
files are the repr(...) of the output from HTMLStripper.strip.
10
If you need to write new tests, write the test, run the unittest and
11
the test will fail--but StripperTest will tell you what the output is.
12
You can verify the output, then copy and paste it into a .expected
16
from StringIO import StringIO
20
from miro.test.framework import MiroTestCase
22
from miro.plat import resources
25
class HTMLStripperTest(unittest.TestCase):
26
def test_garbage(self):
27
stripper = util.HTMLStripper()
29
for mem in [(1, ("", [])),
33
self.assertEquals(stripper.strip(mem[0]), mem[1])
35
for mem in [("<html>", ("", [])),
36
("<html></html>", ("", []))]:
37
self.assertEquals(stripper.strip(mem[0]), mem[1])
39
def test_simple(self):
40
stripper = util.HTMLStripper()
42
for mem in [("<html", ("<html", [])),
43
("<html><html>", ("", [])),
44
("</html></html>", ("", [])),
45
("<p>foo</p>", ("foo", [])),
46
("<p>foo</p><br/>", ("foo", []))
48
self.assertEquals(stripper.strip(mem[0]), mem[1])
50
def test_stripper_data(self):
51
stripper = util.HTMLStripper()
53
testdir = resources.path(os.path.join("testdata", "stripperdata"))
54
tests = [m for m in os.listdir(testdir) if m.endswith(".in")]
57
mem = os.path.join(testdir, mem)
58
if not os.path.isfile(mem):
65
input_ = input_.decode("utf-8")
66
output = stripper.strip(input_)
68
expected = os.path.splitext(mem)[0] + ".expected"
69
if not os.path.isfile(expected):
70
self.assertEquals(0, 1, "%s not found." % expected)
72
f = open(expected, "r")
73
data = f.read().strip()
76
repr(output), data, "output: %s" % repr(output))