def test_register_classes_override(): """Test that register_classes overrides existing entries in the class index.""" class MyProcessSpec(ProcessSpec): pass normal = GEMDJson() custom = GEMDJson() custom.register_classes({MyProcessSpec.typ: MyProcessSpec}) obj = ProcessSpec(name="foo") assert not isinstance(normal.copy(obj), MyProcessSpec),\ "Class registration bled across GEMDJson() objects" assert isinstance(custom.copy(obj), ProcessSpec),\ "Custom GEMDJson didn't deserialize as MyProcessSpec"
def test_name_persistance(): """Verify that a serialized IngredientRun doesn't lose its name.""" from gemd.entity.object import IngredientSpec from gemd.entity.link_by_uid import LinkByUID from gemd.json import GEMDJson je = GEMDJson() ms_link = LinkByUID(scope='local', id='mat_spec') mr_link = LinkByUID(scope='local', id='mat_run') ps_link = LinkByUID(scope='local', id='pro_spec') pr_link = LinkByUID(scope='local', id='pro_run') spec = IngredientSpec(name='Ingred', labels=['some', 'words'], process=ps_link, material=ms_link) run = IngredientRun(spec=spec, process=pr_link, material=mr_link) assert run.name == spec.name assert run.labels == spec.labels # Try changing them and make sure they change spec.name = 'Frank' spec.labels = ['other', 'words'] assert run.name == spec.name assert run.labels == spec.labels run.spec = LinkByUID(scope='local', id='ing_spec') # Name and labels are now stashed but not stored assert run == je.copy(run) assert run.name == spec.name assert run.labels == spec.labels # Test that serialization doesn't get confused after a deser and set spec_too = IngredientSpec(name='Jorge', labels=[], process=ps_link, material=ms_link) run.spec = spec_too assert run == je.copy(run) assert run.name == spec_too.name assert run.labels == spec_too.labels