summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2007-02-14 17:50:02 +0100
committergbrandl <devnull@localhost>2007-02-14 17:50:02 +0100
commit0dcd117d4e662c8a85aef4b312e2cb795a0e7d52 (patch)
tree0aad94cbc5bcd465f49a2f2d24d4e44e58c14516 /tests
parent1c8ddc632f1eb5550f98b8185b1b820069cb8efb (diff)
downloadpygments-0dcd117d4e662c8a85aef4b312e2cb795a0e7d52.tar.gz
[svn] A test case for the external CSS function of the HTML formatter.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_html_formatter.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index ba3ed69e..5297d1f0 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -12,21 +12,42 @@ import unittest
import StringIO
import random
import tempfile
+from os.path import join, dirname, isfile
from pygments import lexers, formatters
from pygments.token import _TokenType
from pygments.formatters import HtmlFormatter
from pygments.lexers import PythonLexer
+tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read()))
+
class HtmlFormatterTest(unittest.TestCase):
-# TODO: write this test.
-# def test_external_css(self):
-# pass
+ def test_external_css(self):
+ # test correct behavior
+ # CSS should be in /tmp directory
+ fmt1 = HtmlFormatter(full=True, cssfile='fmt1.css')
+ # CSS should be in testdir (testdir is absolute)
+ fmt2 = HtmlFormatter(full=True, cssfile=join(testdir, 'fmt2.css'))
+ tfile = tempfile.NamedTemporaryFile(suffix='.html')
+ fmt1.format(tokensource, tfile)
+ try:
+ fmt2.format(tokensource, tfile)
+ except IOError:
+ # test directory not writable
+ pass
+ tfile.close()
+
+ self.assert_(isfile(join(dirname(tfile.name), 'my.css')))
+
+ os.unlink(join(dirname(tfile.name), 'fmt1.css'))
+ try:
+ os.unlink(join(testdir, 'fmt2.css'))
+ except OSError:
+ pass
+
def test_all_options(self):
- tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read()))
-
for optdict in [dict(nowrap=True),
dict(linenos=True),
dict(linenos=True, full=True),
@@ -37,13 +58,10 @@ class HtmlFormatterTest(unittest.TestCase):
fmt.format(tokensource, outfile)
def test_valid_output(self):
- tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read()))
+ # test all available wrappers
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()
@@ -64,4 +82,3 @@ class HtmlFormatterTest(unittest.TestCase):
self.failIf(ret, 'nsgmls run reported errors')
os.unlink(pathname)
- os.chdir(old_wd)