Hi,<br><br>I have been working on converting some of the older test files to use unittest. test_expat.py has a section like:<br><br>class Outputter:<br> def StartElementHandler(self, name, attrs):<br> print 'Start element:\n\t', repr(name), sortdict(attrs)
<br><br> def EndElementHandler(self, name):<br> print 'End element:\n\t', repr(name)<br><br> def CharacterDataHandler(self, data):<br> data = data.strip()<br> if data:<br> print 'Character data:'
<br> print '\t', repr(data)<br><br> def ProcessingInstructionHandler(self, target, data):<br> print 'PI:\n\t', repr(target), repr(data)<br><br> def StartNamespaceDeclHandler(self, prefix, uri):
<br> print 'NS decl:\n\t', repr(prefix), repr(uri)<br> <snip><br><br>...where it defines a set of handlers for an xml document that prints the output to stdout. The test then parses an xml document using this class and the stdout output is compared to a file. There are several lines of text on stdout to be compared:
<br><br>PI:<br> 'xml-stylesheet' 'href="stylesheet.css"'<br>Comment:<br> ' comment data '<br>Notation declared: ('notation', None, 'notation.jpeg', None)<br>
Unparsed entity decl:<br> ('unparsed_entity', None, 'entity.file', None, 'notation')<br>Start element:<br> 'root' {'attr1': 'value1', 'attr2': 'value2\xe1\xbd\x80'}
<br>NS decl:<br> 'myns' '<a href="http://www.python.org/namespace">http://www.python.org/namespace</a>'<br>Start element:<br> '<a href="http://www.python.org/namespace!subelement">http://www.python.org/namespace!subelement
</a>' {}<br>Character data:<br> 'Contents of subelements'<br>End element:<br> '<a href="http://www.python.org/namespace!subelement">http://www.python.org/namespace!subelement</a>'<br>End of NS decl:
<br> 'myns'<br>Start element:<br> 'sub2' {}<br>Start of CDATA section<br>Character data:<br> 'contents of CDATA section'<br>End of CDATA section<br>End element:<br> 'sub2'
<br>External entity ref: (None, 'entity.file', None)<br>End element:<br> 'root'<br><br><br>unittest does not seem well suited to this type of testing, because the stdout output comparison is testing many different pieces of functionality. Some subset of it is probably even important. To do this same testing with unittest would require many lines of
self.assertEquals(expected_string, string_from_stdout).<br><br>Does anyone have ideas on how this can be tested in a manner that is not as brittle as the stdout tests, but doesn't require writing significantly more test code? Or if not, is converting this file to use unittest a bad idea?
<br><br>Jerry Seutter<br>