summaryrefslogtreecommitdiff
path: root/testtools/tests
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2015-12-04 13:54:33 +0000
committerJonathan Lange <jml@mumak.net>2015-12-04 13:54:33 +0000
commit8348d35a80b429ceef063996f22c9401122bed1a (patch)
tree10c39d11377f2f984ffb9f131c6004a099272123 /testtools/tests
parent28bd2dc9efd31bd8cb09d9b2d9ec7b1ddc491964 (diff)
downloadtesttools-8348d35a80b429ceef063996f22c9401122bed1a.tar.gz
Start to use generated behaviors
Diffstat (limited to 'testtools/tests')
-rw-r--r--testtools/tests/samplecases.py59
-rw-r--r--testtools/tests/test_testcase.py28
2 files changed, 65 insertions, 22 deletions
diff --git a/testtools/tests/samplecases.py b/testtools/tests/samplecases.py
index 1f3ec20..c7cb7f0 100644
--- a/testtools/tests/samplecases.py
+++ b/testtools/tests/samplecases.py
@@ -91,6 +91,38 @@ def _unexpected_success(case):
case.expectFailure('arbitrary unexpected success', _success)
+behaviors = [
+ ('success', _success),
+ ('fail', _failure),
+ ('error', _error),
+ ('skip', _skip),
+ ('xfail', _expected_failure),
+ ('uxsuccess', _unexpected_success),
+]
+
+
+def _make_behavior_scenarios(stage):
+ """Given a test stage, iterate over behavior scenarios for that stage.
+
+ e.g.
+ >>> list(_make_behavior_scenarios('setUp'))
+ [('setUp=success', {'setUp_behavior': <function _success>}),
+ ('setUp=fail', {'setUp_behavior': <function _failure>}),
+ ('setUp=error', {'setUp_behavior': <function _error>}),
+ ('setUp=skip', {'setUp_behavior': <function _skip>}),
+ ('setUp=xfail', {'setUp_behavior': <function _expected_failure>),
+ ('setUp=uxsuccess',
+ {'setUp_behavior': <function _unexpected_success>})]
+
+ Ordering is not consistent.
+ """
+ return (
+ ('%s=%s' % (stage, behavior),
+ {'%s_behavior' % (stage,): function})
+ for (behavior, function) in behaviors
+ )
+
+
class _TearDownFails(TestCase):
"""Passing test case with failing tearDown after upcall."""
@@ -162,25 +194,14 @@ def _test_error_traceback(case, traceback_matcher):
A list that can be used with testscenarios to test every deterministic sample
case that we have.
"""
-deterministic_sample_cases_scenarios = [
- ('simple-success-test', {
- 'case': make_test_case('test_success', test_body=_success)
- }),
- ('simple-error-test', {
- 'case': make_test_case('test_error', test_body=_error)
- }),
- ('simple-failure-test', {
- 'case': make_test_case('test_failure', test_body=_failure)
- }),
- ('simple-expected-failure-test', {
- 'case': make_test_case('test_failure', test_body=_expected_failure)
- }),
- ('simple-unexpected-success-test', {
- 'case': make_test_case('test_failure', test_body=_unexpected_success)
- }),
- ('simple-skip-test', {
- 'case': make_test_case('test_failure', test_body=_skip)
- }),
+deterministic_sample_cases_scenarios = _make_behavior_scenarios('body')
+
+
+"""
+A list that can be used with testscenarios to test deterministic cases
+that we cannot easily construct from our test behavior matrix.
+"""
+special_deterministic_sample_cases_scenarios = [
('teardown-fails', {'case': _TearDownFails('test_success')}),
]
diff --git a/testtools/tests/test_testcase.py b/testtools/tests/test_testcase.py
index ce16c19..7f5bfdf 100644
--- a/testtools/tests/test_testcase.py
+++ b/testtools/tests/test_testcase.py
@@ -29,13 +29,10 @@ from testtools.content import (
TracebackContent,
)
from testtools.matchers import (
- AfterPreprocessing,
- AllMatch,
Annotate,
DocTestMatches,
Equals,
HasLength,
- MatchesAll,
MatchesException,
Raises,
)
@@ -56,7 +53,9 @@ from testtools.tests.helpers import (
)
from testtools.tests.samplecases import (
deterministic_sample_cases_scenarios,
+ make_test_case,
nondeterministic_sample_cases_scenarios,
+ special_deterministic_sample_cases_scenarios,
)
@@ -1287,6 +1286,29 @@ class TestRunTwiceDeterminstic(TestCase):
# Tests that are intrinsically determistic can be run twice and
# produce exactly the same results each time, without need for
# explicit resetting or reconstruction.
+
+ # XXX: jml: before resubmitting. Although make_test_case should be
+ # exported, it's a bit wrong to be relying on internal details of the
+ # scenario generation here.
+ test = make_test_case('test_arbitrary', test_body=self.body_behavior)
+ first_result = ExtendedTestResult()
+ test.run(first_result)
+ second_result = ExtendedTestResult()
+ test.run(second_result)
+ self.assertEqual(first_result._events, second_result._events)
+
+
+class TestRunTwiceDeterminsticSpecial(TestCase):
+ """Can we run the same test case twice?"""
+
+ run_tests_with = FullStackRunTest
+
+ scenarios = special_deterministic_sample_cases_scenarios
+
+ def test_runTwice(self):
+ # Tests that are intrinsically determistic can be run twice and
+ # produce exactly the same results each time, without need for
+ # explicit resetting or reconstruction.
test = self.case
first_result = ExtendedTestResult()
test.run(first_result)