def test_deepcopy(self): RecordModel = Schema.record({ "value": Schema.prop(Schema.INT), }) ItemModel = Schema.entity("item", None, None, { "name": Schema.prop(Schema.STRING), "record": RecordModel, }) ListModel = Schema.entity( "list", None, None, { "c_items": Schema.array(Schema.component(ItemModel)), "r_items": Schema.array(Schema.reference(ItemModel)), }) context = Schema.SimpleEntityContext() with contextlib.closing(ListModel.create(context)) as l: l._append_item( "c_items", ItemModel.create(None, { "name": "aa", "record": { "value": 4 } })) l._append_item( "c_items", ItemModel.create(None, { "name": "bb", "record": { "value": 5 } })) l._append_item("r_items", l._get_array_item("c_items", 0)) l._append_item("r_items", l._get_array_item("c_items", 1)) self.assertEqual(4, l._get_array_item("c_items", 0).record.value) self.assertEqual(5, l._get_array_item("c_items", 1).record.value) self.assertEqual(l._get_array_item("r_items", 0), l._get_array_item("c_items", 0)) self.assertEqual(l._get_array_item("r_items", 1), l._get_array_item("c_items", 1)) with contextlib.closing(copy.deepcopy(l)) as ll: self.assertEqual( l._get_array_item("c_items", 0).uuid, ll._get_array_item("c_items", 0).uuid) self.assertEqual( l._get_array_item("c_items", 1).uuid, ll._get_array_item("c_items", 1).uuid) self.assertEqual( l._get_array_item("c_items", 0).modified, ll._get_array_item("c_items", 0).modified) self.assertEqual( l._get_array_item("c_items", 1).modified, ll._get_array_item("c_items", 1).modified) self.assertEqual( l._get_array_item("c_items", 0).name, ll._get_array_item("c_items", 0).name) self.assertEqual( l._get_array_item("c_items", 1).name, ll._get_array_item("c_items", 1).name) self.assertEqual(4, ll._get_array_item("c_items", 0).record.value) self.assertEqual(5, ll._get_array_item("c_items", 1).record.value) self.assertEqual(ll._get_array_item("r_items", 0), ll._get_array_item("c_items", 0)) self.assertEqual(ll._get_array_item("r_items", 1), ll._get_array_item("c_items", 1))
# TODO: support loaded/unloaded entities? # TODO: support mounted/unmounted entity concept (projects) # TODO: support write delay / transactions # TODO: access to auto proxy items for references # TODO: closing, reading, inserting, removing, modifying, copying, container # TODO: notifying, storage, resolving, moving # TODO: are interval descriptors implicit now? # TODO: display_layers could be a record # TODO: display_properties could be a record # TODO: layout could be a record # TODO: closed_items should be a set of references Calibration = Schema.record({ "offset": Schema.prop(Schema.FLOAT), "scale": Schema.prop(Schema.FLOAT), "units": Schema.prop(Schema.STRING), }) Point = Schema.fixed_tuple( [Schema.prop(Schema.FLOAT), Schema.prop(Schema.FLOAT)]) Size = Schema.fixed_tuple( [Schema.prop(Schema.FLOAT), Schema.prop(Schema.FLOAT)]) Rect = Schema.fixed_tuple([Point, Size]) Vector = Schema.fixed_tuple([Point, Point])