Skip to content

Commit

Permalink
[python] Name temp paths for clarity (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl authored Feb 24, 2025
1 parent 85c6629 commit 47ad4c2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apis/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def conftest_pbmc_small(conftest_pbmc_small_h5ad_path) -> AnnData:
@pytest.fixture
def conftest_pbmc_small_exp(conftest_pbmc_small_h5ad_path) -> Experiment:
"""Ingest an ``AnnData``, yield a ``TestCase`` with the original and new AnnData objects."""
with TemporaryDirectory() as exp_path:
with TemporaryDirectory("conftest_pbmc_small_exp_") as exp_path:
tiledbsoma.io.from_h5ad(
exp_path, conftest_pbmc_small_h5ad_path, measurement_name="RNA"
)
Expand Down
26 changes: 13 additions & 13 deletions apis/python/tests/test_basic_anndata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_import_anndata(conftest_pbmc_small, ingest_modes, X_kind):

have_ingested = False

tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_import_anndata_")
output_path = tempdir.name

conftest_pbmc_small.layers["plus1"] = conftest_pbmc_small.X + 1
Expand Down Expand Up @@ -233,7 +233,7 @@ def test_import_anndata(conftest_pbmc_small, ingest_modes, X_kind):
],
)
def test_named_X_layers(conftest_pbmc_small_h5ad_path, X_layer_name):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_named_X_layers_")
soma_path = tempdir.name

if X_layer_name is None:
Expand Down Expand Up @@ -281,13 +281,13 @@ def test_resume_mode(resume_mode_h5ad_file):
anything new
"""

tempdir1 = tempfile.TemporaryDirectory()
tempdir1 = tempfile.TemporaryDirectory(prefix="test_resume_mode_1_")
output_path1 = tempdir1.name
tiledbsoma.io.from_h5ad(
output_path1, resume_mode_h5ad_file.as_posix(), "RNA", ingest_mode="write"
)

tempdir2 = tempfile.TemporaryDirectory()
tempdir2 = tempfile.TemporaryDirectory(prefix="test_resume_mode_2_")
output_path2 = tempdir2.name
tiledbsoma.io.from_h5ad(
output_path2, resume_mode_h5ad_file.as_posix(), "RNA", ingest_mode="write"
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_resume_mode(resume_mode_h5ad_file):

@pytest.mark.parametrize("use_relative_uri", [False, True, None])
def test_ingest_relative(conftest_pbmc3k_h5ad_path, use_relative_uri):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_ingest_relative_")
output_path = tempdir.name

tiledbsoma.io.from_h5ad(
Expand Down Expand Up @@ -432,7 +432,7 @@ def test_ingest_uns(


def test_ingest_uns_string_arrays(h5ad_file_uns_string_arrays):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_ingest_uns_string_arrays_")
output_path = tempdir.name

tiledbsoma.io.from_h5ad(
Expand All @@ -458,7 +458,7 @@ def test_ingest_uns_string_arrays(h5ad_file_uns_string_arrays):


def test_add_matrix_to_collection(conftest_pbmc_small):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_add_matrix_to_collection_")
output_path = tempdir.name

original = conftest_pbmc_small.copy()
Expand Down Expand Up @@ -589,7 +589,7 @@ def add_matrix_to_collection(
use_relative_uri=use_relative_uri,
)

tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_add_matrix_to_collection_1_2_7_")
output_path = tempdir.name
original = conftest_pbmc_small.copy()

Expand Down Expand Up @@ -654,7 +654,7 @@ def add_matrix_to_collection(


def test_export_anndata(conftest_pbmc_small):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_export_anndata_")
output_path = tempdir.name

original = conftest_pbmc_small.copy()
Expand Down Expand Up @@ -696,7 +696,7 @@ def test_export_anndata(conftest_pbmc_small):


def test_ingest_additional_metadata(conftest_pbmc_small):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_ingest_additional_metadata_")
output_path = tempdir.name

additional_metadata = {"key1": "val1", "key2": "val2"}
Expand Down Expand Up @@ -829,7 +829,7 @@ def test_export_obsm_with_holes(h5ad_file_with_obsm_holes, tmp_path):


def test_X_empty(h5ad_file_X_empty):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_X_empty_")
output_path = tempdir.name
tiledbsoma.io.from_h5ad(
output_path, h5ad_file_X_empty.as_posix(), measurement_name="RNA"
Expand All @@ -846,7 +846,7 @@ def test_X_empty(h5ad_file_X_empty):


def test_X_none(h5ad_file_X_none):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_X_none_")
output_path = tempdir.name
tiledbsoma.io.from_h5ad(
output_path, h5ad_file_X_none.as_posix(), measurement_name="RNA"
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def test_index_names_io(tmp_path, obs_index_name, var_index_name):


def test_obsm_data_type(conftest_pbmc_small):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_obsm_data_type_")
soma_path = tempdir.name
bdata = anndata.AnnData(
X=conftest_pbmc_small.X,
Expand Down
2 changes: 1 addition & 1 deletion apis/python/tests/test_platform_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def test_platform_config(conftest_pbmc_small):
# Set up anndata input path and tiledb-group output path
original = conftest_pbmc_small.copy()
with tempfile.TemporaryDirectory() as output_path:
with tempfile.TemporaryDirectory(prefix="test_platform_config_") as output_path:
# Ingest
create_cfg = {
"capacity": 8888,
Expand Down
6 changes: 3 additions & 3 deletions apis/python/tests/test_registration_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def create_anndata_canned(which: int, obs_field_name: str, var_field_name: str):


def create_h5ad_canned(which: int, obs_field_name: str, var_field_name: str):
tmp_path = tempfile.TemporaryDirectory()
tmp_path = tempfile.TemporaryDirectory(prefix="create_h5ad_canned_")
anndata = create_anndata_canned(which, obs_field_name, var_field_name)
return create_h5ad(
anndata,
Expand All @@ -178,7 +178,7 @@ def create_h5ad_canned(which: int, obs_field_name: str, var_field_name: str):


def create_soma_canned(which: int, obs_field_name, var_field_name):
tmp_path = tempfile.TemporaryDirectory()
tmp_path = tempfile.TemporaryDirectory(prefix="create_soma_canned_")
h5ad = create_h5ad_canned(which, obs_field_name, var_field_name)
uri = tmp_path.name + f"soma{which}"
tiledbsoma.io.from_h5ad(uri, h5ad, "measname")
Expand All @@ -198,7 +198,7 @@ def anndata_larger():

@pytest.fixture
def soma_larger(anndata_larger):
tmp_path = tempfile.TemporaryDirectory()
tmp_path = tempfile.TemporaryDirectory(prefix="soma_larger_")
uri = tmp_path.name + "soma-larger"
tiledbsoma.io.from_anndata(uri, anndata_larger, "measname")
return uri
Expand Down
4 changes: 3 additions & 1 deletion apis/python/tests/test_update_dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def multiple_fixtures_with_readback(request, conftest_pbmc_small) -> TestCase:
AnnData/Pandas.
* Each `TestCase` member is also exposed directly as its own `fixture` below.
"""
with tempfile.TemporaryDirectory() as experiment_path:
with tempfile.TemporaryDirectory(
"multiple_fixtures_with_readback_"
) as experiment_path:
old_anndata = conftest_pbmc_small.copy()
tiledbsoma.io.from_anndata(
experiment_path, conftest_pbmc_small, measurement_name="RNA"
Expand Down
4 changes: 2 additions & 2 deletions apis/python/tests/test_update_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_update_matrix_X(conftest_pbmc3k_adata):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_update_matrix_X_")
output_path = tempdir.name

tiledbsoma.io.from_anndata(
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_update_matrix_X(conftest_pbmc3k_adata):

# Magical conftest.py fixture
def test_update_matrix_obsm(conftest_pbmc3k_adata):
tempdir = tempfile.TemporaryDirectory()
tempdir = tempfile.TemporaryDirectory(prefix="test_update_matrix_obsm_")
output_path = tempdir.name

tiledbsoma.io.from_anndata(
Expand Down

0 comments on commit 47ad4c2

Please sign in to comment.