1 from openid.yadis.parsehtml import YadisHTMLParser, ParseDone
2 from HTMLParser import HTMLParseError
3
4 import os.path, unittest, sys
5
7 reserved_values = ['None', 'EOF']
8
9 - def __init__(self, filename, testname, expected, case):
10 self.filename = filename
11 self.testname = testname
12 self.expected = expected
13 self.case = case
14 unittest.TestCase.__init__(self)
15
17 p = YadisHTMLParser()
18 try:
19 p.feed(self.case)
20 except ParseDone, why:
21 found = why[0]
22
23
24
25 assert found not in self.reserved_values
26
27
28 if found is None:
29 found = 'None'
30
31 msg = "%r != %r for case %s" % (found, self.expected, self.case)
32 self.failUnlessEqual(found, self.expected, msg)
33 except HTMLParseError:
34 self.failUnless(self.expected == 'None', (self.case, self.expected))
35 else:
36 self.failUnless(self.expected == 'EOF', (self.case, self.expected))
37
39 return "%s (%s<%s>)" % (
40 self.testname,
41 self.__class__.__module__,
42 os.path.basename(self.filename))
43
50
52 """Make a pyunit TestSuite from a file defining test cases."""
53 s = unittest.TestSuite()
54 for (filename, test_num, expected, case) in getCases():
55 s.addTest(_TestCase(filename, str(test_num), expected, case))
56 return s
57
59 runner = unittest.TextTestRunner()
60 return runner.run(loadTests())
61
62 filenames = ['data/test1-parsehtml.txt']
63
64 default_test_files = []
65 base = os.path.dirname(__file__)
66 for filename in filenames:
67 full_name = os.path.join(base, filename)
68 default_test_files.append(full_name)
69
79
80
81 if __name__ == '__main__':
82 sys.exit(not test().wasSuccessful())
83