Exemplo n.º 1
0
 def test_mode(self):
     with ZipStore('data/store.zip', mode='w') as store:
         store['foo'] = b'bar'
     store = ZipStore('data/store.zip', mode='r')
     with pytest.raises(PermissionError):
         store['foo'] = b'bar'
     with pytest.raises(PermissionError):
         store.clear()
Exemplo n.º 2
0
    def test_flush(self):
        store = ZipStore('data/store.zip', mode='w')
        store['foo'] = b'bar'
        store.flush()
        assert store['foo'] == b'bar'
        store.close()

        store = ZipStore('data/store.zip', mode='r')
        store.flush()  # no-op
Exemplo n.º 3
0
    def test_flush(self):
        store = ZipStore('data/store.zip', mode='w')
        store['foo'] = b'bar'
        store.flush()
        assert store['foo'] == b'bar'
        store.close()

        store = ZipStore('data/store.zip', mode='r')
        with assert_raises(PermissionError):
            store.flush()
Exemplo n.º 4
0
def normalize_store_arg(store, clobber=False, default=dict):
    if store is None:
        return default()
    elif isinstance(store, str):
        if store.endswith('.zip'):
            mode = 'w' if clobber else 'a'
            return ZipStore(store, mode=mode)
        else:
            return DirectoryStore(store)
    else:
        return store
Exemplo n.º 5
0
def normalize_store_arg(store, clobber=False, storage_options=None, mode='w'):
    if store is None:
        return dict()
    elif isinstance(store, str):
        mode = mode if clobber else "r"
        if "://" in store or "::" in store:
            return FSStore(store, mode=mode, **(storage_options or {}))
        elif storage_options:
            raise ValueError("storage_options passed with non-fsspec path")
        if store.endswith('.zip'):
            return ZipStore(store, mode=mode)
        elif store.endswith('.n5'):
            return N5Store(store)
        else:
            return DirectoryStore(store)
    else:
        return store
Exemplo n.º 6
0
def test_local_plot_pipeline(tmp_path):
    height = 100.0

    input_file = "data/mogreps/MOGREPS-UK__wind_from_direction__2020-03-15T15__2020-03-16T07.zarr.zip"

    # Create a suitable filename for the output plot png file
    output_file = filename_for_plot(str(tmp_path),
                                    input_file,
                                    qualifier=f"_height{height}")
    assert output_file.endswith(
        "MOGREPS-UK__wind_from_direction__2020-03-15T15__2020-03-16T07_height100.0.png"
    )

    # Extract wind from direction array
    store = ZipStore(input_file)
    ds = xr.open_zarr(store)
    da = extract_wind_from_direction(ds, height)
    assert da.values.shape == (706, 553)

    # Plot the data and check the output file is a png
    with open(output_file, "wb") as file:
        plot_xarray_data_array(ds, da, file)
    assert Path(output_file).is_file()
    assert imghdr.what(output_file) == "png"
Exemplo n.º 7
0
 def create_store():
     path = tempfile.mktemp(suffix='.zip')
     atexit.register(os.remove, path)
     store = ZipStore(path)
     return store, None
Exemplo n.º 8
0
 def create_store(self):
     path = tempfile.mktemp(suffix='.zip')
     atexit.register(os.remove, path)
     store = ZipStore(path, mode='w')
     return store
Exemplo n.º 9
0
 def test_mode(self):
     with ZipStore('example.zip', mode='w') as store:
         store['foo'] = b'bar'
     store = ZipStore('example.zip', mode='r')
     with assert_raises(PermissionError):
         store['foo'] = b'bar'