示例#1
0
文件: test_cache.py 项目: jhrmnn/mona
def test_db(db, mocker):
    sess = Session([Cache(db)])
    with sess:
        sess.eval(analysis(calcs()))
    mocker.patch.object(sess, 'run_task')
    with sess:
        assert sess.eval(analysis(calcs())) == 20
        assert not sess.run_task.called
示例#2
0
文件: test_files.py 项目: jhrmnn/mona
def test_missing_file(tmpdir):
    fmngr = FileManager(tmpdir)
    with pytest.raises(FilesError):
        with Session([fmngr]) as sess:
            sess.run_task(calcs())
            shutil.rmtree(tmpdir)
            fmngr._cache.clear()
            sess.eval(calcs())
示例#3
0
文件: test_files.py 项目: jhrmnn/mona
 def run(calcs, fmngr=None):
     with Session([fmngr] if fmngr else []) as sess:
         sess.run_task(calcs())
         fut = calcs().future_result()
         sess.eval(calcs())
         task = fut.resolve()[0][1].task
         output = task.resolve().resolve()['STDOUT']
         return task, output
示例#4
0
文件: test_files.py 项目: jhrmnn/mona
def test_access(tmpdir):
    fmngr = FileManager(tmpdir)
    with Session([fmngr]) as sess:
        sess.run_task(calcs())
        fut = calcs().future_result()
        sess.eval(calcs())
        task = fut.resolve()[0][1].task
        output = task.resolve().resolve()['STDOUT']
        assert int(output.value.read_text()) == 0
        shutil.rmtree(tmpdir)
        fmngr._cache.clear()
        with pytest.raises(FilesError):
            output.value.read_text()
示例#5
0
文件: test_cache.py 项目: jhrmnn/mona
def test_postponed(db):
    cache = Cache(db, write='on_exit')
    sess = Session([cache])
    with sess:
        sess.eval(analysis(calcs()), task_filter=lambda t: t.label[0] != '/')
        assert len(cache._objects) == 23
    assert not cache._objects
示例#6
0
def test_basic(tmpdir):
    with Session([TmpdirManager(tmpdir)]) as sess:
        assert sess.eval(analysis(calcs())) == 20