def test_0_property(self): """Test that unbound Property objects can be created successfully""" prop = Property() self.assertIsNotNone(prop) self.assertIsInstance(prop, Property) self.assertIsInstance(type(prop), MetaProperty) self.assertRegexpMatches(str(prop), r".*unbound.*", re.I) roprop = Property(traits=['ro']) self.assertIsNotNone(roprop) self.assertIsInstance(roprop, ROProperty) self.assertIsInstance(type(prop), MetaProperty) roprop = ROProperty() self.assertIsNotNone(roprop) self.assertIsInstance(roprop, ROProperty) lazyprop = Property(lazy=True) self.assertIsInstance(lazyprop, LazyProperty) self.assertFalse(isinstance(lazyprop, SafeProperty)) safelazyprop = Property(lazy=True, isa=str) self.assertIsInstance(safelazyprop, LazyProperty) self.assertIsInstance(safelazyprop, SafeProperty) self.assertRaises(exc.LazyIsFalse, Property, lazy=False) self.assertRaises(exc.CoerceWithoutType, Property, coerce=lambda x: 1)
class TrivialRecord(Record): id = ROProperty() name = Property()
class CheeseCupboardRecord(Record): id = ROProperty(required=True, isa=int) name = SafeProperty(isa=str) best_cheese = SafeProperty(isa=CheeseRecord) cheeses = ListProperty(of=CheeseRecord) favorites = DictProperty(of=CheeseRecord)