def test_nested_internal_log_record_in_untraced_method(self):
        LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass()

        self.assertEqual(1, len(list_handler.records))

        init_function = (
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.
                __dict__["__init__"])
        expected_logger_name = "logged.testing.%s" % getattr(
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass,
            "__qualname__",
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.__name__)
        self._assert_log_record(
            list_handler.records[0], init_function, expected_logger_name,
            "LATC.__INC.__i__")
    def test_nested_internal_method_log_and_trace_records(self):
        obj = LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass()
        value = obj.method(None)

        self.assertEqual("LATC.__INC.m None and None", value)
        self.assertEqual(4, len(list_handler.records))

        wrapped_function = (
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.
                __dict__["method"].__wrapped__)
        qualname = getattr(
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass,
            "__qualname__",
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.__name__)
        expected_tracer_name = "traced.testing.%s" % qualname
        expected_logger_name = "logged.testing.%s" % qualname
        self._assert_call_record(
            list_handler.records[1], wrapped_function, expected_tracer_name,
            ((None,), dict()), "LATC.__INC.m")
        self._assert_log_record(
            list_handler.records[2], wrapped_function, expected_logger_name,
            "LATC.__INC.m")
        self._assert_return_record(
            list_handler.records[3], wrapped_function, expected_tracer_name,
            ("LATC.__INC.m None and None",), "LATC.__INC.m")
    def test_nested_nonpublic_method_log_and_trace_records(self):
        LoggedAndTracedClass._NonPublicNestedClass()

        self.assertEqual(3, len(list_handler.records))

        wrapped_function = LoggedAndTracedClass._NonPublicNestedClass.__dict__[
            "__init__"].__wrapped__
        qualname = getattr(
            LoggedAndTracedClass._NonPublicNestedClass, "__qualname__",
            "_NonPublicNestedClass")
        expected_tracer_name = "traced.testing.%s" % qualname
        expected_logger_name = "test.dummy.%s" % qualname
        self._assert_call_record(
            list_handler.records[0], wrapped_function, expected_tracer_name,
            (tuple(), dict()), "LATC._NPNC.__i__")
        self._assert_log_record(
            list_handler.records[1], wrapped_function, expected_logger_name,
            "LATC._NPNC.__i__")
        self._assert_return_record(
            list_handler.records[2], wrapped_function, expected_tracer_name,
            (None,), "LATC._NPNC.__i__")
    def test_nested_internal_method_log_record_when_trace_disabled(self):
        named_tracer.setLevel(logging.DEBUG)
        obj = LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass()
        value = obj.method(None)

        self.assertEqual("LATC.__INC.m None and None", value)
        self.assertEqual(2, len(list_handler.records))

        wrapped_function = (
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.
                __dict__["method"].__wrapped__)
        expected_logger_name = "logged.testing.%s" % getattr(
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass,
            "__qualname__",
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.__name__)
        self._assert_log_record(
            list_handler.records[1], wrapped_function, expected_logger_name,
            "LATC.__INC.m")
Esempio n. 5
0
    def test_nested_internal_method_trace_records_when_log_disabled(self):
        named_logger.setLevel(logging.WARN)
        obj = LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass()
        value = obj.method(None)

        self.assertEqual("LATC.__INC.m None and None", value)
        self.assertEqual(2, len(list_handler.records))

        wrapped_function = (
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.
                __dict__["method"].__wrapped__)
        expected_tracer_name = "traced.testing.%s" % getattr(
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass,
            "__qualname__",
            LoggedAndTracedClass._LoggedAndTracedClass__InternalNestedClass.__name__)
        self._assert_call_record(
            list_handler.records[0], wrapped_function, expected_tracer_name,
            ((None,), dict()), "LATC.__INC.m")
        self._assert_return_record(
            list_handler.records[1], wrapped_function, expected_tracer_name,
            ("LATC.__INC.m None and None",), "LATC.__INC.m")
Esempio n. 6
0
    def test_call_method_log_and_trace_records(self):
        obj = LoggedAndTracedClass.NestedClass()

        list_handler.reset()
        rv = obj("test")

        self.assertEqual("LATC.NC.__call__ test", rv)
        self.assertEqual(3, len(list_handler.records))

        wrapped_function = \
            LoggedAndTracedClass.NestedClass.__dict__["__call__"].__wrapped__
        qualname = getattr(LoggedAndTracedClass.NestedClass, "__qualname__",
                           "NestedClass")
        expected_tracer_name = "test.dummy.%s" % qualname
        expected_logger_name = "logged.testing.%s" % qualname
        self._assert_call_record(list_handler.records[0], wrapped_function,
                                 expected_tracer_name, (("test", ), dict()),
                                 "LATC.NC.__c__")
        self._assert_log_record(list_handler.records[1], wrapped_function,
                                expected_logger_name, "LATC.NC.__c__")
        self._assert_return_record(list_handler.records[2], wrapped_function,
                                   expected_tracer_name,
                                   ("LATC.NC.__call__ test", ),
                                   "LATC.NC.__c__")
Esempio n. 7
0
    def test_instance_method_log_and_trace_records_when_both_disabled(self):
        dummy_module_logger.setLevel(logging.WARN)
        value = LoggedAndTracedClass().method(None)

        self.assertEqual("LATC.m None and None", value)
        self.assertEqual(0, len(list_handler.records))