Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execute deferred steps in sequence rather than in parallel, don't har…
…d-depend on twisted, support custom twisted reactor implementation, prepare userspace selection of test class (refs #25)
- Loading branch information
Showing
5 changed files
with
156 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#-*- coding: utf8 -*- | ||
|
||
import traceback | ||
import sys | ||
|
||
from freshen.context import ftc, scc | ||
from freshen.stepregistry import UndefinedStepImpl | ||
|
||
|
||
class ExceptionWrapper(Exception): | ||
|
||
def __init__(self, e, step, discard_frames=0): | ||
e = list(e) | ||
while discard_frames: | ||
e[2] = e[2].tb_next | ||
discard_frames -= 1 | ||
self.e = e | ||
self.step = step | ||
|
||
def __str__(self): | ||
return "".join(traceback.format_exception(*self.e)) | ||
|
||
|
||
class FeatureSuite(object): | ||
|
||
def setUp(self): | ||
#log.debug("Clearing feature context") | ||
ftc.clear() | ||
|
||
|
||
class FreshenTestCase(object): | ||
|
||
start_live_server = True | ||
database_single_transaction = True | ||
database_flush = True | ||
selenium_start = False | ||
no_database_interaction = False | ||
make_translations = True | ||
required_sane_plugins = ["django", "http"] | ||
django_plugin_started = False | ||
http_plugin_started = False | ||
last_step = None | ||
|
||
test_type = "http" | ||
|
||
def __init__(self, step_runner, step_registry, feature, scenario, feature_suite): | ||
self.feature = feature | ||
self.scenario = scenario | ||
self.context = feature_suite | ||
self.step_registry = step_registry | ||
self.step_runner = step_runner | ||
|
||
self.description = feature.name + ": " + scenario.name | ||
super(FreshenTestCase, self).__init__() | ||
|
||
def setUp(self): | ||
#log.debug("Clearing scenario context") | ||
scc.clear() | ||
for hook_impl in self.step_registry.get_hooks('before', self.scenario.get_tags()): | ||
hook_impl.run(self.scenario) | ||
|
||
def runAfterStepHooks(self): | ||
for hook_impl in reversed(self.step_registry.get_hooks('after_step', self.scenario.get_tags())): | ||
hook_impl.run(self.scenario) | ||
|
||
def runStep(self, step, discard_frames=0): | ||
try: | ||
self.last_step = step | ||
return self.step_runner.run_step(step) | ||
except (AssertionError, UndefinedStepImpl, ExceptionWrapper): | ||
raise | ||
except: | ||
raise ExceptionWrapper(sys.exc_info(), step, discard_frames) | ||
self.runAfterStepHooks() | ||
|
||
def runTest(self): | ||
raise NotImplementedError('Must be implemented by subclasses') | ||
|
||
def tearDown(self): | ||
for hook_impl in reversed(self.step_registry.get_hooks('after', self.scenario.get_tags())): | ||
hook_impl.run(self.scenario) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#-*- coding: utf8 -*- | ||
|
||
from freshen.test.base import FreshenTestCase | ||
|
||
from unittest import TestCase | ||
|
||
|
||
class PyunitTestCase(FreshenTestCase, TestCase): | ||
"""Support PyUnit tests.""" | ||
|
||
def __init__(self, step_runner, step_registry, feature, scenario, feature_suite): | ||
FreshenTestCase.__init__(self, step_runner, step_registry, | ||
feature, scenario, feature_suite) | ||
TestCase.__init__(self) | ||
|
||
def runTest(self): | ||
for step in self.scenario.iter_steps(): | ||
self.runStep(step, 3) | ||
self.last_step = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#-*- coding: utf8 -*- | ||
|
||
from freshen.test.base import FreshenTestCase | ||
|
||
from twisted.trial.unittest import TestCase | ||
from twisted.internet.defer import inlineCallbacks, Deferred | ||
|
||
class TwistedTestCase(FreshenTestCase, TestCase): | ||
"""Support asynchronous feature tests.""" | ||
|
||
# pylint: disable=R0913 | ||
def __init__(self, step_runner, step_registry, | ||
feature, scenario, feature_suite): | ||
FreshenTestCase.__init__(self, step_runner, step_registry, | ||
feature, scenario, feature_suite) | ||
TestCase.__init__(self) | ||
|
||
@inlineCallbacks | ||
def runTest(self): | ||
for step in self.scenario.iter_steps(): | ||
result = self.runStep(step) | ||
if isinstance(result, Deferred): | ||
yield result | ||
self.last_step = None |