def test_weave_object_instance(self):
     """tests Weaver.weave_object() for an instance"""
     weaver.weave_object(self.instance, ContractAspect)
     self.assertRaises(ContractFailedError, self.instance.foo, 15)
     another_instance = Test()
     # In another instance : contracts are not activated, this should pass !
     self.assertRaises(ValueError, another_instance.foo, 15)
 def test_weave_object_instance(self):
     """tests Weaver.weave_object() for an instance"""
     weaver.weave_object(self.instance, ContractAspect)
     self.assertRaises(ContractFailedError, self.instance.foo, 15)
     another_instance = Test()
     # In another instance : contracts are not activated, this should pass !
     self.assertRaises(ValueError, another_instance.foo, 15)
 def test_get_aspect(self):
     """tests weaver.get_aspect()"""
     aspect = weaver.get_aspect(ProfilerAspect)
     self.assertEquals(aspect, None)
     weaver.weave_object(self.klass, ProfilerAspect)
     aspect = weaver.get_aspect(ProfilerAspect)
     self.assertEquals(isinstance(aspect, ProfilerAspect), True)
 def test_get_aspect(self):
     """tests weaver.get_aspect()"""
     aspect = weaver.get_aspect(ProfilerAspect)
     self.assertEquals(aspect, None)
     weaver.weave_object(self.klass, ProfilerAspect)
     aspect = weaver.get_aspect(ProfilerAspect)
     self.assertEquals(isinstance(aspect, ProfilerAspect), True)
 def test_dump_readable_profiles(self):
     """tests that dump_readable_profiles() doesn't raise an exception"""
     weaver.weave_object(Test, ProfilerAspect)
     self.instance.bar()
     aspect = weaver.get_aspect(ProfilerAspect)
     stream = StringIO()
     aspect.dump_readable_profiles(stream)
 def test_dump_readable_profiles(self):
     """tests that dump_readable_profiles() doesn't raise an exception"""
     weaver.weave_object(Test, ProfilerAspect)
     self.instance.bar()
     aspect = weaver.get_aspect(ProfilerAspect)
     stream = StringIO()
     aspect.dump_readable_profiles(stream)
 def test_get_weaved_methods(self):
     """test weaved methods list"""
     self.assertRaises(ClassNotWeaved, weaver.get_weaved_methods,
                       self.klass)
     weaver.weave_object(self.klass, ProfilerAspect)
     method_names = Set(['foo', 'bar'])
     self.assertEquals(Set(weaver.get_weaved_methods(self.klass)),
                       method_names)
 def test_get_weaved_methods(self):
     """test weaved methods list"""
     self.assertRaises(ClassNotWeaved, weaver.get_weaved_methods,
                       self.klass)
     weaver.weave_object(self.klass, ProfilerAspect)
     method_names = Set(['foo', 'bar'])
     self.assertEquals(Set(weaver.get_weaved_methods(self.klass)),
                       method_names)
 def test_get_weaved_classes(self):
     """tests get_weaved_classes()"""
     class SomeClass:
         """some class to weave"""
         def some_method(self):
             """a method"""
     weaver.weave_object(self.klass, ContractAspect)
     weaver.weave_object(SomeClass, ContractAspect)
     classnames = [klass.__name__ for klass in weaver.get_weaved_classes()]
     classnames.sort()
     self.assertEquals(classnames, ['SomeClass', 'Test'])
 def test_register_aspect(self):
     """tests() aspect registration"""
     old_foo = self.instance.foo
     weaver.weave_object(self.klass, ContractAspect)
     # instances of self.klass must have been aspected !
     self.assertNotEquals(old_foo, self.instance.foo)
     contract = weaver.get_aspect(ContractAspect)
     old_foo = self.instance.foo
     # Trying to reaspect self.instance should not change its methods
     weaver._weave_method(self.klass, 'foo', contract)
     self.assertEquals(old_foo, self.instance.foo)
 def test_already_aspected(self):
     """tests weaver.obj_class_is_aspected()"""
     self.assertEquals(
         weaver.obj_class_is_aspected(self.instance, ContractAspect), False)
     weaver.weave_object(self.klass, ContractAspect)
     # obj_class_is_aspected() always returns False on classes
     self.assertEquals(
         weaver.obj_class_is_aspected(self.klass, ContractAspect), False)
     # but make sure it returns True on the aspected instance
     self.assertEquals(
         weaver.obj_class_is_aspected(self.instance, ContractAspect), True)
Beispiel #12
0
 def test_register_aspect(self):
     """tests() aspect registration"""
     old_foo = self.instance.foo
     weaver.weave_object(self.klass, ContractAspect)
     # instances of self.klass must have been aspected !
     self.assertNotEquals(old_foo, self.instance.foo)
     contract = weaver.get_aspect(ContractAspect)
     old_foo = self.instance.foo
     # Trying to reaspect self.instance should not change its methods
     weaver._weave_method(self.klass, 'foo', contract)
     self.assertEquals(old_foo, self.instance.foo)
 def test_who_is_called(self):
     """test which wrapper function is choosed"""
     weaver.weave_object(Extended, LoggerAspect, self.log_device)
     weaver.weave_object(Base, LoggerAspect, self.log_device)
     self.ext.some_method()
     self.assertEquals(self.ext.trace, ['Extended', 'Base'])
     self.ext.trace = []
     Base.some_method(self.ext)
     self.assertEquals(self.ext.trace, ['Base'])
     self.ext.trace = []
     Extended.some_method(self.ext)
     self.assertEquals(self.ext.trace, ['Extended', 'Base'])
    def test_get_weaved_classes(self):
        """tests get_weaved_classes()"""
        class SomeClass:
            """some class to weave"""
            def some_method(self):
                """a method"""

        weaver.weave_object(self.klass, ContractAspect)
        weaver.weave_object(SomeClass, ContractAspect)
        classnames = [klass.__name__ for klass in weaver.get_weaved_classes()]
        classnames.sort()
        self.assertEquals(classnames, ['SomeClass', 'Test'])
Beispiel #15
0
 def test_get_aspects(self):
     """tests weaver.get_aspects()"""
     class SomeClass:
         """a simple class"""
         def foo(self):
             """a simple method"""
     self.assertRaises(ClassNotWeaved, weaver.get_aspects, SomeClass, 'foo')
     weaver.weave_object(SomeClass, ProfilerAspect)
     weaver.weave_object(SomeClass, ContractAspect)
     aspects = weaver.get_aspects(SomeClass, 'foo')
     classes = [aspect.__class__ for aspect in aspects]
     self.assertEquals(classes, [ProfilerAspect, ContractAspect])
Beispiel #16
0
 def test_who_is_called(self):
     """test which wrapper function is choosed"""
     weaver.weave_object(Extended, LoggerAspect, self.log_device)
     weaver.weave_object(Base, LoggerAspect, self.log_device)
     self.ext.some_method()
     self.assertEquals(self.ext.trace, ['Extended', 'Base'])
     self.ext.trace = []
     Base.some_method(self.ext)
     self.assertEquals(self.ext.trace, ['Base'])
     self.ext.trace = []
     Extended.some_method(self.ext)
     self.assertEquals(self.ext.trace, ['Extended', 'Base'])
    def test_get_aspects(self):
        """tests weaver.get_aspects()"""
        class SomeClass:
            """a simple class"""
            def foo(self):
                """a simple method"""

        self.assertRaises(ClassNotWeaved, weaver.get_aspects, SomeClass, 'foo')
        weaver.weave_object(SomeClass, ProfilerAspect)
        weaver.weave_object(SomeClass, ContractAspect)
        aspects = weaver.get_aspects(SomeClass, 'foo')
        classes = [aspect.__class__ for aspect in aspects]
        self.assertEquals(classes, [ProfilerAspect, ContractAspect])
Beispiel #18
0
 def test_already_aspected(self):
     """tests weaver.obj_class_is_aspected()"""
     self.assertEquals(weaver.obj_class_is_aspected(self.instance,
                                                    ContractAspect),
                       False)
     weaver.weave_object(self.klass, ContractAspect)
     # obj_class_is_aspected() always returns False on classes
     self.assertEquals(weaver.obj_class_is_aspected(self.klass,
                                                    ContractAspect),
                       False)
     # but make sure it returns True on the aspected instance
     self.assertEquals(weaver.obj_class_is_aspected(self.instance,
                                                    ContractAspect),
                       True)
Beispiel #19
0
 def test_weave_same_aspect(self):
     """Checks that weaver forbids weaving multiple time the same
     aspect on a method.
     """
     weaver.weave_object(self.klass, ContractAspect)
     old_aspects = weaver.get_aspects(self.klass, 'foo')
     # Trying to weave a second time
     weaver.weave_object(self.klass, ContractAspect)
     new_aspects = weaver.get_aspects(self.klass, 'foo')
     self.assert_(old_aspects == new_aspects)
     # Now trying to weave on self.instance should produce warnings
     old_foo = self.instance.foo
     weaver.weave_methods(self.instance, ContractAspect)
     # self.instance.foo should not have been modified !
     self.assertEquals(old_foo, self.instance.foo)
 def test_weave_same_aspect(self):
     """Checks that weaver forbids weaving multiple time the same
     aspect on a method.
     """
     weaver.weave_object(self.klass, ContractAspect)
     old_aspects = weaver.get_aspects(self.klass, 'foo')
     # Trying to weave a second time
     weaver.weave_object(self.klass, ContractAspect)
     new_aspects = weaver.get_aspects(self.klass, 'foo')
     self.assert_(old_aspects == new_aspects)
     # Now trying to weave on self.instance should produce warnings
     old_foo = self.instance.foo
     weaver.weave_methods(self.instance, ContractAspect)
     # self.instance.foo should not have been modified !
     self.assertEquals(old_foo, self.instance.foo)
Beispiel #21
0
 def test_weaving_impact(self):
     """make sure weaving base class doesn't impact extended class"""
     ext_orig = self.ext
     ext_orig = Extended.some_method
     base_orig = Base.some_method
     weaver.weave_object(Extended, LoggerAspect, self.log_device)
     ext_mid = Extended.some_method
     base_mid = Base.some_method
     # Weaving on extended class should not affect Base class
     self.assertNotEquals(ext_orig, ext_mid)
     self.assertEquals(base_orig, base_mid)
     weaver.weave_object(Base, LoggerAspect, self.log_device)
     ext_final = Extended.some_method
     base_final = Base.some_method
     # Weaving on Base class should not affect already weaved Extended class
     self.assertEquals(ext_mid, ext_final)
     self.assertNotEquals(base_mid, base_final)
 def test_weaving_impact(self):
     """make sure weaving base class doesn't impact extended class"""
     ext_orig = self.ext
     ext_orig = Extended.some_method
     base_orig = Base.some_method
     weaver.weave_object(Extended, LoggerAspect, self.log_device)
     ext_mid = Extended.some_method
     base_mid = Base.some_method
     # Weaving on extended class should not affect Base class
     self.assertNotEquals(ext_orig, ext_mid)
     self.assertEquals(base_orig, base_mid)
     weaver.weave_object(Base, LoggerAspect, self.log_device)
     ext_final = Extended.some_method
     base_final = Base.some_method
     # Weaving on Base class should not affect already weaved Extended class
     self.assertEquals(ext_mid, ext_final)
     self.assertNotEquals(base_mid, base_final)
Beispiel #23
0
 def test_aspect_is_abstract(self):
     """ensures that using ConfirmationAbstractAspect raises an exception"""
     jumper = BaseJumper()
     weaver.weave_object(jumper, ConfirmationAbstractAspect)
     self.assertRaises(NotImplementedError, jumper.jump)
 def test_get_weaved_instances(self):
     """tests weaved instances"""
     weaver.weave_object(self.instance, ContractAspect)
     instances = weaver.get_weaved_instances()
     self.assertEquals(instances, [self.instance])
 def test_weave_object_class(self):
     """tests Weaver.weave_object() for a class"""
     weaver.weave_object(self.klass, ContractAspect)
     self.assertRaises(ContractFailedError, self.instance.foo, 15)
     another_instance = Test()
     self.assertRaises(ContractFailedError, another_instance.foo, 15)
Beispiel #26
0
 def test_get_weaved_instances(self):
     """tests weaved instances"""
     weaver.weave_object(self.instance, ContractAspect)
     instances = weaver.get_weaved_instances()
     self.assertEquals(instances, [self.instance])
 def test_aspect_is_abstract(self):
     """ensures that using ConfirmationAbstractAspect raises an exception"""
     jumper = BaseJumper()
     weaver.weave_object(jumper, ConfirmationAbstractAspect)
     self.assertRaises(NotImplementedError, jumper.jump)
Beispiel #28
0
 def test_weave_object_class(self):
     """tests Weaver.weave_object() for a class"""
     weaver.weave_object(self.klass, ContractAspect)
     self.assertRaises(ContractFailedError, self.instance.foo, 15)
     another_instance = Test()
     self.assertRaises(ContractFailedError, another_instance.foo, 15)
 def test_weave_object_module(self):
     """tests Weaver.weave_module() for an instance"""
     weaver.weave_object(self.mod, ContractAspect)
     stack = self.mod.StackImpl(3)
     self.assertRaises(ContractFailedError, stack.pop)
Beispiel #30
0
def enable_dbc_on(obj):
    weaver.weave_object(obj, ContractAspect)
Beispiel #31
0
 def test_weave_object_module(self):
     """tests Weaver.weave_module() for an instance"""
     weaver.weave_object(self.mod, ContractAspect)
     stack = self.mod.StackImpl(3)
     self.assertRaises(ContractFailedError, stack.pop)