Exemplo n.º 1
0
 def _add_step_entry(self, entry, event):
     report_node_data = self.report.get(event.location)
     if not report_node_data:
         raise ProgrammingError("Cannot find location %s in the report" % event.location)
     step = self._lookup_step(report_node_data.steps, event.step)
     if step.end_time:
         raise ProgrammingError("Cannot update step '%s', it is already ended" % step.description)
     step.entries.append(entry)
Exemplo n.º 2
0
 def wrapper(klass):
     if not inspect.isclass(klass):
         raise ProgrammingError(
             "%s is not a class (suite decorator can only be used on a class)"
             % klass)
     md = get_metadata(klass)
     if md.dependencies:
         raise ProgrammingError(
             "'depends_on' can not be used on a suite class")
     md.is_suite = True
     md.rank = rank if rank is not None else get_metadata_next_rank()
     md.name = name or klass.__name__
     md.description = description
     return klass
Exemplo n.º 3
0
def _unserialize_step_data(xml):
    step = Step(xml.attrib["description"])
    step.start_time = _unserialize_datetime(xml.attrib["start-time"])
    step.end_time = _unserialize_datetime(
        xml.attrib["end-time"]) if "end-time" in xml.attrib else None
    for xml_entry in xml:
        if xml_entry.tag == "log":
            entry = Log(xml_entry.attrib["level"], xml_entry.text,
                        _unserialize_datetime(xml_entry.attrib["time"]))
        elif xml_entry.tag == "attachment":
            entry = Attachment(xml_entry.attrib["description"], xml_entry.text,
                               _unserialize_bool(xml_entry.attrib["as-image"]),
                               _unserialize_datetime(xml_entry.attrib["time"]))
        elif xml_entry.tag == "url":
            entry = Url(xml_entry.attrib["description"], xml_entry.text,
                        _unserialize_datetime(xml_entry.attrib["time"]))
        elif xml_entry.tag == "check":
            entry = Check(xml_entry.attrib["description"],
                          _unserialize_outcome(xml_entry.attrib["outcome"]),
                          xml_entry.text,
                          _unserialize_datetime(xml_entry.attrib["time"]))
        else:
            raise ProgrammingError("Unknown tag '%s' for step" % xml_entry.tag)
        step.entries.append(entry)
    return step
Exemplo n.º 4
0
def _unserialize_bool(value):
    if value == "true":
        return True
    elif value == "false":
        return False
    else:
        raise ProgrammingError("Invalid boolean representation: '%s'" % value)
Exemplo n.º 5
0
 def wrapper(obj):
     md = get_metadata(obj)
     if md.is_suite:
         raise ProgrammingError(
             "'depends_on' can not be used on a suite class")
     md.dependencies.extend(deps)
     return obj
Exemplo n.º 6
0
 def _get_rule_application(self, on_test, on_suite):
     if on_test is None and on_suite is None:
         return True, False
     if not on_test and not on_suite:
         raise ProgrammingError(
             "either on_test or on_suite need to be True")
     return bool(on_test), bool(on_suite)
Exemplo n.º 7
0
    def wrapper(func):
        if scope not in SCOPE_LEVELS.keys():
            raise ProgrammingError(
                "Invalid fixture scope '%s' in fixture function '%s'" %
                (scope, func.__name__))

        setattr(func, "_lccfixtureinfo", FixtureInfo(names, scope))
        return func
Exemplo n.º 8
0
 def _lookup_step(steps, step):
     if step is None:
         return steps[-1]
     else:
         try:
             return next(s for s in reversed(steps) if s.description == step)
         except StopIteration:
             raise ProgrammingError("Cannot find step '%s'" % step)
Exemplo n.º 9
0
def _unserialize_outcome(value):
    if value == OUTCOME_SUCCESS:
        return True
    elif value == OUTCOME_FAILURE:
        return False
    elif value == OUTCOME_NOT_AVAILABLE:
        return None
    else:
        raise ProgrammingError("Unknown value '%s' for outcome" % value)
Exemplo n.º 10
0
def get_fixture(name):
    """
    Return the corresponding fixture value. Only fixtures whose scope is session_prerun can be retrieved.
    """
    global _scheduled_fixtures

    if not _scheduled_fixtures:
        raise ProgrammingError("Fixture cache has not yet been initialized")

    if not _scheduled_fixtures.has_fixture(name):
        raise ProgrammingError(
            "Fixture '%s' either does not exist or don't have a prerun_session scope"
            % name)

    try:
        return _scheduled_fixtures.get_fixture_result(name)
    except AssertionError as excp:
        raise ProgrammingError(str(excp))
Exemplo n.º 11
0
 def get_fixture_result(self, name):
     if name in self._fixtures:
         assert name in self._results, "Cannot get fixture '%s' result, it has not been previously executed" % name
         return self._results[name].get()
     elif self._parent_scheduled_fixtures:
         return self._parent_scheduled_fixtures.get_fixture_result(name)
     else:
         raise ProgrammingError(
             "Cannot find fixture named '%s' in scheduled fixtures" % name)
Exemplo n.º 12
0
def _get_actual_for_dict_operation(in_):
    if in_ is not None:
        return in_
    else:
        context = ThisDict.get_current_context()
        if not context:
            raise ProgrammingError(
                "Actual dict must be set either using in_ argument or using 'with this_dict(...)' statement"
            )
        return context.actual
Exemplo n.º 13
0
def get_callable_args(cb):
    if not inspect.isroutine(cb):
        try:
            cb = getattr(cb, "__call__")
        except AttributeError:
            raise ProgrammingError("%s is not something that can be called" %
                                   cb)

    spec = inspect.getfullargspec(cb) if six.PY3 else inspect.getargspec(cb)
    args_start = 1 if inspect.ismethod(cb) else 0
    return spec.args[args_start:]
Exemplo n.º 14
0
 def wrapper(func):
     if not inspect.isfunction(func):
         raise ProgrammingError(
             "%s is not a function (test decorator can only be used on a function)"
             % func)
     md = get_metadata(func)
     md.is_test = True
     md.rank = get_metadata_next_rank()
     md.name = name or func.__name__
     md.description = description
     return func
Exemplo n.º 15
0
def load_suite_from_class(class_):
    try:
        md = class_._lccmetadata
    except AttributeError:
        raise InvalidSuiteError()

    try:
        suite_obj = class_()
    except UserError as e:
        raise e  # propagate UserError
    except Exception:
        raise ProgrammingError("Got an unexpected error while instantiating suite class '%s':%s" % (
            class_.__name__, serialize_current_exception()
        ))
    ensure_node_is_visible(suite_obj, md)

    suite = Suite(suite_obj, md.name, md.description)
    suite.tags.extend(md.tags)
    suite.properties.update(md.properties)
    suite.links.extend(md.links)
    suite.rank = md.rank
    suite.disabled = md.disabled

    for hook_name in SUITE_HOOKS:
        if hasattr(suite_obj, hook_name):
            suite.add_hook(hook_name, getattr(suite_obj, hook_name))

    for test in load_tests_from_methods(get_test_methods_from_class(suite_obj)):
        suite.add_test(test)

    for test in get_generated_tests(suite_obj):
        suite.add_test(test)

    for sub_suite in load_suites_from_classes(get_sub_suites_from_class(suite_obj)):
        suite.add_suite(sub_suite)

    return suite
Exemplo n.º 16
0
 def save(self):
     if not self.is_bound():
         raise ProgrammingError("Cannot save unbound report")
     save_report(self.path, self, self.backend)
Exemplo n.º 17
0
def save_report(filename, report, backend):
    if not backend.get_capabilities() & CAPABILITY_SAVE_REPORT:
        raise ProgrammingError(
            "Reporting backend '%s' does not support save operation" %
            backend.name)
    backend.save_report(filename, report)
Exemplo n.º 18
0
def run_project(project, cli_args):
    nb_threads = get_nb_threads(cli_args)
    if nb_threads > 1 and not project.is_threaded():
        raise LemonCheesecakeException("Project does not support multi-threading")

    suites = get_suites_from_project(project, cli_args)

    # Build fixture registry
    fixture_registry = build_fixture_registry(project, cli_args)
    fixture_registry.check_fixtures_in_suites(suites)

    # Set active reporting backends
    available_reporting_backends = {
        backend.name: backend for backend in
        filter_reporting_backends_by_capabilities(
            project.get_all_reporting_backends(), CAPABILITY_REPORTING_SESSION
        )
    }
    active_reporting_backends = set()
    for backend_name in cli_args.reporting + cli_args.enable_reporting:
        try:
            active_reporting_backends.add(available_reporting_backends[backend_name])
        except KeyError:
            raise LemonCheesecakeException("Unknown reporting backend '%s'" % backend_name)
    for backend_name in cli_args.disable_reporting:
        try:
            active_reporting_backends.discard(available_reporting_backends[backend_name])
        except KeyError:
            raise LemonCheesecakeException("Unknown reporting backend '%s'" % backend_name)

    # Get report save mode
    report_saving_strategy = get_report_saving_strategy(cli_args)

    # Create report dir
    if cli_args.report_dir:
        report_dir = cli_args.report_dir
        try:
            os.mkdir(report_dir)
        except Exception as e:
            return LemonCheesecakeException("Cannot create report directory: %s" % e)
    else:
        try:
            report_dir = project.create_report_dir()
        except UserError as e:
            raise e
        except Exception:
            raise LemonCheesecakeException(
                "Got an unexpected exception while creating report directory:%s" % \
                serialize_current_exception(show_stacktrace=True)
            )

    # Handle before run hook
    try:
        project.run_pre_session_hook(cli_args, report_dir)
    except UserError as e:
        raise e
    except Exception:
        raise ProgrammingError(
            "Got an unexpected exception while running the pre-session hook:%s" % \
            serialize_current_exception(show_stacktrace=True)
        )

    # Initialize event manager
    event_manager = initialize_event_manager(
        suites, active_reporting_backends, report_dir, report_saving_strategy, nb_threads
    )
    event_manager.add_listener(project)

    # Run tests
    is_successful = run_suites(
        suites, fixture_registry, event_manager,
        force_disabled=cli_args.force_disabled, stop_on_failure=cli_args.stop_on_failure,
        nb_threads=nb_threads
    )

    # Handle after run hook
    try:
        project.run_post_session_hook(cli_args, report_dir)
    except UserError as e:
        raise e
    except Exception:
        raise ProgrammingError(
            "Got an unexpected exception while running the post-session hook:%s" % \
            serialize_current_exception(show_stacktrace=True)
        )

    if cli_args.exit_error_on_failure:
        return 0 if is_successful else 1
    else:
        return 0