summaryrefslogtreecommitdiff
path: root/tests/test_examplefiles.py
diff options
context:
space:
mode:
authorBenjamin Peterson <devnull@localhost>2008-09-18 21:21:36 -0500
committerBenjamin Peterson <devnull@localhost>2008-09-18 21:21:36 -0500
commita1444aa1a7ce57dd6453a6e7a4a6adfe116d0d52 (patch)
treebdc335750421a046073a1948054cd1589ed8e622 /tests/test_examplefiles.py
parent88a938f2989ddeb8b0141116a8dfb38408ae7cb0 (diff)
downloadpygments-a1444aa1a7ce57dd6453a6e7a4a6adfe116d0d52.tar.gz
make use of test generators for test_examplefiles
Diffstat (limited to 'tests/test_examplefiles.py')
-rw-r--r--tests/test_examplefiles.py54
1 files changed, 24 insertions, 30 deletions
diff --git a/tests/test_examplefiles.py b/tests/test_examplefiles.py
index 52ff3093..2ebb2101 100644
--- a/tests/test_examplefiles.py
+++ b/tests/test_examplefiles.py
@@ -16,37 +16,31 @@ from pygments.token import Error
from pygments.util import ClassNotFound
-class ExampleFileTest(unittest.TestCase):
- pass
-
-lfd = 0
-
# generate methods
-testdir = os.path.dirname(__file__)
-for fn in os.listdir(os.path.join(testdir, 'examplefiles')):
- absfn = os.path.join(testdir, 'examplefiles', fn)
- if not os.path.isfile(absfn):
- continue
+def test_example_files():
+ testdir = os.path.dirname(__file__)
+ 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 ClassNotFound:
try:
- name, rest = fn.split("_", 1)
- lx = get_lexer_by_name(name)
+ lx = get_lexer_for_filename(absfn)
except ClassNotFound:
- 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'
- text = text.decode('latin1')
- ntext = []
- for type, val in lx.get_tokens(text):
- ntext.append(val)
- self.failIf(type == Error, 'lexer generated error token for '+absfn)
- if u''.join(ntext) != text:
- self.fail('round trip failed for '+absfn)
-
- setattr(ExampleFileTest, 'test_%i' % lfd, test)
- lfd += 1
+ try:
+ name, rest = fn.split("_", 1)
+ lx = get_lexer_by_name(name)
+ except ClassNotFound:
+ raise AssertionError('no lexer found for file %r' % fn)
+ yield check_lexer, lx, absfn
+
+def check_lexer(lx, absfn):
+ text = file(absfn, 'U').read()
+ text = text.strip('\n') + '\n'
+ text = text.decode('latin1')
+ ntext = []
+ for type, val in lx.get_tokens(text):
+ ntext.append(val)
+ assert type != Error, 'lexer generated error token for ' + absfn
+ if u''.join(ntext) != text:
+ raise AssertionError('round trip failed for ' + absfn)