summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2010-02-01 15:49:05 +1100
committerRobert Collins <robertc@robertcollins.net>2010-02-01 15:49:05 +1100
commite659415fc6f0a437d475beb0e4655d03cefb5c18 (patch)
tree3b5eabc6d3cafe5413507753dd67d3ecfe2bf376
parent7b795c0b42770ec978805db3db3d1b99270e6e16 (diff)
parentcdfb53972b4c7c15c0060f90d8079b630d3421ee (diff)
downloadtestscenarios-git-e659415fc6f0a437d475beb0e4655d03cefb5c18.tar.gz
Merge patch from Ben Finney making tests with a shortDescription have that altered as well as the id.
-rw-r--r--Makefile2
-rw-r--r--NEWS7
-rw-r--r--lib/testscenarios/__init__.py2
-rw-r--r--lib/testscenarios/scenarios.py7
-rw-r--r--lib/testscenarios/tests/test_scenarios.py47
-rwxr-xr-xsetup.py2
6 files changed, 56 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 75e780d..c38edf6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
PYTHONPATH:=$(shell pwd)/lib:${PYTHONPATH}
PYTHON ?= python
-all:
+all: check
check:
PYTHONPATH=$(PYTHONPATH) $(PYTHON) -m testtools.run \
diff --git a/NEWS b/NEWS
index 7be0609..311d576 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,13 @@ testscenarios release notes
IN DEVELOPMENT
~~~~~~~~~~~~~~
+0.2
+~~~
+
+CHANGES:
+
+* Adjust the cloned tests ``shortDescription`` if one is present. (Ben Finney)
+
0.1
~~~
diff --git a/lib/testscenarios/__init__.py b/lib/testscenarios/__init__.py
index 9d762d6..d608f13 100644
--- a/lib/testscenarios/__init__.py
+++ b/lib/testscenarios/__init__.py
@@ -38,7 +38,7 @@ methods for details.
# established at this point, and setup.py will use a version of next-$(revno).
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
# Otherwise it is major.minor.micro~$(revno).
-__version__ = (0, 1, 0, 'final', 0)
+__version__ = (0, 2, 0, 'final', 0)
__all__ = [
'TestWithScenarios',
diff --git a/lib/testscenarios/scenarios.py b/lib/testscenarios/scenarios.py
index 7d781a7..e531b2e 100644
--- a/lib/testscenarios/scenarios.py
+++ b/lib/testscenarios/scenarios.py
@@ -35,8 +35,13 @@ def apply_scenario((name, parameters), test):
:param test: The test to apply the scenario to. This test is unaltered.
:return: A new test cloned from test, with the scenario applied.
"""
+ scenario_suffix = '(' + name + ')'
newtest = clone_test_with_new_id(test,
- test.id() + '(' + name + ')')
+ test.id() + scenario_suffix)
+ test_desc = test.shortDescription()
+ if test_desc is not None:
+ newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
+ newtest.shortDescription = (lambda: newtest_desc)
for key, value in parameters.iteritems():
setattr(newtest, key, value)
return newtest
diff --git a/lib/testscenarios/tests/test_scenarios.py b/lib/testscenarios/tests/test_scenarios.py
index cf6685d..4c80150 100644
--- a/lib/testscenarios/tests/test_scenarios.py
+++ b/lib/testscenarios/tests/test_scenarios.py
@@ -104,17 +104,50 @@ class TestGenerateScenarios(testtools.TestCase):
class TestApplyScenario(testtools.TestCase):
- def test_apply_scenario_sets_id_and_attributes(self):
+ def setUp(self):
+ super(TestApplyScenario, self).setUp()
+
+ self.scenario_name = 'demo'
+ self.scenario_attrs = {'foo': 'bar'}
+ self.scenario = (self.scenario_name, self.scenario_attrs)
+
class ReferenceTest(unittest.TestCase):
def test_pass(self):
pass
- test = ReferenceTest("test_pass")
- result = apply_scenario(('demo', {'foo': 'bar'}), test)
- self.assertEqual(
- 'testscenarios.tests.test_scenarios.ReferenceTest.test_pass(demo)',
- result.id())
- self.assertEqual('bar', result.foo)
+ def test_pass_with_docstring(self):
+ """ The test that always passes.
+
+ This test case has a PEP 257 conformant docstring,
+ with its first line being a brief synopsis and the
+ rest of the docstring explaining that this test
+ does nothing but pass unconditionally.
+
+ """
+ pass
+ self.ReferenceTest = ReferenceTest
+
+ def test_sets_specified_id(self):
+ raw_test = self.ReferenceTest('test_pass')
+ raw_id = "testscenarios.tests.test_scenarios.ReferenceTest.test_pass"
+ scenario_name = self.scenario_name
+ expect_id = "%(raw_id)s(%(scenario_name)s)" % vars()
+ modified_test = apply_scenario(self.scenario, raw_test)
+ self.assertEqual(expect_id, modified_test.id())
+
+ def test_sets_specified_attributes(self):
+ raw_test = self.ReferenceTest('test_pass')
+ modified_test = apply_scenario(self.scenario, raw_test)
+ self.assertEqual('bar', modified_test.foo)
+
+ def test_appends_scenario_name_to_short_description(self):
+ raw_test = self.ReferenceTest('test_pass_with_docstring')
+ modified_test = apply_scenario(self.scenario, raw_test)
+ raw_doc = self.ReferenceTest.test_pass_with_docstring.__doc__
+ raw_desc = raw_doc.split("\n")[0].strip()
+ scenario_name = self.scenario_name
+ expect_desc = "%(raw_desc)s (%(scenario_name)s)" % vars()
+ self.assertEqual(expect_desc, modified_test.shortDescription())
class TestApplyScenarios(testtools.TestCase):
diff --git a/setup.py b/setup.py
index 8f71543..d974b0f 100755
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
from distutils.core import setup
setup(name="testscenarios",
- version="0.1",
+ version="0.2",
description="Testscenarios, a pyunit extension for dependency injection",
maintainer="Robert Collins",
maintainer_email="robertc@robertcollins.net",