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
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())
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
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()
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
def test_basic(tmpdir): with Session([TmpdirManager(tmpdir)]) as sess: assert sess.eval(analysis(calcs())) == 20