Ejemplo n.º 1
0
def test_runs(db: RunDBInterface):
    run1 = new_run('s1', {'l1': 'v1', 'l2': 'v2'}, x=1)
    db.store_run(run1, 'uid1')
    run2 = new_run('s1', {'l2': 'v2', 'l3': 'v3'}, x=2)
    db.store_run(run2, 'uid2')
    run3 = new_run('s2', {'l3': 'v3'}, x=2)
    uid3 = 'uid3'
    db.store_run(run3, uid3)
    db.store_run(run3, uid3)  # should not raise

    updates = {
        'status': {
            'start_time': run_now(),
            'state': 's2',
        },
    }
    db.update_run(updates, uid3)

    runs = db.list_runs(labels={'l2': 'v2'})
    assert 2 == len(runs), 'labels length'
    assert {1, 2} == {r['x'] for r in runs}, 'xs labels'

    runs = db.list_runs(state='s2')
    assert 1 == len(runs), 'state length'
    run3['status'] = updates['status']
    assert run3 == runs[0], 'state run'

    db.del_run(uid3)
    with pytest.raises(RunDBError):
        db.read_run(uid3)

    label = 'l1'
    db.del_runs(labels=[label])
    for run in db.list_runs():
        assert label not in run['metadata']['labels'], 'del_runs'
Ejemplo n.º 2
0
def test_update_run(db: sqldb.SQLDB):
    uid = 'uid83'
    run = new_run('s1', {'l1': 'v1', 'l2': 'v2'}, x=1)
    db.store_run(run, uid)
    val = 13
    db.update_run({'x': val}, uid)
    r = db.read_run(uid)
    assert val == r['x'], 'bad update'
Ejemplo n.º 3
0
def test_list_runs(db: RunDBInterface):
    if isinstance(db, FileRunDB):
        pytest.skip('FIXME')
    uid = 'u183'
    run = new_run('s1', {'l1': 'v1', 'l2': 'v2'}, uid, x=1)
    count = 5
    for iter in range(count):
        db.store_run(run, uid, iter=iter)

    runs = list(db.list_runs(uid=uid))
    assert 1 == len(runs), 'iter=False'

    runs = list(db.list_runs(uid=uid, iter=True))
    assert 5 == len(runs), 'iter=True'
Ejemplo n.º 4
0
def test_list_projects(db: sqldb.SQLDB):
    for i in range(10):
        run = new_run('s1', {'l1': 'v1', 'l2': 'v2'}, x=1)
        db.store_run(run, 'u7', project=f'prj{i%3}', iter=i)

    assert {'prj0', 'prj1', 'prj2'} == {p.name for p in db.list_projects()}
Ejemplo n.º 5
0
def test_run_iter0(db: sqldb.SQLDB):
    uid, prj = 'uid39', 'lemon'
    run = new_run('s1', {'l1': 'v1', 'l2': 'v2'}, x=1)
    for i in range(7):
        db.store_run(run, uid, prj, i)
    db._get_run(uid, prj, 0)  # See issue 140