def test_nested(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) assert len(test.items) == 2 test.items[1].name = "hello" orig_sub_version = test.items[1].unique_id assert len(test.items) == 2 mo.store(test) assert test.items[1].unique_id == orig_sub_version
def test_unique_links(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) sub_version = test.items[1].unique_id test.items = [test.items[1]] mo.store(test) test.items = [] test = mo.retrieve("group", unique_id=test.unique_id)[0] assert len(test.items) == 1, len(test.items) assert test.items[0].unique_id == sub_version
def test_circular_reference(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) orig_id = test.unique_id test.items[0].items.append(test) mo.store(test) test.items = [] test = mo.retrieve("group", unique_id=test.unique_id)[0] sub0 = test.items[0] assert len(sub0.items) == 2, sub0.items assert sub0.items[1].unique_id == orig_id assert test.unique_id == orig_id
def test_preserve_provenance(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) test2 = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) mo.store([test, test2]) assert len(test.items) == 2 test.items = [] test2.items = [] mo.store([test, test2]) assert len(test.items) == 0 previous = mo.retrieve("group", unique_id=test.prev_uid)[0] assert len(previous.items) == 2, repr(previous)
def test_remove_objects(sqlite): group = mo.Group(name="foo", items=[mo.Group(name="baz", description="hello")]) sub_id = group.items[0].unique_id mo.store(group) first = mo.retrieve("groups", unique_id=sub_id)[0] assert first.unique_id == sub_id mo.remove_objects(group, _override=True) test = mo.retrieve("groups", name="foo") assert not test test_sub = mo.retrieve("groups_items", target_id=sub_id) assert not test_sub
def test_clone01(): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) test2 = test.clone() assert test2.unique_id != test.unique_id assert test2.prev_uid == test.unique_id assert test2.items[0].unique_id == test.items[0].unique_id test3 = test.clone(True) assert test3.unique_id != test.unique_id assert test3.prev_uid == test.unique_id assert test3.items[0].unique_id != test.items[0].unique_id assert test3.items[0].prev_uid == test.items[0].unique_id
def test_recover(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) test.name = "howdy" top_version = test.unique_id sub_version = test.items[1].unique_id mo.store(test) mo.store(test) # should have no effect assert len(test.items) == 2 assert test.unique_id == top_version # make sure we can recover the previous version test.items = [] assert test.unique_id == top_version test = mo.retrieve("group", unique_id=top_version)[0] assert test.unique_id == top_version assert len(test.items) == 2, len(test.items) assert test.unique_id == top_version assert test.items[1].unique_id == sub_version
def test_simple(sqlite): test = mo.Group() uid = test.unique_id mo.store(test) assert test.unique_id == uid assert test.prev_uid != "" test.name = "hello" mo.store(test) assert test.unique_id == uid assert test.prev_uid != ""
def test_dill(): test = mo.Group(items=[mo.Group(description="hello")]) blob = dill.dumps(test) new = dill.loads(blob) assert new.items[0].description == "hello" # pylint: disable=no-member
def test_store_stubs(sqlite): test = mo.Group(items=[mo.Group(items=[mo.LcmsRun()]), mo.LcmsRun()]) mo.store(test) test = mo.retrieve("group", unique_id=test.unique_id)[0] assert isinstance(test.items[0], mo.Group) mo.store(test)
def test_list_item_changed(): grp = mo.Group() grp.items = [] grp._changed = False grp.items.append(mo.Group()) assert grp._changed