From 1c8ddc632f1eb5550f98b8185b1b820069cb8efb Mon Sep 17 00:00:00 2001 From: gbrandl Date: Wed, 14 Feb 2007 17:32:51 +0100 Subject: [svn] Add validation test for HTML formatter. --- tests/test_html_formatter.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/test_html_formatter.py') diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py index a23fbfa9..ba3ed69e 100644 --- a/tests/test_html_formatter.py +++ b/tests/test_html_formatter.py @@ -11,6 +11,7 @@ import os import unittest import StringIO import random +import tempfile from pygments import lexers, formatters from pygments.token import _TokenType @@ -34,4 +35,33 @@ class HtmlFormatterTest(unittest.TestCase): outfile = StringIO.StringIO() fmt = HtmlFormatter(**optdict) fmt.format(tokensource, outfile) - + + def test_valid_output(self): + tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read())) + fmt = HtmlFormatter(full=True, linenos=True, noclasses=True) + + handle, pathname = tempfile.mkstemp('.html') + # place all output files in /tmp too + old_wd = os.getcwd() + os.chdir(os.path.dirname(pathname)) + tfile = os.fdopen(handle, 'w+b') + fmt.format(tokensource, tfile) + tfile.close() + catname = os.path.join(testdir, 'dtds', 'HTML4.soc') + try: + try: + import subprocess + ret = subprocess.Popen(['nsgmls', '-s', '-c', catname, pathname], + stdout=subprocess.PIPE).wait() + except ImportError: + # Python 2.3 - no subprocess module + ret = os.popen('nsgmls -s -c "%s" "%s"' % (catname, pathname)).close() + if ret == 32512: raise OSError # not found + except OSError: + # latex not available + pass + else: + self.failIf(ret, 'nsgmls run reported errors') + + os.unlink(pathname) + os.chdir(old_wd) -- cgit v1.2.1