# Perforce Defect Tracking Integration Project # # # TEST_CHECK_XHTML.PY -- UNIT TEST FOR XHTML CHECKER # # Gareth Rees, Ravenbrook Limited, 2001-05-06 # # # 1. INTRODUCTION # # This Python module is a unit test case for the check_xhtml Python module that # checks XHTML documents against the XHTML 1.0 Transitional specification. # # The tests are purely regression tests. The test cases feed documents to the # XHTML checker, collect the output of the checker, and compare the actual # output to the expected output. import StringIO import check_xhtml import unittest class case(unittest.TestCase): def __init__(self, name, text, error, methodName='runTest'): self.name = name self.text = text self.error = error unittest.TestCase.__init__(self, methodName) def shortDescription(self): return self.name + " (test_check_xhtml)" def runTest(self): text_stream = StringIO.StringIO(self.text) error_stream = StringIO.StringIO() h = check_xhtml.handler("Test", error_stream = error_stream) h.check(text_stream) if error_stream.getvalue() != self.error: self.fail("XHTML document:\n%s\n%s\n%s\nExpected errors:\n%s%s\nFound errors:\n%s" % ("-" * 70, self.text, "-" * 70, self.error, "-" * 70, error_stream.getvalue())) start = """ Test document """ end = "\n" test_cases = [ ('Unknown element', start + "" + end, "Test(6) [1] element is not legal in XHTML 1.0 Transitional.\n"), ('Element not allowed in element', start + "

    Foo

" + end, "Test(6) [2] Element

appears in