summaryrefslogtreecommitdiff
path: root/tests/test_examplefiles.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2006-10-19 20:27:28 +0200
committergbrandl <devnull@localhost>2006-10-19 20:27:28 +0200
commitf4d019954468db777760d21f9243eca8b852c184 (patch)
tree328b8f8fac25338306b0e7b827686dcc7597df23 /tests/test_examplefiles.py
downloadpygments-f4d019954468db777760d21f9243eca8b852c184.tar.gz
[svn] Name change, round 4 (rename SVN root folder).
Diffstat (limited to 'tests/test_examplefiles.py')
-rw-r--r--tests/test_examplefiles.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_examplefiles.py b/tests/test_examplefiles.py
new file mode 100644
index 00000000..6347ab88
--- /dev/null
+++ b/tests/test_examplefiles.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+"""
+ Pygments tests with example files
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: 2006 by Georg Brandl.
+ :license: GNU GPL, see LICENSE for more details.
+"""
+
+import unittest
+import os
+
+from pygments import highlight
+from pygments.lexers import get_lexer_for_filename, get_lexer_by_name
+from pygments.token import Error
+
+
+class ExampleFileTest(unittest.TestCase):
+ pass
+
+lfd = 0
+
+# generate methods
+for fn in os.listdir(os.path.join(testdir, 'examplefiles')):
+ absfn = os.path.join(testdir, 'examplefiles', fn)
+ if not os.path.isfile(absfn):
+ continue
+
+ try:
+ lx = get_lexer_for_filename(absfn)
+ except ValueError:
+ try:
+ name, rest = fn.split("_", 1)
+ lx = get_lexer_by_name(name)
+ except ValueError:
+ raise AssertionError('no lexer found for file %r' % fn)
+
+ def test(self, lx=lx, absfn=absfn):
+ text = file(absfn, 'U').read()
+ text = text.strip('\n') + '\n'
+ ntext = ''
+ for type, val in lx.get_tokens(text):
+ ntext += val
+ self.failIf(type == Error, 'lexer generated error token for '+absfn)
+ if ntext != text:
+ self.fail('round trip failed for '+absfn)
+
+ setattr(ExampleFileTest, 'test_%i' % lfd, test)
+ lfd += 1