Пример #1
0
    def _decorate(obj=None, check_steps_end=False):
        # check that decorated function is not statimethod or classmethod
        if not obj:
            raise MolerStatusException(
                "Decorator for 'staticmethod' or 'classmethod' not implemented yet.",
            )

        if hasattr(obj, "__dict__"):
            if obj.__dict__.items():
                for attributeName in dir(obj):
                    if attributeName == "_already_decorated":
                        break

                    attribute = getattr(obj, attributeName)

                    if not attributeName.startswith("_"):
                        if isinstance(attribute, (FunctionType, MethodType)):
                            setattr(
                                obj, attributeName,
                                MolerTest._wrapper(
                                    attribute,
                                    check_steps_end=check_steps_end))
            else:
                obj = MolerTest._wrapper(obj, check_steps_end=check_steps_end)
        else:
            raise MolerStatusException("No '__dict__' in decorated object.")

        return obj
Пример #2
0
    def _check_exceptions_occured(caught_exception=None):
        unraised_exceptions = ConnectionObserver.get_unraised_exceptions(True)
        occured_exceptions = list()
        for unraised_exception in unraised_exceptions:
            occured_exceptions.append(unraised_exception)
            MolerTest.error(
                "Unhandled exception: '{}'".format(unraised_exception))
        if caught_exception:
            occured_exceptions.append(caught_exception)

        was_error_in_last_execution = MolerTest._was_error
        err_msg = ""

        if was_error_in_last_execution:
            err_msg += "There were error messages in Moler execution. Please check Moler logs for details.\n"
        if len(occured_exceptions) > 0:
            err_msg += "There were unhandled exceptions in Moler.\n"
            for exc in occured_exceptions:
                try:
                    import traceback
                    exc_traceback = ' '.join(
                        traceback.format_tb(exc.__traceback__))
                    err_msg += "{}{}".format(exc_traceback, repr(exc))
                except AttributeError:
                    err_msg += repr(exc)
        if err_msg:
            MolerTest.error(err_msg)
            MolerTest._was_error = False
            raise MolerStatusException(err_msg, occured_exceptions)
Пример #3
0
    def _check_exceptions_occured(caught_exception=None):
        err_msg = MolerTest._prepare_err_msg(caught_exception)

        if err_msg:
            MolerTest._error(err_msg)
            MolerTest._was_error = False
            MolerTest._list_of_errors = list()
            raise MolerStatusException(err_msg)
Пример #4
0
    def _final_check(caught_exception=None, check_steps_end=True):
        exceptions = ConnectionObserver.get_unraised_exceptions(True)
        unhandled_exceptions = list()
        for exception in exceptions:
            unhandled_exceptions.append(exception)
            MolerTest.error("Unhandled exception: '{}'".format(exception))
        if caught_exception:
            unhandled_exceptions.append(caught_exception)

        was_error_in_last_execution = MolerTest._was_error
        err_msg = ""

        if check_steps_end and not MolerTest._was_steps_end:
            err_msg += "Method steps_end() was not called.\n"
        if was_error_in_last_execution:
            err_msg += "There were error messages in Moler execution. Please check Moler logs for details.\n"
        if len(unhandled_exceptions) > 0:
            err_msg += "There were unhandled exceptions in Moler.\n"
        if err_msg or len(unhandled_exceptions) > 0:
            MolerTest.error(err_msg)
            MolerTest._was_error = False
            raise MolerStatusException(err_msg, unhandled_exceptions)
Пример #5
0
 def _check_steps_end():
     if not MolerTest._was_steps_end:
         err_msg = "Method 'steps_end()' was not called or parameter 'check_steps_end' was not set properly.\n."
         MolerTest._error(err_msg)
         MolerTest._was_error = False
         raise MolerStatusException(err_msg)
Пример #6
0
 def _check_steps_end():
     if not MolerTest._was_steps_end:
         err_msg = "Method steps_end() was not called.\n"
         MolerTest.error(err_msg)
         MolerTest._was_error = False
         raise MolerStatusException(err_msg)