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)
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)