def test_save_layer_multiple_no_named_plugin(tmpdir, layer_data_and_types): """Test saving multiple layers without naming a plugin.""" # make writer builtin plugins get called first from napari.plugins import plugin_manager plugin_manager.hooks.napari_get_writer.bring_to_front(['builtins']) layers, _, _, filenames = layer_data_and_types path = os.path.join(tmpdir, 'layers_folder') # Check file does not exist assert not os.path.isdir(path) # Write data save_layers(path, layers, plugin='builtins') # Check folder now exists assert os.path.isdir(path) # Check individual files now exist for f in filenames: assert os.path.isfile(os.path.join(path, f)) # Check no additional files exist assert set(os.listdir(path)) == set(filenames) assert set(os.listdir(tmpdir)) == {'layers_folder'}
def test_save_layer_single_named_plugin(tmpdir, layer_data_and_types): """Test saving a single layer with a named plugin.""" layers, _, _, filenames = layer_data_and_types for layer, fn in zip(layers, filenames): path = os.path.join(tmpdir, fn) # Check file does not exist assert not os.path.isfile(path) # Write data save_layers(path, [layer], plugin='builtins') # Check file now exists assert os.path.isfile(path)
def test_save_layer_single_no_named_plugin(builtins, tmpdir, layer_data_and_types): """Test saving a single layer without naming plugin.""" # make writer builtin plugins get called first layers, _, _, filenames = layer_data_and_types for layer, fn in zip(layers, filenames): path = os.path.join(tmpdir, fn) # Check file does not exist assert not os.path.isfile(path) # Write data save_layers(path, [layer]) # Check file now exists assert os.path.isfile(path)
def test_save_layer_single_no_named_plugin(tmpdir, layer_data_and_types): """Test saving a single layer without naming plugin.""" # make writer builtin plugins get called first from napari.plugins import plugin_manager plugin_manager.hooks.napari_write_image.bring_to_front(['builtins']) plugin_manager.hooks.napari_write_points.bring_to_front(['builtins']) layers, _, _, filenames = layer_data_and_types for layer, fn in zip(layers, filenames): path = os.path.join(tmpdir, fn) # Check file does not exist assert not os.path.isfile(path) # Write data save_layers(path, [layer]) # Check file now exists assert os.path.isfile(path)
def test_save_layer_multiple_named_plugin(tmpdir, layer_data_and_types): """Test saving multiple layers with a named plugin.""" layers, _, _, filenames = layer_data_and_types path = os.path.join(tmpdir, 'layers_folder') # Check file does not exist assert not os.path.isdir(path) # Write data save_layers(path, layers, plugin='builtins') # Check folder now exists assert os.path.isdir(path) # Check individual files now exist for f in filenames: assert os.path.isfile(os.path.join(path, f)) # Check no additional files exist assert set(os.listdir(path)) == set(filenames) assert set(os.listdir(tmpdir)) == {'layers_folder'}
def test_write_and_read(make_napari_viewer): with tempfile.TemporaryDirectory() as tmpdir: ds_path = os.path.join(tmpdir, 'tmp.zarr') dataset = ZDataset(ds_path, mode='w') dataset.add_channel('Image', shape=(5, 25, 25, 25), dtype=int, value=0) dataset.append_metadata({ 'Image': { 'dz': 2, 'dt': 20, 'tx': 1.5, 'tz': 3.5, } }) dataset.close() viewer: napari.Viewer = make_napari_viewer() layer = viewer.open(ds_path)[0] assert np.all(layer.scale == (20, 2, 1, 1)) assert np.all(layer.translate == (0, 3.5, 0, 1.5)) saved_path = os.path.join(tmpdir, 'saved.zarr') save_layers(saved_path, [layer]) saved_layer = viewer.open(saved_path)[0] assert np.all(np.asarray(saved_layer.data) == np.asarray(layer.data))
def test_save_layer_no_results(): """Test no layers is not an error, and warns on no results.""" with pytest.warns(UserWarning): result = save_layers('no_layers', []) assert result == []
def test_save_layer_no_results(tmpdir): """Test no layers is not an error, and warns on no results.""" with pytest.warns(UserWarning): result = save_layers('no_layers', [], plugin='builtins') assert result == []