summaryrefslogtreecommitdiff
path: root/functional_tests
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2007-04-29 03:26:24 +0000
committerJason Pellerin <jpellerin@gmail.com>2007-04-29 03:26:24 +0000
commitd9b9b6d3de8e909869c9865f9bfefc022763bc57 (patch)
tree1a7047e044cbd48bde4a0bb28980516ae5b95c1c /functional_tests
parent6f3806be83e020d17ee86660686e4e4f73cc1e49 (diff)
downloadnose-d9b9b6d3de8e909869c9865f9bfefc022763bc57.tar.gz
Added functional test for testid/doctest integration when tests are from non-module files.
Diffstat (limited to 'functional_tests')
-rw-r--r--functional_tests/test_id_plugin.py86
1 files changed, 81 insertions, 5 deletions
diff --git a/functional_tests/test_id_plugin.py b/functional_tests/test_id_plugin.py
index ccc0819..7dd558c 100644
--- a/functional_tests/test_id_plugin.py
+++ b/functional_tests/test_id_plugin.py
@@ -1,4 +1,5 @@
import os
+import re
import sys
import tempfile
import unittest
@@ -10,6 +11,7 @@ from cPickle import dump, load
support = os.path.join(os.path.dirname(__file__), 'support')
idfile = tempfile.mktemp()
+test_part = re.compile(r'(#\d+)? +([^(]+)')
def teardown():
try:
@@ -110,7 +112,6 @@ class TestLoadNamesMode_2(PluginTester, unittest.TestCase):
self.assertEqual(count, 1)
-
class TestWithDoctest_1(PluginTester, unittest.TestCase):
activate = '--with-id'
plugins = [Doctest(), TestId()]
@@ -118,16 +119,24 @@ class TestWithDoctest_1(PluginTester, unittest.TestCase):
suitepath = os.path.join(support, 'idp')
def test_doctests_get_ids(self):
- print '>' * 70
- print str(self.output)
- print '>' * 70
+ #print '>' * 70
+ #print str(self.output)
+ #print '>' * 70
last = None
for line in self.output:
if line.startswith('='):
break
+ if not line.strip():
+ continue
# assert line startswith # or test part matches last
-
+ m = test_part.match(line.rstrip())
+ assert m
+ idx, name = m.groups()
+ assert idx or last is None or name == last, \
+ "Expected an id on line %s" % line.strip()
+ last = name
+
fh = open(idfile, 'r')
ids = load(fh)
fh.close()
@@ -167,6 +176,73 @@ class TestWithDoctest_2(PluginTester, unittest.TestCase):
count += 1
self.assertEqual(count, 1)
+
+class TestWithDoctestFileTests_1(PluginTester, unittest.TestCase):
+ activate = '--with-id'
+ plugins = [Doctest(), TestId()]
+ args = ['-v', '--id-file=%s' % idfile, '--with-doctest',
+ '--doctest-extension=.txt']
+ suitepath = os.path.join(support, 'dtt', 'docs')
+
+ def test_docfile_tests_get_ids(self):
+ print '>' * 70
+ print str(self.output)
+ print '>' * 70
+
+ last = None
+ for line in self.output:
+ if line.startswith('='):
+ break
+ # assert line startswith # or test part matches last
+ if not line.strip():
+ continue
+ m = test_part.match(line.rstrip())
+ assert m, "line %s does not match expected pattern" % line.strip()
+ idx, name = m.groups()
+ assert idx or last is None or name == last, \
+ "Expected an id on line %s" % line.strip()
+
+ last = name
+ fh = open(idfile, 'r')
+ ids = load(fh)
+ fh.close()
+ for key, (file, mod, call) in ids.items():
+ assert mod != 'doctest', \
+ "Doctest test was incorrectly identified as being part of "\
+ "the doctest module itself (#%s)" % key
+
+
+class TestWithDoctestFileTests_2(PluginTester, unittest.TestCase):
+ activate = '--with-id'
+ plugins = [Doctest(), TestId()]
+ args = ['-v', '--id-file=%s' % idfile, '--with-doctest',
+ '--doctest-extension=.txt', '2']
+ suitepath = None
+
+ def setUp(self):
+ sys.path.insert(0, os.path.join(support, 'dtt', 'docs'))
+ super(TestWithDoctestFileTests_2, self).setUp()
+
+ def tearDown(self):
+ sys.path.remove(os.path.join(support, 'dtt', 'docs'))
+ super(TestWithDoctestFileTests_2, self).tearDown()
+
+ def makeSuite(self):
+ return None
+
+ def test_load_from_name_id_docfile_test(self):
+ print '*' * 70
+ print str(self.output)
+ print '*' * 70
+
+ assert 'Doctest: errdoc.txt ... FAIL' in self.output
+
+ count = 0
+ for line in self.output:
+ if line.startswith('#'):
+ count += 1
+ assert count == 1
+
if __name__ == '__main__':
import logging