本文整理汇总了Python中lettuce.registry.CALLBACK_REGISTRY类的典型用法代码示例。如果您正苦于以下问题:Python CALLBACK_REGISTRY类的具体用法?Python CALLBACK_REGISTRY怎么用?Python CALLBACK_REGISTRY使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CALLBACK_REGISTRY类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_after_each_all_is_executed_before_each_all
def test_after_each_all_is_executed_before_each_all():
"terrain.before.each_all and terrain.after.each_all decorators"
import lettuce
from lettuce.fs import FeatureLoader
world.all_steps = []
loader_mock = mock.Mock(spec=FeatureLoader)
old_sys_path = lettuce.sys.path
old_fs = lettuce.fs
old_FileSystem = lettuce.fs.FileSystem
old_Feature = lettuce.Feature
lettuce.sys.path = mock.Mock(spec=old_sys_path)
lettuce.sys.path.insert = mock.Mock()
lettuce.sys.path.remove = mock.Mock()
lettuce.fs = mock.Mock(spec=old_fs)
lettuce.fs.FileSystem = mock.Mock(spec=old_FileSystem)
lettuce.Feature = mock.Mock(spec=old_Feature)
loader_mock.find_feature_files = mock.Mock(return_value=['some_basepath/foo.feature'])
lettuce.fs.FeatureLoader = mock.Mock(return_value=loader_mock)
lettuce.Feature.from_file = mock.Mock(return_value=Feature.from_string(FEATURE2))
runner = lettuce.Runner('some_basepath')
CALLBACK_REGISTRY.clear()
@before.all
def set_state_to_before():
world.all_steps.append('before')
@step('append "during" to states')
def append_during_to_all_steps(step):
world.all_steps.append("during")
@after.all
def set_state_to_after(total):
world.all_steps.append('after')
isinstance(total, TotalResult)
runner.run()
lettuce.sys.path.insert.assert_called_with(0, 'some_basepath')
lettuce.sys.path.remove.assert_called_with('some_basepath')
loader_mock.find_and_load_step_definitions.assert_called_once
lettuce.Feature.from_file.assert_called_once_with('some_basepath/foo.feature')
assert_equals(
world.all_steps,
['before', 'during', 'during', 'after'],
)
lettuce.sys.path = old_sys_path
lettuce.fs = old_fs
lettuce.fs.FileSystem = old_FileSystem
lettuce.Feature = old_Feature
示例2: inner
def inner(self, callback, name=None):
if not callable(callback):
name = callback
return lambda callback: inner(self, callback, name=name)
CALLBACK_REGISTRY.append_to(
where,
when.format(name=self.name),
function=callback,
name=name,
)
return callback
示例3: each_feature
def each_feature(cls, function):
CALLBACK_REGISTRY.append_to('feature', "%s_each" % cls.__name__, function)
return function
示例4: outline
def outline(cls, function):
CALLBACK_REGISTRY.append_to('scenario', "outline", function)
return function
示例5: each_scenario
def each_scenario(cls, function):
CALLBACK_REGISTRY.append_to('scenario', "%s_each" % cls.__name__, function)
return function
示例6: each_step
def each_step(cls, function):
CALLBACK_REGISTRY.append_to('step', "%s_each" % cls.__name__, function)
return function
示例7: all
def all(cls, function):
CALLBACK_REGISTRY.append_to('all', cls.__name__, function)
return function
示例8: method
def method(self, fn):
CALLBACK_REGISTRY.append_to(where, when % {'0': self.name}, fn)
return fn
示例9: handle_request
def handle_request(cls, function):
CALLBACK_REGISTRY.append_to('handle_request', cls.__name__, function)
return function
示例10: runserver
def runserver(cls, function):
CALLBACK_REGISTRY.append_to('runserver', cls.__name__, function)
return function
示例11: run
def run(self):
""" Find and load step definitions, and them find and load
features under `base_path` specified on constructor
"""
CALLBACK_REGISTRY.clear(name='output')
CALLBACK_REGISTRY.clear(name='common_output')
if self.verbosity is 0:
from lettuce.plugins import non_verbose as output
elif self.verbosity is 1:
from lettuce.plugins import dots as output
elif self.verbosity is 2:
from lettuce.plugins import scenario_names as output
elif self.verbosity is 3:
from lettuce.plugins import shell_output as output
else:
from lettuce.plugins import colored_shell_output as output
reload(output)
self.output = output
results = []
if self.single_feature:
features_files = [self.single_feature]
else:
features_files = self.loader.find_feature_files()
if self.random:
random.shuffle(features_files)
if not features_files:
self.output.print_no_features_found(self.loader.base_dir)
return
# only load steps if we've located some features.
# this prevents stupid bugs when loading django modules
# that we don't even want to test.
try:
self.loader.find_and_load_step_definitions()
except StepLoadingError as e:
print "Error loading step definitions:\n", e
raise SystemExit(3)
failed = False
try:
call_hook('before', 'all')
for filename in features_files:
feature = Feature.from_file(filename)
results.append(
feature.run(self.scenarios,
tags=self.tags,
random=self.random,
failfast=self.failfast))
except exceptions.LettuceSyntaxError as e:
sys.stderr.write(e.msg)
failed = True
except exceptions.FailFast:
print
print ("Lettuce aborted running any more tests "
"because was called with the `--failfast` option")
failed = True
except Exception:
# ensure our output is undiverted
sys.stdout = real_stdout
print "Exception in Lettuce itself!"
failed = True
raise
except BaseException:
failed = True
raise
finally:
total = TotalResult(results)
total.output_format()
call_hook('after', 'all', total)
if not total.passed:
failed = True
if failed:
raise SystemExit(2)
return total
示例12: method
def method(self, fn):
CALLBACK_REGISTRY.append_to(where, when.format(self.name), fn)
return fn