Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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)
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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 != ""
Exemple #9
0
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
Exemple #10
0
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)
Exemple #11
0
def test_list_item_changed():
    grp = mo.Group()
    grp.items = []
    grp._changed = False
    grp.items.append(mo.Group())
    assert grp._changed