class Star(Record): hip_id = Property(isa=int, required=True, coerce=fix_id, check=lambda i: 0 < i < 120000) name = Property(isa=str) spectral_type = Property(isa=str) designations = DictProperty(of=basestring) coordinates = DictProperty(of=list_of(basestring))
def test_cast_collection(self): RecordList = list_of(Record) casted = VisitorPattern.cast(RecordList, [{}, {}]) self.assertIsInstance(casted[0], Record) self.assertIsInstance(casted, RecordList) empty_casted = VisitorPattern.cast(RecordList, []) self.assertIsInstance(empty_casted, RecordList)
class Pilcrow(Record): bar = ListProperty(of=Octothorpe) foo = Property(isa=Caret) baz = Property() quux = DictProperty(of=str) frop = DictProperty(of=list_of(unicode))
class FakeSite(JsonRecord): slug = Property() _custom_tags = DictProperty(of=list_of(str))
def auto_upgrade_list(cls, thing): if len(thing) and isinstance(thing[0], dict): return list_of(NCAutoJsonRecord)(thing) else: return thing