Exemplo n.º 1
0
    def test_running_all(self):
        """
            Test running a all features
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1)

        scenario = Scenario(1, 1, "Scenario", "Some scenario",
                            "somefile.feature", 2, feature)
        feature.scenarios.append(scenario)

        step = Step(1, "Some step", "somefile.feature", 3, scenario, True)
        step.definition_func = some_step
        argument_match_mock = Mock()
        argument_match_mock.evaluate.return_value = (tuple(), {})
        step.argument_match = argument_match_mock
        scenario.steps.append(step)

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        runner.start([feature], None)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
Exemplo n.º 2
0
    def test_running_all(self):
        """
            Test running a all features
        """
        data = threading.local()
        data.step_was_called = False

        def some_step(step):
            data.step_was_called = True

        feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1)

        scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature)
        feature.scenarios.append(scenario)

        step = Step(1, "Some step", "somefile.feature", 3, scenario, True)
        step.definition_func = some_step
        step.arguments = tuple()
        step.keyword_arguments = {}
        scenario.steps.append(step)

        hook_mock = Mock()
        hook_mock.call.return_value = True
        runner = Runner(hook_mock)
        runner.start([feature], None)
        step.state.should.be.equal(Step.State.PASSED)
        data.step_was_called.should.be.true
Exemplo n.º 3
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)
Exemplo n.º 4
0
def show_features(core):
    """
        Show the parsed features
    """
    # FIXME: load dynamically
    import radish.extensions.console_writer

    # set needed configuration
    world.config.write_steps_once = True
    if not sys.stdout.isatty():
        world.config.no_ansi = True

    runner = Runner(HookRegistry(), dry_run=True)
    runner.start(core.features_to_run, marker="show")
Exemplo n.º 5
0
def test_start_run_should_iterate_all_given_features(hook_registry,
                                                     default_config, mocker):
    """All Features given to run should be iterated"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_feature = mocker.MagicMock()

    first_feature = mocker.MagicMock(name="First Feature")
    second_feature = mocker.MagicMock(name="Second Feature")

    # when
    runner.start([first_feature, second_feature])

    # given
    runner.run_feature.assert_has_calls(
        [call(first_feature), call(second_feature)])
Exemplo n.º 6
0
def test_should_only_run_feature_which_have_to_run(hook_registry,
                                                   default_config, mocker):
    """The Runner should only run features which need to be run"""
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_feature = mocker.MagicMock()

    first_feature = mocker.MagicMock(name="First Feature")
    first_feature.has_to_run.return_value = True
    second_feature = mocker.MagicMock(name="Second Feature")
    second_feature.has_to_run.return_value = False
    third_feature = mocker.MagicMock(name="Third Feature")
    third_feature.has_to_run.return_value = True

    # when
    runner.start([first_feature, second_feature, third_feature])

    # given
    runner.run_feature.assert_has_calls(
        [call(first_feature), call(third_feature)])
Exemplo n.º 7
0
def test_should_exit_for_failed_feature_if_early_exit_set(
        hook_registry, default_config, mocker):
    """The Runner should exit early if a Feature failes if the early exit flag is set"""
    # given
    default_config.early_exit = True

    runner = Runner(default_config, None, hook_registry)
    runner.run_feature = mocker.MagicMock()
    runner.run_feature.side_effect = [State.PASSED, State.FAILED, State.PASSED]

    first_feature = mocker.MagicMock(name="First Feature")
    second_feature = mocker.MagicMock(name="Second Feature")
    third_feature = mocker.MagicMock(name="Third Feature")

    # when
    runner.start([first_feature, second_feature, third_feature])

    # given
    runner.run_feature.assert_has_calls(
        [call(first_feature), call(second_feature)])
Exemplo n.º 8
0
def test_start_run_without_features(hook_registry, default_config):
    """When starting the Runner without any Features it should pass and call the ``all`` hooks"""
    # given
    runner = Runner(default_config, None, hook_registry)

    # when
    status = runner.start([])

    # then
    assert status
    hook_registry.call.assert_has_calls(
        [call("all", "before", False, []),
         call("all", "after", False, [])])
Exemplo n.º 9
0
def test_should_return_good_status_if_all_features_passed(
        hook_registry, default_config, mocker):
    """
    The Runner should return a good status when finished if all features passed in normal mode
    """
    # given
    runner = Runner(default_config, None, hook_registry)
    runner.run_feature = mocker.MagicMock()
    runner.run_feature.side_effect = [State.PASSED, State.PASSED]

    first_feature = mocker.MagicMock(name="First Feature", state=State.PASSED)
    second_feature = mocker.MagicMock(name="Second Feature",
                                      state=State.PASSED)

    # when
    status = runner.start([first_feature, second_feature])

    # given
    assert status
Exemplo n.º 10
0
def test_should_return_good_status_if_all_features_failed_in_wip_mode(
        hook_registry, default_config, mocker):
    """
    The Runner should return a good status when finished if all features failed in WIP mode
    """
    # given
    default_config.wip_mode = True

    runner = Runner(default_config, None, hook_registry)
    runner.run_feature = mocker.MagicMock()
    runner.run_feature.side_effect = [State.FAILED, State.FAILED]

    first_feature = mocker.MagicMock(name="First Feature", state=State.FAILED)
    second_feature = mocker.MagicMock(name="Second Feature",
                                      state=State.FAILED)

    # when
    status = runner.start([first_feature, second_feature])

    # given
    assert status
Exemplo n.º 11
0
def cli(**kwargs):
    """radish - The root from red to green. BDD tooling for Python.

    Use radish to run your Feature File.

    Provide the Feature Files to run in FEATURE_FILES.
    """
    config = Config(kwargs)
    world.config = config

    # turn of ANSI colors if requested
    if config.no_ansi:
        cf.disable()

    logger.debug(
        "Loaded %d built-in extension modules: %s",
        len(loaded_built_in_extensions),
        ", ".join(str(e) for e in loaded_built_in_extensions),
    )
    logger.debug("Feature Files: %s",
                 ", ".join(str(p) for p in config.feature_files))
    logger.debug("Basedirs: %s", ", ".join(str(d) for d in config.basedirs))

    logger.debug("Loading extensions")
    loaded_extensions = extension_registry.load_extensions(config)
    logger.debug(
        "Loaded %d extensions: %s",
        len(loaded_extensions),
        ", ".join(type(e).__name__ for e in loaded_extensions),
    )

    parser = FeatureFileParser()

    features = []
    for feature_file in config.feature_files:
        logger.debug("Parsing Feature File %s", feature_file)
        try:
            feature_ast = parser.parse(feature_file)
            if feature_ast:
                features.append(feature_ast)
        except RadishError as exc:
            print("", flush=True)
            print(
                "An error occured while parsing the Feature File {}:".format(
                    feature_file),
                flush=True,
            )
            print(exc, flush=True)
            sys.exit(1)

    logger.debug("Loading all modules from the basedirs")
    loaded_modules = loader.load_modules(config.basedirs)
    logger.debug(
        "Loaded %d modules from the basedirs: %s",
        len(loaded_modules),
        ", ".join(str(m) for m in loaded_modules),
    )

    exit_status = 0
    try:
        runner = Runner(config,
                        step_registry=step_registry,
                        hook_registry=hook_registry)
        logger.debug(
            "Starting Runner WIP mode: %r, Dry-Run mode: %r",
            config.wip_mode,
            config.dry_run_mode,
        )
        success = runner.start(features)
        logger.debug("Finished Runner with status %s", success)

        exit_status = 0 if success else 1
    except RadishError as exc:
        print("", flush=True)
        print("An error occured while running the Feature Files:", flush=True)
        print(exc, flush=True)
        exit_status = 1

    sys.exit(exit_status)