def test_delattr(self): obj = Struct() obj.abc = 123 obj._LX_forbidden = 456 Dialect.delattr(obj, "abc") self.assertFalse(hasattr(obj, "abc")) with self.assertRaises(AttributeError) as cm: Dialect.delattr(obj, "efg") with self.assertRaises(exceptions.LXPrivateAttrError) as cm: Dialect.delattr(obj, "_LX_forbidden") with self.assertRaises(exceptions.ForbiddenAttrError) as cm: Dialect.delattr(obj, "__class__")
def test_getattr(self): obj = Struct() obj.abc = 123 obj._LX_forbidden = 456 self.assertEquals(123, Dialect.getattr(obj, "abc")) self.assertEquals(None, Dialect.getattr(obj, "efg", None)) with self.assertRaises(AttributeError) as cm: Dialect.getattr(obj, "efg") with self.assertRaises(exceptions.LXPrivateAttrError) as cm: Dialect.getattr(obj, "_LX_forbidden") with self.assertRaises(exceptions.ForbiddenAttrError) as cm: Dialect.getattr(obj, "__class__")
def test_setattr(self): obj = Struct() obj.abc = 123 obj._LX_forbidden = 456 Dialect.setattr(obj, "abc", 321) self.assertTrue(321, obj.abc) Dialect.setattr(obj, "efg", "xyz") self.assertTrue("xyz", obj.efg) with self.assertRaises(exceptions.LXPrivateAttrError) as cm: Dialect.setattr(obj, "_LX_forbidden", 101) with self.assertRaises(exceptions.ForbiddenAttrError) as cm: Dialect.setattr(obj, "__class__", "what a class!")