summaryrefslogtreecommitdiff
path: root/unit_tests
diff options
context:
space:
mode:
authorMichael Killough <michaeljkillough@gmail.com>2014-01-03 20:13:12 +0000
committerMichael Killough <michaeljkillough@gmail.com>2014-01-03 20:13:12 +0000
commitac7f05e6dbc018c0a8c67015ce5fae1b60ff53c2 (patch)
tree0289ed0e508acf4db9a27b8ab7a0e42fa9f67dce /unit_tests
parent49aa9934d00596b6909facabec7cd0718ccfd910 (diff)
downloadnose-ac7f05e6dbc018c0a8c67015ce5fae1b60ff53c2.tar.gz
Add test that transplants a function generator
Currently failing due to issue 501. When the test is transplanted it is wrapped in another function, which means that inspect.isgeneratorfunction() returns False. There is already a fix for this in pull 620.
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/test_loader.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/unit_tests/test_loader.py b/unit_tests/test_loader.py
index 1f622a5..e2dfcc4 100644
--- a/unit_tests/test_loader.py
+++ b/unit_tests/test_loader.py
@@ -35,6 +35,8 @@ def mods():
M['test_module_with_metaclass_tests'] = imp.new_module(
'test_module_with_metaclass_tests')
M['test_transplant'] = imp.new_module('test_transplant')
+ M['test_module_transplant_generator'] = imp.new_module(
+ 'test_module_transplant_generator')
# a unittest testcase subclass
class TC(unittest.TestCase):
@@ -112,6 +114,14 @@ def mods():
def runTest(self):
pass
+ def test_func_generator_transplant():
+ """docstring for transplanted test func generator
+ """
+ def test_odd(v):
+ assert v % 2
+ for i in range(0, 4):
+ yield test_odd, i
+
M['nose'] = nose
M['__main__'] = sys.modules['__main__']
M['test_module'].TC = TC
@@ -133,6 +143,9 @@ def mods():
TestMetaclassed.__module__ = 'test_module_with_metaclass_tests'
M['test_transplant'].Transplant = Transplant
Transplant.__module__ = 'test_class_source'
+ M['test_module_transplant_generator'].test_func_generator_transplant = \
+ test_func_generator_transplant
+ # don't set test_func_generator_transplant.__module__ so it is transplanted
del TC
del TC2
del TestMetaclassed
@@ -141,6 +154,7 @@ def mods():
del TestClass
del test_func_generator
del Transplant
+ del test_func_generator_transplant
return M
M = mods()
@@ -514,7 +528,37 @@ class TestTestLoader(unittest.TestCase):
count += 1
assert count == 4, \
"Expected to generate 4 tests, but got %s" % count
-
+
+ def test_load_transplanted_generator(self):
+ print "load transplanted generator (issue 501)"
+ test_module_transplant_generator = M['test_module_transplant_generator']
+ l = self.l
+ suite = l.loadTestsFromModule(test_module_transplant_generator)
+ tests = [t for t in suite]
+
+ assert len(tests) == 1
+ print "test", tests[0]
+ assert isinstance(tests[0], unittest.TestSuite), \
+ "Test is not a suite - probably did not look like a generator"
+
+ count = 0
+ for t in tests[0]:
+ print "generated test %s" % t
+ print t.shortDescription()
+ assert isinstance(t, nose.case.Test), \
+ "Test %s is not a Test?" % t
+ assert isinstance(t.test, nose.case.FunctionTestCase), \
+ "Test %s is not a FunctionTestCase" % t.test
+ assert 'test_func_generator' in str(t), \
+ "Bad str val '%s' for test" % str(t)
+ assert 'docstring for transplanted test func generator' \
+ in t.shortDescription(), \
+ "Bad shortDescription '%s' for test %s" % \
+ (t.shortDescription(), t)
+ count += 1
+ assert count == 4, \
+ "Expected to generate 4 tests, but got %s" % count
+
if __name__ == '__main__':
#import logging
#logging.basicConfig(level=logging.DEBUG)