def test_eval_with_symbolic_object(self): some_obj = mock.Mock() del some_obj._eval some_obj.some_attr = 'attribute value' expr = GetAttr(Symbol('some_symbol'), 'some_attr') self.assertEqual(expr._eval({'some_symbol': some_obj}), 'attribute value')
def test_eval_with_symbolic_object(self): some_obj = mock.Mock() del some_obj._eval some_obj.some_attr = 'attribute value' expr = GetAttr(Symbol('some_symbol'), 'some_attr') self.assertEqual( expr._eval({'some_symbol': some_obj}), 'attribute value')
def test_eval_with_nonsymbolic_object(self): some_obj = mock.Mock() del some_obj._eval # Ensure constructing the expression does not access `.some_attr`. del some_obj.some_attr with self.assertRaises(AttributeError): some_obj.some_attr expr = GetAttr(some_obj, 'some_attr') some_obj.some_attr = 'attribute value' self.assertEqual(expr._eval({}), 'attribute value')
def test_repr(self): self.assertEqual(repr(GetAttr('object', 'attrname')), "getattr('object', 'attrname')")