예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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 != ""
예제 #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
예제 #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)
예제 #11
0
def test_list_item_changed():
    grp = mo.Group()
    grp.items = []
    grp._changed = False
    grp.items.append(mo.Group())
    assert grp._changed