def test_manager_prepare(basedir, filenames_all, data_a, tmpdir): """Test the volume manager prepare method.""" # -- Setup ---------------------------------------------------------------- s1_dir = os.path.join(tmpdir, 's1') s0 = FileSystemStorage(basedir=basedir, identifier=DEFAULT_STORE) s1 = FileSystemStorage(basedir=s1_dir, identifier='s1') volumes = VolumeManager( stores=[s0.to_dict(), s1.to_dict()], files={f: [DEFAULT_STORE] for f in filenames_all} ) # Case 1: Empty arguments. volumes.prepare(store=s0, inputs=[], outputs=[]) # Case 2: No file copy. volumes.prepare(store=s0, inputs=['examples/'], outputs=['examples/']) assert len(os.listdir(basedir)) == 3 assert len(os.listdir(s1_dir)) == 0 for f in filenames_all: assert volumes.files[f] == [DEFAULT_STORE] # Case 3: Copy file between stores. volumes.prepare(store=s1, inputs=['A.json', 'docs/'], outputs=['results/A.json', 'docs/']) assert len(os.listdir(basedir)) == 3 assert len(os.listdir(s1_dir)) == 3 filename = os.path.join(s1_dir, 'A.json') assert os.path.isfile(filename) with s1.load('A.json').open() as f: assert json.load(f) == data_a assert volumes.files == { 'docs/D.json': [DEFAULT_STORE, 's1'], 'examples/data/data.json': [DEFAULT_STORE], 'examples/C.json': [DEFAULT_STORE], 'A.json': [DEFAULT_STORE, 's1'], 'examples/B.json': [DEFAULT_STORE] }
def test_engine_volume_manager(tmpdir): """Test creating the volume manager for a workflow run from the engine configuration and the default run store. """ runstore = FileSystemStorage(basedir=tmpdir, identifier=DEFAULT_STORE) # Minimal arguments. volumes = volume_manager(specs=[], runstore=runstore, runfiles=[]) assert len(volumes._storespecs) == 1 assert len(volumes.files) == 0 # Only runstore given. volumes = volume_manager(specs=[], runstore=runstore, runfiles=['a', 'b']) assert len(volumes._storespecs) == 1 assert volumes.files['a'] == [DEFAULT_STORE] assert volumes.files['b'] == [DEFAULT_STORE] # Multiple stores with files. doc_ignore = runstore.to_dict() doc_ignore['files'] = ['c', 'd'] doc_fs = FStore(basedir=tmpdir, identifier='s0') doc_fs['files'] = ['a', 'c'] volumes = volume_manager( specs=[doc_ignore, doc_fs, FStore(basedir=tmpdir, identifier='s1')], runstore=runstore, runfiles=['a', 'b']) assert len(volumes._storespecs) == 3 assert volumes.files['a'] == [DEFAULT_STORE, 's0'] assert volumes.files['b'] == [DEFAULT_STORE] assert volumes.files['c'] == ['s0'] assert volumes.files.get('d') is None