import re import unittest import StringIO import tempfile from os.path import join, dirname, isfile from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter, NullFormatter from pygments.formatters.html import escape_html from pygments.util import uni_open import support TESTFILE, TESTDIR = support.location(__file__) fp = uni_open(TESTFILE, encoding='utf-8') try: tokensource = list(PythonLexer().get_tokens(fp.read())) finally: fp.close() class HtmlFormatterTest(unittest.TestCase): def test_correct_output(self): hfmt = HtmlFormatter(nowrap=True) houtfile = StringIO.StringIO() hfmt.format(tokensource, houtfile) nfmt = NullFormatter() noutfile = StringIO.StringIO() nfmt.format(tokensource, noutfile)
import unittest import StringIO import tempfile from os.path import join, dirname, isfile from pygments.lexers import PythonLexer from pygments.formatters import HtmlFormatter, NullFormatter from pygments.formatters.html import escape_html from pygments.util import uni_open import support TESTFILE, TESTDIR = support.location(__file__) tokensource = list(PythonLexer().get_tokens( uni_open(TESTFILE, encoding='utf-8').read())) class HtmlFormatterTest(unittest.TestCase): def test_correct_output(self): hfmt = HtmlFormatter(nowrap=True) houtfile = StringIO.StringIO() hfmt.format(tokensource, houtfile) nfmt = NullFormatter() noutfile = StringIO.StringIO() nfmt.format(tokensource, noutfile) stripped_html = re.sub('<.*?>', '', houtfile.getvalue()) escaped_text = escape_html(noutfile.getvalue()) self.assertEquals(stripped_html, escaped_text)