def test_lazy_load(self):
     # Write class where a method is defined using __getattr__
     lazy = Facade(LazyBones())
     c = lazy.c()
     self.assertEquals(c.__class__, Wrapper)
     self.assertEquals(c.wrapper__unwrap().__class__, TestC)
     self.assertEquals(c.methoda(), 'a')
Пример #2
0
 def test_lazy_load(self):
     # Write class where a method is defined using __getattr__
     lazy = Facade(LazyBones())
     c = lazy.c()
     self.assertEquals( c.__class__, Wrapper )
     self.assertEquals( c.wrapper__unwrap().__class__, TestC )
     self.assertEquals( c.methoda(), 'a' )
Пример #3
0
    def test_model_interface(self):
        a = Facade(TestA())

        a.attribute_a = "a"
        a.attribute_b = "b"
        a.attribute_c = "c"

        self.assertEquals( a.attribute_a, "a")
        self.assertEquals( a.attribute_b, "b")
        self.assertEquals( a.attribute_c, "c")
    def test_model_interface(self):
        a = Facade(TestA())

        a.attribute_a = "a"
        a.attribute_b = "b"
        a.attribute_c = "c"

        self.assertEquals(a.attribute_a, "a")
        self.assertEquals(a.attribute_b, "b")
        self.assertEquals(a.attribute_c, "c")
Пример #5
0
    def test_chaining(self):
        a = TestA()
        b = a.getb()
        c = b.getc()

        self.assertEquals( a.__class__, TestA )
        self.assertEquals( b.__class__, TestB )
        self.assertEquals( c.__class__, TestC )

        a_f = Facade(TestA())
        b_f = a_f.getb()
        c_f = b_f.getc()

        self.assertEquals( a_f.__class__, Facade(a).__class__ )
        self.assertEquals( b_f.__class__, Facade(a).__class__ )
        self.assertEquals( c_f.__class__, Facade(a).__class__ )

        self.assertEquals( 'a', c_f.methoda() )
Пример #6
0
    def test_various_attribute_types(self):
        c = Facade(TestC())

        # 'Primitives'
        self.assertEquals(c.primitive_a, "a")
        self.assertEquals(c.primitive_b, 1)
        self.assertEquals(c.primitive_c, [1])
        self.assertEquals(c.primitive_d, {"a": 1})

        # Instance methods
        self.assertEquals(c.methoda(), "a")
        self.assertEquals(c.methodb(), "b")

        # Lambda functions
        self.assertEquals(c.lambda_function(2), 4)

        # Models
        self.assertEquals(c.some_model.a, 1)
        self.assertEquals(c.some_model.b, 2)

        # Classes
        self.assertEquals(c.test_a_class().wrapper__unwrap().__class__, TestA)
Пример #7
0
    def test_various_attribute_types_after_chaining(self):
        c = Facade(TestA()).getb().getc()

        # 'Primitives'
        self.assertEquals( c.primitive_a, 'a' )
        self.assertEquals( c.primitive_b, 1 )
        self.assertEquals( c.primitive_c, [ 1 ] )
        self.assertEquals( c.primitive_d, { 'a': 1 } )

        # Instance methods
        self.assertEquals( c.methoda(), 'a' )
        self.assertEquals( c.methodb(), 'b' )

        # Lambda functions
        self.assertEquals( c.lambda_function( 2 ), 4 )

        # Models
        self.assertEquals( c.some_model.a, 1 )
        self.assertEquals( c.some_model.b, 2 )

        # Classes
        self.assertEquals( c.test_a_class( ).wrapper__unwrap( ).__class__, TestA )
    def test_facade(self):
        mtc = TestC()
        mtc_f = Facade(mtc)

        self.assertEquals(mtc.methoda(), mtc_f.methoda())
        self.assertEquals(mtc.methodb(), mtc_f.methodb())
        self.assertEquals(mtc_f.methoda(), "a")

        self.assertEquals(mtc_f.increment(), 1)
        self.assertEquals(mtc_f.increment(), 2)
        self.assertEquals(mtc_f.increment(), 3)
        self.assertEquals(mtc_f.increment(), 4)
Пример #9
0
    def test_facade(self):
        mtc = TestC( )
        mtc_f = Facade( mtc )

        self.assertEquals( mtc.methoda( ), mtc_f.methoda( ) )
        self.assertEquals( mtc.methodb( ), mtc_f.methodb( ) )
        self.assertEquals( mtc_f.methoda( ), "a" )

        self.assertEquals( mtc_f.increment( ), 1 )
        self.assertEquals( mtc_f.increment( ), 2 )
        self.assertEquals( mtc_f.increment( ), 3 )
        self.assertEquals( mtc_f.increment( ), 4 )
    def test_chaining(self):
        a = TestA()
        b = a.getb()
        c = b.getc()

        self.assertEquals(a.__class__, TestA)
        self.assertEquals(b.__class__, TestB)
        self.assertEquals(c.__class__, TestC)

        a_f = Facade(TestA())
        b_f = a_f.getb()
        c_f = b_f.getc()

        self.assertEquals(a_f.__class__, Facade(a).__class__)
        self.assertEquals(b_f.__class__, Facade(a).__class__)
        self.assertEquals(c_f.__class__, Facade(a).__class__)

        self.assertEquals('a', c_f.methoda())
    def test_various_attribute_types_after_chaining(self):
        c = Facade(TestA()).getb().getc()

        # 'Primitives'
        self.assertEquals(c.primitive_a, 'a')
        self.assertEquals(c.primitive_b, 1)
        self.assertEquals(c.primitive_c, [1])
        self.assertEquals(c.primitive_d, {'a': 1})

        # Instance methods
        self.assertEquals(c.methoda(), 'a')
        self.assertEquals(c.methodb(), 'b')

        # Lambda functions
        self.assertEquals(c.lambda_function(2), 4)

        # Models
        self.assertEquals(c.some_model.a, 1)
        self.assertEquals(c.some_model.b, 2)

        # Classes
        self.assertEquals(c.test_a_class().wrapper__unwrap().__class__, TestA)
 def test(fh):
     o = Facade(cls=CallsServiceInInit)
     result = o.nested_init().methoda()
     fh.write(str(result == 'a'))
     fh.close()
     os._exit(0)
Пример #13
0
    def test_exclusion_list(self):
        # Ignore an instance:
        a = Facade(TestA())

        b = a.getb()
        self.assertEquals( b.__class__, Wrapper )

        a.wrapper__ignore( TestB )
        b = a.getb()
        self.assertEquals( b.__class__, TestB )

        a.wrapper__unignore( TestB )
        b = a.getb()
        self.assertEquals( b.__class__, Wrapper )

        # Ignore a class:
        c = Facade(TestC())

        self.assertTrue( c.test_a_class().__class__, Wrapper )

        c.wrapper__ignore( TestA )
        a = c.test_a_class()
        self.assertTrue( isinstance( a, TestA ) )
 def test(fh):
     Facade(o)
     result = o.update()
     fh.write(str(result == 1))
     fh.close()
     os._exit(0)
    def test_recache(self):
        mtc = TestC()
        mtc_f = Facade(mtc)

        hashes = []

        self.assertEquals(mtc.methoda(), mtc_f.methoda())
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc.methodb(), mtc_f.methodb())
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.methoda(), "a")
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)

        self.assertEquals(mtc_f.increment(), 1)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 2)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 3)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)
        self.assertEquals(mtc_f.increment(), 4)
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append(mtc_f.last_cached)

        # Ensure hashes are now in db:
        for hash in hashes:
            self.assertIsNotNone(hash, "Hash is none. whoops.")
            cd = fetch(hash)
            self.assertTrue(cd is not None, "%s was not found" % hash)
            self.assertEquals(cd.hash, hash, "%s was not found" % hash)

        # Delete some:
        caliendo.util.recache('methodb', 'caliendo_test.py')
        caliendo.util.recache('methoda', 'caliendo_test.py')

        # Ensure they're gone:
        methodb = hashes[0]
        methoda = hashes[1]
        cd = fetch(methodb)

        self.assertIsNone(cd, "Method b failed to recache.")
        cd = fetch(methoda)

        self.assertIsNone(cd, "Method a failed to recache.")

        # Ensure the rest are there:
        hashes = hashes[3:]
        for hash in hashes:
            cd = fetch(hash)
            self.assertEquals(cd.hash, hash)

        # Delete them ALL:
        caliendo.util.recache()

        #Ensure they're all gone:
        for hash in hashes:
            cd = fetch(hash)
            self.assertIsNone(cd)
Пример #16
0
    def test_recache(self):
        mtc = TestC( )
        mtc_f = Facade( mtc )

        hashes = []

        self.assertEquals( mtc.methoda( ), mtc_f.methoda( ) )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc.methodb( ), mtc_f.methodb( ) )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.methoda( ), "a" )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )

        self.assertEquals( mtc_f.increment( ), 1 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 2 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 3 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )
        self.assertEquals( mtc_f.increment( ), 4 )
        self.assertIsNotNone(mtc_f.last_cached)
        hashes.append( mtc_f.last_cached )

        # Ensure hashes are now in db:
        for hash in hashes:
            self.assertIsNotNone(hash, "Hash is none. whoops.")
            cd = fetch( hash )
            self.assertTrue( cd is not None, "%s was not found" % hash )
            self.assertEquals( cd.hash, hash, "%s was not found" % hash )

        # Delete some:
        caliendo.util.recache( 'methodb', 'caliendo_test.py' )
        caliendo.util.recache( 'methoda', 'caliendo_test.py' )

        # Ensure they're gone:
        methodb = hashes[0]
        methoda = hashes[1]
        cd = fetch( methodb )

        self.assertIsNone( cd, "Method b failed to recache." )
        cd = fetch( methoda )

        self.assertIsNone( cd, "Method a failed to recache." )

        # Ensure the rest are there:
        hashes = hashes[3:]
        for hash in hashes:
            cd = fetch( hash )
            self.assertEquals( cd.hash, hash )

        # Delete them ALL:
        caliendo.util.recache()

        #Ensure they're all gone:
        for hash in hashes:
            cd = fetch( hash )
            self.assertIsNone( cd )
Пример #17
0
 def test(fh):
     o = Facade( cls=CallsServiceInInit )
     result = o.nested_init().methoda()
     fh.write(str(result == 'a'))
     fh.close()
     os._exit(0)
    def test_exclusion_list(self):
        # Ignore an instance:
        a = Facade(TestA())

        b = a.getb()
        self.assertEquals(b.__class__, Wrapper)

        a.wrapper__ignore(TestB)
        b = a.getb()
        self.assertEquals(b.__class__, TestB)

        a.wrapper__unignore(TestB)
        b = a.getb()
        self.assertEquals(b.__class__, Wrapper)

        # Ignore a class:
        c = Facade(TestC())

        self.assertTrue(c.test_a_class().__class__, Wrapper)

        c.wrapper__ignore(TestA)
        a = c.test_a_class()
        self.assertTrue(isinstance(a, TestA))
Пример #19
0
 def test(fh):
     o = Facade( a )
     result = o.methoda()
     fh.write(str(result == 'a'))
     fh.close()
     os._exit(0)
 def test(fh):
     o = Facade(a)
     result = o.methoda()
     fh.write(str(result == 'a'))
     fh.close()
     os._exit(0)