Example #1
0
    def test_merge_steps(self):
        """
            Test merging steps from feature files with registered steps
        """
        matcher = Matcher()
        steps = {
            re.compile(r"Given I have the number (\d+)"): "some_func",
            re.compile(r"I add (\d+) to my number"): "some_other_func"
        }

        feature = Feature(1, "Feature", "Some feature", "test.feature", 1)
        scenario = Scenario(1, "Scenario", "Adding numbers", "test.feature", 2,
                            feature)
        scenario.steps.append(
            Step(1, "Given I have the number 5", "test.feature", 3, scenario,
                 False))
        scenario.steps.append(
            Step(2, "When I add 2 to my number", "test.feature", 4, scenario,
                 False))
        feature.scenarios.append(scenario)

        matcher.merge_steps([feature], steps)

        scenario.steps[0].definition_func.should.be.equal("some_func")
        scenario.steps[0].arguments.should.be.equal(("5", ))
        scenario.steps[1].definition_func.should.be.equal("some_other_func")
        scenario.steps[1].arguments.should.be.equal(("2", ))
Example #2
0
def run_features(core):
    """
        Run the parsed features

        :param Core core: the radish core object
    """
    # FIXME: load dynamically
    import radish.extensions.argumentexpressions
    import radish.extensions.time_recorder
    import radish.extensions.syslog_writer
    import radish.extensions.console_writer
    import radish.extensions.endreport_writer
    import radish.extensions.failure_inspector
    import radish.extensions.failure_debugger
    import radish.extensions.bdd_xml_writer

    # set needed configuration
    world.config.expand = True

    # load user's custom python files
    loader = Loader(world.config.basedir)
    loader.load_all()

    # match feature file steps with user's step definitions
    Matcher.merge_steps(core.features, StepRegistry().steps)

    # run parsed features
    if world.config.marker == "time.time()":
        world.config.marker = int(time())

    # scenario choice
    amount_of_scenarios = sum(len(f.scenarios) for f in core.features_to_run)
    if world.config.scenarios:
        world.config.scenarios = [int(s) for s in world.config.scenarios.split(",")]
        for s in world.config.scenarios:
            if s <= 0 or s > amount_of_scenarios:
                raise ScenarioNotFoundError(s, amount_of_scenarios)

    # tags
    if world.config.feature_tags:
        world.config.feature_tags = [t for t in world.config.feature_tags.split(",")]
        for tag in world.config.feature_tags:
            if not any(f for f in core.features if tag in [t.name for t in f.tags]):
                raise FeatureTagNotFoundError(tag)

    if world.config.scenario_tags:
        world.config.scenario_tags = [t for t in world.config.scenario_tags.split(",")]
        for tag in world.config.scenario_tags:
            if not any(s for f in core.features for s in f.scenarios if tag in [t.name for t in s.tags]):
                raise ScenarioTagNotFoundError(tag)

    runner = Runner(HookRegistry(), early_exit=world.config.early_exit)
    runner.start(core.features_to_run, marker=world.config.marker)
Example #3
0
    def test_merge_steps(self):
        """
            Test merging steps from feature files with registered steps
        """
        matcher = Matcher()
        steps = {re.compile(r"Given I have the number (\d+)"): "some_func", re.compile(r"I add (\d+) to my number"): "some_other_func"}

        feature = Feature(1, "Feature", "Some feature", "test.feature", 1)
        scenario = Scenario(1, "Scenario", "Adding numbers", "test.feature", 2, feature)
        scenario.steps.append(Step(1, "Given I have the number 5", "test.feature", 3, scenario, False))
        scenario.steps.append(Step(2, "When I add 2 to my number", "test.feature", 4, scenario, False))
        feature.scenarios.append(scenario)

        matcher.merge_steps([feature], steps)

        scenario.steps[0].definition_func.should.be.equal("some_func")
        scenario.steps[0].arguments.should.be.equal(("5",))
        scenario.steps[1].definition_func.should.be.equal("some_other_func")
        scenario.steps[1].arguments.should.be.equal(("2",))