예제 #1
0
def test_fs_volume_load_file(basedir, data_e):
    """Test loading a file from a file system storage volume."""
    store = FileSystemStorage(basedir=basedir)
    with store.load(key='examples/data/data.json').open() as f:
        doc = json.load(f)
    assert doc == data_e
    # -- Error case for unknown file.
    with pytest.raises(err.UnknownFileError):
        store.load(key='examples/data/unknown.json')
예제 #2
0
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]
    }
예제 #3
0
def test_fs_volume_subfolder(basedir, data_d, data_e):
    """Test creating a new storage volume for a sub-folder of the base directory
    of a file system storage volume.
    """
    store = FileSystemStorage(basedir=basedir)
    substore = store.get_store_for_folder(key='docs', identifier='SUBSTORE')
    assert substore.identifier == 'SUBSTORE'
    with substore.load(key='D.json').open() as f:
        doc = json.load(f)
    assert doc == data_d
    substore.erase()
    with store.load(key='examples/data/data.json').open() as f:
        doc = json.load(f)
    assert doc == data_e
    with pytest.raises(err.UnknownFileError):
        store.load(key='docs/D.json')