Ejemplo n.º 1
0
 def testKlass(self):
   self.assertEqual(t2.Klass.C2(), 3)
   k = t2.Klass(3)
   self.assertEqual(k.i, 3)
   self.assertEqual(k.i2, 9)
   self.assertEqual(k.Int1(), 4)
   self.assertIs(False, t2.k_check(k))
   with self.assertRaises(TypeError):
     t2.k_check(0)
   k.i = 0
   self.assertIs(True, t2.k_check(k))
   # AttributeError on CPython; TypeError on PyPy.
   with self.assertRaises((AttributeError, TypeError)):
     k.i2 = 0
   t2.k_modify(k, 5)
   self.assertEqual(k.i, 5)
Ejemplo n.º 2
0
 def testDerived(self):
   k = t2.Derived()
   self.assertEqual(k.i, 0)
   self.assertEqual(k.j, 0)
   self.assertIs(True, t2.k_check(k))
   self.assertNotIn(2, k)
   with self.assertRaises(TypeError):
     t2.Derived(1)
Ejemplo n.º 3
0
 def testDerivedInit(self):
   k = t2.Derived.Init(1, 2)
   self.assertEqual(k.i, 1)
   self.assertEqual(k.j, 2)
   self.assertIs(False, t2.k_check(k))
Ejemplo n.º 4
0
 def test_class_name(self):
   with self.assertRaisesRegexp(TypeError, r'\bOldStyleClass\b'):
     t2.k_check(OldStyleClass())