コード例 #1
0
ファイル: matcher.py プロジェクト: nokia/radish
def assert_step_not_match(
    step: Step, expected_step_func: str, step_registry: StepRegistry
):
    """Assert that the Step doesn't match a Step Implementation from the Registry"""
    print(
        "{} STEP '{}' SHOULD NOT MATCH {}".format(
            cf.orange(">>"),
            cf.deepSkyBlue3("{} {}".format(step.keyword, step.text)),
            cf.deepSkyBlue3(expected_step_func if expected_step_func else "ANY"),
        ),
        end="    ",
        flush=True,
    )

    # match the step text from the config with one from the registry
    try:
        matcher.match_step(step, step_registry)
    except StepImplementationNotFoundError:
        print(cf.bold_forestGreen("✔"))
        return True

    matched_step_func = step.step_impl.func
    if matched_step_func.__name__ == expected_step_func:
        print_failure(
            matched_step_func,
            [
                "Expected Step Text matched {} but it shouldn't".format(
                    expected_step_func
                )
            ],
        )
        return False

    print(cf.bold_forestGreen("✔"))
    return True
コード例 #2
0
ファイル: gherkin.py プロジェクト: nokia/radish
def write_step(step, step_color_func, indentation=None):
    """Write a Step with the given color function"""
    if indentation is None:
        indentation_level = 2 if isinstance(step.rule, DefaultRule) else 3
        indentation = INDENT_STEP * indentation_level

    step_text = "{step_keyword} {text}".format(step_keyword=step_color_func(
        step.used_keyword),
                                               text=step_color_func(step.text))

    print(indentation + step_text, flush=True)

    if step.doc_string is not None:
        doc_string_indentation = indentation + INDENT_STEP
        print(doc_string_indentation + cf.white('"""'), flush=True)
        print(
            cf.deepSkyBlue3(
                textwrap.indent(step.doc_string, doc_string_indentation)),
            end="",
            flush=True,
        )
        print(cf.white(doc_string_indentation + '"""'), flush=True)

    if step.data_table is not None:
        data_table_indentation = indentation + INDENT_STEP
        pretty_table = pretty_print_table(step.data_table, cf.white,
                                          cf.deepSkyBlue3)
        print(textwrap.indent(pretty_table, data_table_indentation),
              flush=True)
コード例 #3
0
ファイル: gherkin.py プロジェクト: nokia/radish
def write_tagline(tag, indentation=""):
    tagline = cf.deepSkyBlue3("@{name}".format(name=tag.name))
    print(indentation + tagline, flush=True)
コード例 #4
0
ファイル: gherkin.py プロジェクト: nokia/radish
def write_summary(features):
    """Write the end report after all Feature Files are ran"""
    feature_states = [f.state for f in features]
    features_line = "{} Feature{} ({})".format(
        len(feature_states),
        "s" if len(feature_states) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(feature_states).items()),
    )

    scenarios = []
    rules_scenarios = (rule.scenarios for feature in features
                       for rule in feature.rules)
    for scenario in itertools.chain(*rules_scenarios):
        if hasattr(scenario, "examples"):
            scenarios.extend(scenario.examples)
        else:
            scenarios.append(scenario)

    scenarios_line = "{} Scenario{} ({})".format(
        len(scenarios),
        "s" if len(scenarios) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(s.state for s in scenarios).items()),
    )

    steps = [s for s in scenarios for s in s.steps]
    steps_line = "{} Step{} ({})".format(
        len(steps),
        "s" if len(steps) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(s.state for s in steps).items()),
    )

    print(features_line, flush=True)
    print(scenarios_line, flush=True)
    print(steps_line, flush=True)

    # remind about pending Steps
    pending_steps = [s for s in steps if s.state is State.PENDING]
    if pending_steps:
        pending_step_implementations = {s.step_impl for s in pending_steps}
        print(
            cf.orange(
                "You have {} pending Step Implementation{} affecting {} Step{}:"
                .format(
                    cf.bold_orange(len(pending_step_implementations)),
                    "s" if len(pending_step_implementations) != 1 else "",
                    cf.bold_orange(len(pending_steps)),
                    "s" if len(pending_steps) != 1 else "",
                )))
        for pending_step_implementation in pending_step_implementations:
            print(
                cf.orange("*  '{} {}' @ {}:{}".format(
                    cf.bold_orange(pending_step_implementation.keyword),
                    cf.bold_orange(pending_step_implementation.pattern),
                    cf.bold_orange(
                        pending_step_implementation.func.__code__.co_filename),
                    cf.bold_orange(pending_step_implementation.func.__code__.
                                   co_firstlineno),
                )))
        print(
            cf.orange(
                "Note: This may be the reason for potentially failed Steps!"))

    total_duration = sum((f.duration() for f in features), timedelta())
    timing_information = cf.deepSkyBlue3(
        "Run {marker} finished within {duration} seconds".format(
            marker=cf.bold_deepSkyBlue3(world.config.marker),
            duration=cf.bold_deepSkyBlue3(total_duration.total_seconds()),
        ))

    print(timing_information, flush=True)
コード例 #5
0
ファイル: matcher.py プロジェクト: nokia/radish
def assert_step_match(
    step: Step,
    expected_step_func: str,
    expected_step_arguments: List[Dict[str, Any]],
    step_registry: StepRegistry,
):
    """Assert that the Step correctly matches in the Registry"""
    print(
        "{} STEP '{}' SHOULD MATCH {}".format(
            cf.orange(">>"),
            cf.deepSkyBlue3("{} {}".format(step.keyword, step.text)),
            cf.deepSkyBlue3(expected_step_func),
        ),
        end="    ",
        flush=True,
    )

    # match the step text from the config with one from the registry
    try:
        matcher.match_step(step, step_registry)
    except StepImplementationNotFoundError:
        print_failure(None, ["Expected Step Text didn't match any Step Implementation"])
        return False

    # check if Step matches the correct Step Implementation Function
    matched_step_func = step.step_impl.func
    if matched_step_func.__name__ != expected_step_func:
        print_failure(
            matched_step_func,
            [
                "Expected Step Text matched {} instead of {}".format(
                    matched_step_func.__name__, expected_step_func
                )
            ],
        )
        return False

    # check if the Step has a match with the correct arguments
    if expected_step_arguments:
        # merge the Step's keyword and positional arguments into one dict
        args, kwargs = step.step_impl_match.evaluate()
        actual_step_arguments = utils.get_func_pos_args_as_kwargs(
            matched_step_func, args
        )
        actual_step_arguments.update(kwargs)

        # turn the list of single-item-dicts to a multi-item dict
        # -> [{1: 2}, {3: 4}] --> {1: 2, 3: 4}
        # NOTE(TF) for Python 3.5 test reproducibility we need an OrderedDict -.^
        expected_step_arguments = OrderedDict(
            (
                argpair
                for argpairs in expected_step_arguments
                for argpair in argpairs.items()
            )
        )
        errors = assert_step_arguments(actual_step_arguments, expected_step_arguments)

        if errors:
            print_failure(matched_step_func, errors)
            return False

    print(cf.bold_forestGreen("✔"))
    return True