コード例 #1
0
 def test_deep_hasattr(self):
     class MyClass(object):
         pass
     obj = MyClass()
     obj.sub = MyClass()
     obj.sub.sub = MyClass()
     obj.a = 1
     obj.sub.b = 2
     obj.sub.sub.c = 3
     self.assertEqual(deep_hasattr(obj,'a'), True)
     self.assertEqual(deep_hasattr(obj,'z'), False)
     self.assertEqual(deep_hasattr(obj,'sub'), True)
     self.assertEqual(deep_hasattr(obj,'bus'), False)
     self.assertEqual(deep_hasattr(obj,'sub.b'), True)
     self.assertEqual(deep_hasattr(obj,'sub.y'), False)
     self.assertEqual(deep_hasattr(obj,'sub.sub.c'), True)
     self.assertEqual(deep_hasattr(obj,'sub.sub.d'), False)
     self.assertEqual(deep_hasattr(obj,'sub.blah.foo.d'), False)
コード例 #2
0
 def test_deep_hasattr(self):
     class MyClass(object):
         pass
     obj = MyClass()
     obj.sub = MyClass()
     obj.sub.sub = MyClass()
     obj.a = 1
     obj.sub.b = 2
     obj.sub.sub.c = 3
     self.assertEqual(deep_hasattr(obj, 'a'), True)
     self.assertEqual(deep_hasattr(obj, 'z'), False)
     self.assertEqual(deep_hasattr(obj, 'sub'), True)
     self.assertEqual(deep_hasattr(obj, 'bus'), False)
     self.assertEqual(deep_hasattr(obj, 'sub.b'), True)
     self.assertEqual(deep_hasattr(obj, 'sub.y'), False)
     self.assertEqual(deep_hasattr(obj, 'sub.sub.c'), True)
     self.assertEqual(deep_hasattr(obj, 'sub.sub.d'), False)
     self.assertEqual(deep_hasattr(obj, 'sub.blah.foo.d'), False)