Source

pygments-main / tests / test_latex_formatter.py

Full commit
gbrandl e24cb7a 




Georg Brandl bcd674c 
gbrandl 6cd72bd 
gbrandl e24cb7a 








Benjamin Peterso… 2b6e56f 


Benjamin Peterso… 9b02c77 
gbrandl e24cb7a 



Georg Brandl ea295cf 




gbrandl a88f6c3 
gbrandl e24cb7a 




gbrandl a88f6c3 
gbrandl e24cb7a 


gbrandl e32afa6 
Georg Brandl ea295cf 


Georg Brandl 183947d 
Georg Brandl ea295cf 
gbrandl e24cb7a 



Georg Brandl 183947d 

Georg Brandl ea295cf 
gbrandl e24cb7a 

# -*- coding: utf-8 -*-
"""
    Pygments LaTeX formatter tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import unittest
import tempfile

from pygments.formatters import LatexFormatter
from pygments.lexers import PythonLexer

import support

TESTFILE, TESTDIR = support.location(__file__)


class LatexFormatterTest(unittest.TestCase):

    def test_valid_output(self):
        fp = open(TESTFILE)
        try:
            tokensource = list(PythonLexer().get_tokens(fp.read()))
        finally:
            fp.close()
        fmt = LatexFormatter(full=True, encoding='latin1')

        handle, pathname = tempfile.mkstemp('.tex')
        # place all output files in /tmp too
        old_wd = os.getcwd()
        os.chdir(os.path.dirname(pathname))
        tfile = os.fdopen(handle, 'wb')
        fmt.format(tokensource, tfile)
        tfile.close()
        try:
            import subprocess
            po = subprocess.Popen(['latex', '-interaction=nonstopmode',
                                   pathname], stdout=subprocess.PIPE)
            ret = po.wait()
            output = po.stdout.read()
            po.stdout.close()
        except OSError:
            # latex not available
            pass
        else:
            if ret:
                print output
            self.assertFalse(ret, 'latex run reported errors')

        os.unlink(pathname)
        os.chdir(old_wd)