def test_excludes_named_methods_only(self): _install_traceable_methods(SampleClass, "public", exclude=True) for traced_method_name in ["class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue( hasattr(descriptor.__func__, "__autologging_traced__"), traced_method_name) for traced_method_name in [ "__init__", "_nonpublic", "_SampleClass__internal" ]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue(hasattr(descriptor, "__autologging_traced__"), traced_method_name) # explicitly excluded self.assertFalse( hasattr(SampleClass.__dict__["public"], "__autologging_traced__"), "public") # excluded by default self.assertFalse( hasattr(SampleClass.__dict__["__special__"], "__autologging_traced__"), "__special__")
def test_excludes_named_methods_only(self): _install_traceable_methods(SampleClass, "public", exclude=True) for traced_method_name in [ "class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue( hasattr(descriptor.__func__, "__autologging_traced__"), traced_method_name) for traced_method_name in [ "__init__", "_nonpublic", "_SampleClass__internal"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue( hasattr(descriptor, "__autologging_traced__"), traced_method_name) # explicitly excluded self.assertFalse( hasattr( SampleClass.__dict__["public"], "__autologging_traced__"), "public") # excluded by default self.assertFalse( hasattr( SampleClass.__dict__["__special__"], "__autologging_traced__"), "__special__")
def test_traces_named_methods_only(self): _install_traceable_methods(SampleClass, "public", "__special__") for nontraced_method_name in [ "class_method", "static_method"]: descriptor = SampleClass.__dict__[nontraced_method_name] self.assertFalse( hasattr(descriptor.__func__, "__autologging_traced__"), nontraced_method_name) for nontraced_method_name in [ "__init__", "_nonpublic", "_SampleClass__internal"]: descriptor = SampleClass.__dict__[nontraced_method_name] self.assertFalse( hasattr(descriptor, "__autologging_traced__"), nontraced_method_name) for traced_method_name in [ "public", "__special__"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue( hasattr(descriptor, "__autologging_traced__"), traced_method_name)
def test_traces_with_named_logger(self): _install_traceable_methods(SampleClass, logger=named_logger) for traced_method_name in ["class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual(named_logger.name, descriptor.__func__._tracing_proxy.logger.name) for traced_method_name in [ "__init__", "public", "_nonpublic", "_SampleClass__internal" ]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual(named_logger.name, descriptor._tracing_proxy.logger.name)
def test_traces_with_default_logger(self): _install_traceable_methods(SampleClass) for traced_method_name in ["class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual("%s.SampleClass" % __name__, descriptor.__func__._trace_log_delegator.name) for traced_method_name in [ "__init__", "public", "_nonpublic", "_SampleClass__internal" ]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual("%s.SampleClass" % __name__, descriptor._trace_log_delegator.name)
def test_traces_default_methods_if_none_are_named(self): _install_traceable_methods(SampleClass) for traced_method_name in ["class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue( hasattr(descriptor.__func__, "__autologging_traced__"), traced_method_name) for traced_method_name in [ "__init__", "public", "_nonpublic", "_SampleClass__internal" ]: descriptor = SampleClass.__dict__[traced_method_name] self.assertTrue(hasattr(descriptor, "__autologging_traced__"), traced_method_name) self.assertFalse( hasattr(SampleClass.__dict__["__special__"], "__autologging_traced__"), "__special__")
def test_traces_with_named_logger(self): _install_traceable_methods(SampleClass, logger=named_logger) for traced_method_name in [ "class_method", "static_method"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual( named_logger.name, descriptor.__func__._tracing_proxy.logger.name) for traced_method_name in [ "__init__", "public", "_nonpublic", "_SampleClass__internal"]: descriptor = SampleClass.__dict__[traced_method_name] self.assertEqual( named_logger.name, descriptor._tracing_proxy.logger.name)
def test_does_not_replace_class(self): class_ = _install_traceable_methods(SampleClass) self.assertTrue(class_ is SampleClass)
def test_does_not_replace_class(self): class_ = _install_traceable_methods(SampleClass) self.assertTrue(class_ is SampleClass)