Permalink
Browse files

Added functional test for test cases, implemented testName and descri…

…beTest plugin hooks.
  • Loading branch information...
1 parent 2410896 commit a942398ffd58bc25e656842bd2ebd4472c893243 @jpellerin jpellerin committed Apr 13, 2007
Showing with 153 additions and 23 deletions.
  1. +4 −0 PLUGIN_API_CHANGES.txt
  2. +1 −0 TODO
  3. +54 −0 functional_tests/test_attribute_plugin.py
  4. +38 −0 functional_tests/test_cases.py
  5. +7 −2 nose/case.py
  6. +49 −21 nose/plugins/base.py
View
@@ -18,6 +18,8 @@ New methods available:
* beforeTest
+* describeTest
+
* formatError
* formatFailure
@@ -31,3 +33,5 @@ New methods available:
* prepareTestResult
* prepareTestRunner
+
+* testName
View
1 TODO
@@ -28,6 +28,7 @@ Failure test logs can be more informative
before/after Directory
before/after Import
before/after Context [in suite, call with parent]
+describeTest
makeTest
when result prints final result, patch in error classes, eg,
@@ -0,0 +1,54 @@
+import os
+import unittest
+from nose.plugins.attrib import AttributeSelector
+from nose.plugins import PluginTester
+
+support = os.path.join(os.path.dirname(__file__), 'support')
+
+class TestSimpleAttribute(PluginTester, unittest.TestCase):
+ activate = "-a a"
+ args = ['-v']
+ plugins = [AttributeSelector()]
+ suitepath = os.path.join(support, 'att')
+
+ def runTest(self):
+ print '*' * 70
+ print str(self.output)
+ print '*' * 70
+
+ assert 'test_attr.test_one ... ok' in self.output
+ assert 'test_attr.test_two ... ok' in self.output
+ assert 'TestClass.test_class_one ... ok' in self.output
+ assert 'TestClass.test_class_two ... ok' in self.output
+ assert 'TestClass.test_class_three ... ok' in self.output
+ assert 'test_three' not in self.output
+ assert 'test_case_two' not in self.output
+ assert 'test_case_one' not in self.output
+ assert 'test_case_three' not in self.output
+
+class TestAttributeValue(PluginTester, unittest.TestCase):
+ activate = "-a b=2"
+ args = ['-v']
+ plugins = [AttributeSelector()]
+ suitepath = os.path.join(support, 'att')
+
+ def runTest(self):
+ print '*' * 70
+ print str(self.output)
+ print '*' * 70
+
+ assert 'test_attr.test_one ... ok' not in self.output
+ assert 'test_attr.test_two ... ok' not in self.output
+ assert 'test_attr.test_three ... ok' not in self.output
+ assert 'TestClass.test_class_one ... ok' not in self.output
+ assert 'TestClass.test_class_two ... ok' in self.output
+ assert 'TestClass.test_class_three ... ok' not in self.output
+ assert 'test_case_two' in self.output
+ assert 'test_case_one' in self.output
+ assert 'test_case_three' in self.output
+
+
+if __name__ == '__main__':
+ #import logging
+ #logging.basicConfig(level=logging.DEBUG)
+ unittest.main()
@@ -0,0 +1,38 @@
+import unittest
+from nose.config import Config
+from nose import case
+from nose.plugins import Plugin, PluginManager
+
+class TestTestCasePluginCalls(unittest.TestCase):
+
+ def test_describe_test_called(self):
+ class Descrip(Plugin):
+ counter = 0
+ enabled = True
+ def describeTest(self, test):
+ return "test #%s" % id(test)
+ def testName(self, test):
+ self.counter += 1
+ return "(%s) test" % self.counter
+
+ class TC(unittest.TestCase):
+ def test_one(self):
+ pass
+ def test_two(self):
+ pass
+
+ config = Config(plugins=PluginManager(plugins=[Descrip()]))
+
+ c1 = case.Test(TC('test_one'), config=config)
+ c2 = case.Test(TC('test_two'), config=config)
+
+ self.assertEqual(str(c1), '(1) test')
+ self.assertEqual(str(c2), '(2) test')
+ assert c1.shortDescription().startswith('test #'), \
+ "Unexpected shortDescription: %s" % c1.shortDescription()
+ assert c2.shortDescription().startswith('test #'), \
+ "Unexpected shortDescription: %s" % c2.shortDescription()
+
+
+if __name__ == '__main__':
+ unittest.main()
View
@@ -54,14 +54,17 @@ def __init__(self, test, config=None, resultProxy=None):
self.assertDetails = None
self.capturedOutput = None
self.resultProxy = resultProxy
+ self.plugins = config.plugins
unittest.TestCase.__init__(self)
def __call__(self, *arg, **kwarg):
log.debug("Test call %s %s %s", self, arg, kwarg)
return self.run(*arg, **kwarg)
def __str__(self):
- # FIXME plugins.testName(self)
+ name = self.plugins.testName(self)
+ if name is not None:
+ return name
return str(self.test)
def __repr__(self):
@@ -136,7 +139,9 @@ def runTest(self, result):
self.test(result)
def shortDescription(self):
- # FIXME plugins.describeTest(self)
+ desc = self.plugins.describeTest(self)
+ if desc is not None:
+ return desc
return self.test.shortDescription()
View
@@ -174,36 +174,19 @@ def addOptions(self, parser, env=os.environ):
Do *not* return a value from this method unless you want to stop
all other plugins from setting their options.
- """
- pass
- add_options = addOptions
-
- def afterTest(self, test):
- """Called after the test has been run and the result recorded
- (after stopTest).
- Parameters:
- * test:
- test test case
+ DEPRECATED
"""
pass
- afterTest._new = True
-
- def beforeTest(self, test):
- """Called before the test is run (before startTest).
-
- Parameters:
- * test:
- test test case
- """
- pass
- beforeTest._new = True
+ add_options = addOptions
def addDeprecated(self, test, err):
"""Called when a deprecated test is seen. DO NOT return a value
unless you want to stop other plugins from seeing the deprecated
test.
+ DEPRECATED
+
Parameters:
* test:
the test case
@@ -245,6 +228,8 @@ def addSkip(self, test, err):
"""Called when a test is skipped. DO NOT return a value unless
you want to stop other plugins from seeing the skipped test.
+ DEPRECATED
+
Parameters:
* test:
the test case
@@ -262,6 +247,27 @@ def addSuccess(self, test, capt):
Captured output, if any.
"""
pass
+
+ def afterTest(self, test):
+ """Called after the test has been run and the result recorded
+ (after stopTest).
+
+ Parameters:
+ * test:
+ test test case
+ """
+ pass
+ afterTest._new = True
+
+ def beforeTest(self, test):
+ """Called before the test is run (before startTest).
+
+ Parameters:
+ * test:
+ test test case
+ """
+ pass
+ beforeTest._new = True
def begin(self):
"""Called before any tests are collected or run. Use this to
@@ -288,6 +294,16 @@ def finalize(self, result):
"""
pass
+ def describeTest(self, test):
+ """Return a test description. Called by test.shortDescription.
+
+ Parameters:
+ * test:
+ the test case
+ """
+ pass
+ describeTest._new = True
+
def formatError(self, test, err):
"""Called in result.addError, before plugin.addError. If you
want to replace or modify the error tuple, return a new error
@@ -399,6 +415,8 @@ def loadTestsFromTestCase(self, cls):
not able to load any tests, or an iterable if you are. May be a
generator.
+ DEPRECATE?
+
Parameters:
* cls:
The test case class
@@ -511,6 +529,16 @@ def stopTest(self, test):
"""
pass
+ def testName(self, test):
+ """Return a short test name. Called by test.__str__.
+
+ Parameters:
+ * test:
+ the test case
+ """
+ pass
+ testName._new = True
+
def wantClass(self, cls):
"""Return true if you want the main test selector to collect
tests from this class, false if you don't, and None if you don't

0 comments on commit a942398

Please sign in to comment.