def test_existing_without_kwarg(self): self.assertIsNone(gattr(NESTED_OBJ, 'get_attr', 'get_attr', 'get_attr'))
def test_non_existing_is_none(self): self.assertIsNone(gattr(NESTED_OBJ, 'attr1', invoke_callables=True))
def test_error_returns_none(self): self.assertIsNone(gattr(NESTED_LIST, 'notthere'))
def test_existing(self): self.assertEqual(gattr(NESTED_OBJ, 'get_attr', 'get_attr', 'get_attr', invoke_callables=True), 'value') self.assertEqual(gattr(NESTED_OBJ, 'attr', 'get_attr', 'attr', invoke_callables=True), 'value') self.assertEqual(gattr(NESTED_OBJ, 'attr', 'attr', 'attr'), 'value')
def test_non_existing_is_none(self): self.assertIsNone(gattr(NESTED_LIST, 42))
def test_existing(self): self.assertEqual(gattr(NESTED_LIST, 0, 1), 1) self.assertEqual(gattr(NESTED_LIST, -1, 0), 2)
def test_default(self): self.assertEqual(gattr(NESTED_DICT, 'notthere', default='default'), 'default') self.assertEqual(gattr(NESTED_DICT, 'k1', 'n1k1', default='hello'), 'n1v1')
def test_non_existing_is_none(self): self.assertIsNone(gattr(NESTED_DICT, 'notthere'))
def test_existing(self): self.assertEqual(gattr(NESTED_DICT, 'k1', 'n1k1'), 'n1v1')