def test_final_property(self):
        from Merlin.Testing.BaseClass import Callback, CProperty32

        class C(CProperty32):
            pass

        x = C()
        Callback.On(x)  # 0 - 4 + 400 + 40
        pv = x.Property  # -4
        self.assertEqual(432, pv)

        class C(CProperty32):
            def __init__(self):
                self.field = 5

            def get_Property(self):
                return self.field

            def set_Property(self, value):
                self.field = value + 50

            Property = property(get_Property, set_Property)

        x = C()
        Callback.On(x)
        #self.assertEqual(x.Property, 5)  # bug 372831
        x.Property = 6
    def test_long_hierarchy(self):
        from Merlin.Testing import Flag
        from Merlin.Testing.BaseClass import Callback, CType11, CType21
        class C(CType11): pass

        x = C()
        x.m1()
        Flag.Check(10)
        
        Flag.Reset()
        Callback.On(x)
        Flag.Check(10)
        
        class C(CType11):
            def m1(self): Flag.Set(20)
        
        x = C()
        Callback.On(x)
        Flag.Check(20)
        
        class C(CType21):
            pass
        x = C()
        self.assertRaises(AttributeError, Callback.On, x)
        
        class C(CType21):
            def m1(self): Flag.Set(30)
        x = C()
        Callback.On(x)
        Flag.Check(30)
Exemplo n.º 3
0
 def test_super_on_property(self):
     from Merlin.Testing.BaseClass import Callback, CProperty30
     class C(CProperty30):
         def get_Property(self): 
             return super(C, self).Property
         def set_Property(self, value):
             CProperty30.Property.SetValue(self, value + 500)
         Property = property(get_Property, set_Property)
     
     x = C()
     Callback.On(x)   # read (base_read)/+200/+500/write (base_write/+20)
     self.assertEqual(x.Property, 720)
     
     x = C()
     x.Property = 1
     self.assertEqual(x.Property, 521)
 
     ## bad user code attempt: use 'Property' directly
     class C(CProperty30): 
         def get_Property(self): 
             return super(C, self).Property
         def set_Property(self, value):
             super(C, self).Property = value
         Property = property(get_Property, set_Property)
     x = C()
     self.assertRaises(AttributeError, Callback.On, x)
     self.assertEqual(x.Property, 0)      # read
     
     def f(): x.Property = 1  # write
     self.assertRaises(AttributeError, f)   # cannot set slot
Exemplo n.º 4
0
 def test_abstract_property(self):
     from Merlin.Testing.BaseClass import Callback, CProperty31
     class C(CProperty31): 
         pass
     x = C()
     self.assertRaises(AttributeError, Callback.On, x)
     
     class C(CProperty31):
         def __init__(self):
             self.field = 1
         def get_PropertyX(self): 
             return self.field;
         def set_PropertyX(self, value):
             self.field = value + 10
         Property = property(get_PropertyX, set_PropertyX)
     
     x = C()
     Callback.On(x)
     self.assertEqual(x.field, 111)
     
     x = C()
     self.assertTrue(not hasattr(CProperty31, 'get_Property'))
     self.assertTrue(not hasattr(CProperty31, 'set_Property'))
     self.assertTrue(not hasattr(x, 'get_Property'))
     self.assertTrue(not hasattr(x, 'set_Property'))
 def test_final_methods(self):
     from Merlin.Testing.BaseClass import Callback, Class210e
     class C(Class210e): 
         def m210(self): return 700
     x = C()
     self.assertEqual(x.m210(), 700)
     #self.assertEqual(Class210a.m210(x), 210) # bug 368813
     self.assertEqual(Class210e.m210(x), 214)
     self.assertEqual(Callback.On(x), 214)
    def test_virtual_property(self):
        from Merlin.Testing.BaseClass import Callback, CProperty30

        class C(CProperty30):
            pass

        x = C()
        Callback.On(x)
        self.assertEqual(x.Property, 220)

        self.assertTrue(not hasattr(CProperty30, 'set_Property'))
        self.assertTrue(not hasattr(CProperty30, 'get_Property'))

        class C(CProperty30):
            def __init__(self):
                self.field = 3

            def get_Property(self):
                return self.field

            def set_Property(self, value):
                self.field = value + 30

        x = C()
        Callback.On(x)
        self.assertEqual(
            x.field,
            233)  # we read field, we added 200 from C#, and added 30 ourself
        self.assertEqual(x.Property, 233)

        x.field = 3
        C.Property = property(C.get_Property, C.set_Property)
        Callback.On(x)
        self.assertEqual(x.field, 233)
        self.assertEqual(x.Property, 233)

        self.assertTrue(not hasattr(CProperty30, 'set_Property'))
        self.assertTrue(not hasattr(CProperty30, 'get_Property'))

        del C.Property  # workaround: remove after bug 327528
        C.Property = property(C.get_Property)
        self.assertRaisesMessage(AttributeError, "readonly attribute",
                                 Callback.On, x)
Exemplo n.º 7
0
 def test_basic(self): 
     from Merlin.Testing.BaseClass import Callback, COperator10
     class C(COperator10):
         def __add__(self, other):
             return C(self.Value * other.Value)
             
     x = C(4)
     y = C(5)
     z = x + y
     self.assertEqual(z.Value, 20)
     
     z = Callback.On(x, y)
Exemplo n.º 8
0
 def test_super_on_default_index(self):
     from Merlin.Testing.BaseClass import Callback, CIndexer40
     class C(CIndexer40):
         def __setitem__(self, index, value):
             super(C, self).__setitem__(index, value)
         def __getitem__(self, index):
             return super(C, self).__getitem__(index)
     
     x = C()
     Callback.On(x)
     self.assertEqual(x[0], 12)
     x[1] = 90
     self.assertEqual(x[1], 90)
    def test_virtual_override_method(self):
        from Merlin.Testing.BaseClass import Callback, Class210a, Class210b, Class210c, Class210d

        class C(Class210b):
            pass

        x = C()
        self.assertEqual(Class210a.m210(x), 210)
        self.assertEqual(Class210b.m210(x), 211)
        self.assertEqual(x.m210(), 211)
        self.assertEqual(C.m210(x), 211)
        self.assertEqual(Callback.On(x), 210)

        C.m210 = lambda self: 400
        self.assertEqual(Class210a.m210(x), 210)
        self.assertEqual(Class210b.m210(x), 211)
        self.assertEqual(x.m210(), 400)
        self.assertEqual(C.m210(x), 400)
        self.assertEqual(Callback.On(x), 210)

        class C(Class210c):
            def m210(self):
                return 500

        x = C()
        #self.assertEqual(Class210a.m210(x), 210) # bug 368813
        self.assertEqual(Class210c.m210(x), 212)
        self.assertEqual(x.m210(), 500)
        self.assertEqual(C.m210(x), 500)
        self.assertEqual(Callback.On(x), 500)

        del C.m210
        #self.assertEqual(Class210a.m210(x), 210) # bug 368813
        self.assertEqual(Class210c.m210(x), 212)
        self.assertEqual(x.m210(), 212)
        self.assertEqual(C.m210(x), 212)
        self.assertEqual(Callback.On(x), 212)

        class C(Class210d):
            pass

        x = C()
        self.assertEqual(Class210a.m210(x), 210)
        self.assertEqual(Class210d.m210(x), 210)
        self.assertEqual(x.m210(), 210)
        self.assertEqual(C.m210(x), 210)
        self.assertEqual(Callback.On(x), 210)

        C.m210 = lambda self: 600
        #self.assertEqual(Class210a.m210(x), 210) # bug 368813
        self.assertEqual(Class210d.m210(x), 210)
        self.assertEqual(x.m210(), 600)
        self.assertEqual(C.m210(x), 600)
        self.assertEqual(Callback.On(x), 600)