Skip to content

Commit

Permalink
RF: make any "new_dandiset" fixture work together with @sweep_embargo
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Nov 27, 2024
1 parent c56665c commit f2705df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
20 changes: 19 additions & 1 deletion dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,23 @@ def sample_dandiset_factory(
return SampleDandisetFactory(local_dandi_api, tmp_path_factory)


# @sweep_embargo can be used along with `new_dandiset` fixture to
# run the test against both embargoed and non-embargoed Dandisets.
# "embargo: bool" argument should be added to the test function.
sweep_embargo = pytest.mark.parametrize("embargo", [True, False])


@pytest.fixture()
def new_dandiset(
request: pytest.FixtureRequest, sample_dandiset_factory: SampleDandisetFactory
) -> SampleDandiset:
kws = {}
if "embargo" in request.node.fixturenames:
kws["embargo"] = request.node.callspec.params["embargo"]
return sample_dandiset_factory.mkdandiset(
f"Sample Dandiset for {request.node.name}"
f"Sample {'Embargoed' if kws.get('embargo') else 'Public'} "
f"Dandiset for {request.node.name}",
**kws,
)


Expand Down Expand Up @@ -813,3 +824,10 @@ def tmp_home(
monkeypatch.setenv("USERPROFILE", str(home))
monkeypatch.setenv("LOCALAPPDATA", str(home))
return home


@pytest.fixture()
def new_fixture(request: pytest.FixtureRequest) -> int:
if "embargo" in request.node.fixturenames:
print("EMBARGO: ", request.node.callspec.params["embargo"])
return 1
16 changes: 3 additions & 13 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pytest_mock import MockerFixture
import zarr

from .fixtures import SampleDandiset, SampleDandisetFactory
from .fixtures import SampleDandiset, sweep_embargo
from .test_helpers import assert_dirtrees_eq
from ..consts import ZARR_MIME_TYPE, EmbargoStatus, dandiset_metadata_file
from ..dandiapi import AssetType, RemoteBlobAsset, RemoteZarrAsset
Expand Down Expand Up @@ -250,21 +250,11 @@ def test_upload_bids_non_nwb_file(bids_dandiset: SampleDandiset) -> None:
assert [asset.path for asset in bids_dandiset.dandiset.get_assets()] == ["README"]


@pytest.mark.parametrize("embargo", [True, False])
def test_upload_sync_zarr(
mocker, sample_dandiset_factory: SampleDandisetFactory, embargo: bool
) -> None:
zarr_dandiset = sample_dandiset_factory.mkdandiset(
f"Sample {'embargoed' if embargo else 'public'} Dandiset",
embargo=embargo,
)
@sweep_embargo
def test_upload_sync_zarr(mocker, zarr_dandiset: SampleDandiset, embargo: bool) -> None:
assert zarr_dandiset.dandiset.embargo_status == (
EmbargoStatus.EMBARGOED if embargo else EmbargoStatus.OPEN
)
zarr.save(
zarr_dandiset.dspath / "sample.zarr", np.arange(1000), np.arange(1000, 0, -1)
)
zarr_dandiset.upload()
rmtree(zarr_dandiset.dspath / "sample.zarr")
zarr.save(zarr_dandiset.dspath / "identity.zarr", np.eye(5))
confirm_mock = mocker.patch("click.confirm", return_value=True)
Expand Down

0 comments on commit f2705df

Please sign in to comment.