def reset_runtime(): """Reset runtime environment. Best effort to reset module data to initial state. """ from behave import step_registry from behave import matchers # -- RESET 1: behave.step_registry step_registry.registry = step_registry.StepRegistry() step_registry.setup_step_decorators(None, step_registry.registry) # -- RESET 2: behave.matchers matchers.ParseMatcher.custom_types = {} matchers.current_matcher = matchers.ParseMatcher
def test_find_match_with_no_match_returns_none(self): registry = step_registry.StepRegistry() step_defs = [Mock() for x in range(0, 10)] for mock in step_defs: mock.match.return_value = None registry.steps['when'] = step_defs step = Mock() step.step_type = 'when' step.name = 'just a test step' assert registry.find_match(step) is None
def test_add_step_definition_adds_to_lowercased_keyword(self): registry = step_registry.StepRegistry() with patch('behave.matchers.get_matcher') as get_matcher: func = lambda x: -x string = 'just a test string' magic_object = object() get_matcher.return_value = magic_object for step_type in registry.steps.keys(): l = [] registry.steps[step_type] = l registry.add_step_definition(step_type.upper(), string, func) get_matcher.assert_called_with(func, string) eq_(l, [magic_object])
def setUp(self): runner_ = Mock() self.config = runner_.config = Mock() runner_.config.verbose = False runner_.config.stdout_capture = False runner_.config.stderr_capture = False runner_.config.log_capture = False self.context = runner.Context(runner_) runner_.context = self.context self.context.feature = Mock() self.context.feature.parser = parser.Parser() if not self.step_registry: # -- SETUP ONCE: self.step_registry = step_registry.StepRegistry() ExampleSteps.register_steps_with(self.step_registry) ExampleSteps.text = None ExampleSteps.table = None
def test_add_step_definition_adds_to_lowercased_keyword(self): registry = step_registry.StepRegistry() # -- MONKEYPATCH-PROBLEM: # with patch('behave.matchers.get_matcher') as get_matcher: with patch('behave.step_registry.get_matcher') as get_matcher: func = lambda x: -x pattern = 'just a test string' magic_object = object() get_matcher.return_value = magic_object for step_type in list(registry.steps.keys()): l = [] registry.steps[step_type] = l registry.add_step_definition(step_type.upper(), pattern, func) get_matcher.assert_called_with(func, pattern) eq_(l, [magic_object])
def test_find_match_with_a_match_returns_match(self): registry = step_registry.StepRegistry() step_defs = [Mock() for x in range(0, 10)] for mock in step_defs: mock.match.return_value = None magic_object = object() step_defs[5].match.return_value = magic_object registry.steps['then'] = step_defs step = Mock() step.step_type = 'then' step.name = 'just a test step' assert registry.find_match(step) is magic_object for mock in step_defs[6:]: eq_(mock.match.call_count, 0)
def test_find_match_with_specific_step_type_also_searches_generic(self): registry = step_registry.StepRegistry() given_mock = Mock() given_mock.match.return_value = None step_mock = Mock() step_mock.match.return_value = None registry.steps['given'].append(given_mock) registry.steps['step'].append(step_mock) step = Mock() step.step_type = 'given' step.name = 'just a test step' assert registry.find_match(step) is None given_mock.match.assert_called_with(step.name) step_mock.match.assert_called_with(step.name)
def test_failed_step_causes_remaining_steps_to_be_skipped(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = True steps = [Mock(), Mock()] scenario = model.Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) steps[0].run.return_value = False steps[1].step_type = "when" steps[1].name = "step1" def step1_function(context): pass my_step_registry = step_registry.StepRegistry() my_step_registry.add_step_definition("when", "step1", step1_function) with patch("behave.step_registry.registry", my_step_registry): assert scenario.run(self.runner) eq_(steps[1].status, 'skipped')
def test_failed_step_causes_remaining_steps_to_be_skipped(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tag_expression.check.return_value = True # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario("foo.feature", 17, u"Scenario", u"foo", steps=steps) steps[0].run.return_value = False steps[1].step_type = "when" steps[1].name = "step1" def step1_function(context): # pylint: disable=unused-argument pass my_step_registry = step_registry.StepRegistry() my_step_registry.add_step_definition("when", "step1", step1_function) with patch("behave.step_registry.registry", my_step_registry): assert scenario.run(self.runner) assert steps[1].status == Status.skipped