[Zope-Checkins] CVS: Zope/lib/python/StructuredText/tests - testStructuredText.py:1.6
Andreas Jung
andreas@zope.com
Mon, 8 Oct 2001 14:28:29 -0400
Update of /cvs-repository/Zope/lib/python/StructuredText/tests
In directory cvs.zope.org:/tmp/cvs-serv501/tests
Modified Files:
testStructuredText.py
Log Message:
made regression test a bit more noisy. it nows shows
a diff-like output (using ndiff) of the difference
between HTML reference and generated HTML
=== Zope/lib/python/StructuredText/tests/testStructuredText.py 1.5 => 1.6 ===
from StructuredText import StructuredText
from StructuredText import HTMLClass
-import sys, os, unittest
+from StructuredText.StructuredText import HTML
+import sys, os, unittest, cStringIO
execfile(os.path.join(sys.path[0],'framework.py'))
+from OFS import ndiff
"""
This tester first ensures that all regression files
@@ -103,7 +105,8 @@
regressions=os.path.join(package_dir, 'regressions')
files = ['index.stx','Acquisition.stx','ExtensionClass.stx',
- 'MultiMapping.stx','examples.stx','Links.stx']
+ 'MultiMapping.stx','examples.stx','Links.stx','examples1.stx',
+ 'table.stx']
def readFile(dirname,fname):
@@ -177,8 +180,44 @@
reg_fname = f.replace('.stx','.ref')
reg_html = readFile(regressions , reg_fname)
- assert reg_html.strip()== html.strip(), \
- 'HTML regression test failed on %s' % f
+ if reg_html.strip()!= html.strip():
+ IO = cStringIO.StringIO()
+
+ oldStdout = sys.stdout
+ sys.stdout = IO
+
+ try:
+ open('_tmpout','w').write(html)
+ ndiff.fcompare(os.path.join(regressions,reg_fname),'_tmpout')
+ os.unlink('_tmpout')
+ finally:
+ sys.stdout = oldStdout
+
+ raise AssertionError, \
+ 'HTML regression test failed on %s\nDiff:\n%s\n' % (f,IO.getvalue())
+
+
+class BasicTests(unittest.TestCase):
+
+ def _test(self,stxtxt , expected):
+
+ res = HTML(stxtxt,level=1,header=0)
+ if res.find(expected)==-1:
+ print res
+ raise AssertionError,"basic test failed for '%s'" % stxtxt
+
+ def testUnderline(self):
+ """underline"""
+ self._test("xx _this is html_ xx","xx <u>this is html</u> xx")
+
+ def testEmphasis(self):
+ """underline"""
+ self._test("xx *this is html* xx","xx <em>this is html</em> xx")
+
+ def testStrong(self):
+ """underline"""
+ self._test("xx **this is html** xx","xx <strong>this is html</strong> xx")
+
framework()