def test_ref(self): a = ref(symbol('a')) self.assertEqual(deref(a), undefined) self.assertEqual(setref(a, 100), 100) self.assertEqual(deref(a), 100) self.assertEqual(repr(a), "ref(symbol('a'))") b = ref(symbol('b'), 101) self.assertEqual(deref(b), 101)
def test_attr(self): a = ref(symbol('a')) b = attr(symbol('b'), a._get_value, a._set_value) self.assertEqual(deref(a), deref(b)) self.assertEqual(deref(b), undefined) self.assertEqual(setref(b, 101), 101) self.assertEqual(deref(b), 101) self.assertEqual(deref(a), 101) self.assertEqual(setref(a, 102), 102) self.assertEqual(deref(b), 102) self.assertEqual(deref(a), 102) c = attr(symbol('c'), a._get_value) self.assertEqual(deref(c), 102) with self.assertRaises(AttributeError): setref(c, 999)