From 2d273cd96c4512c768cfe398dd2e3b0973afa243 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Mon, 11 Oct 2021 09:23:57 -0400 Subject: [PATCH] Apply "skipif_no_network" to all relevant tests --- dandi/cli/tests/test_ls.py | 5 +++++ dandi/tests/fixtures.py | 5 ++--- dandi/tests/skip.py | 5 +++++ dandi/tests/test_dandiapi.py | 4 ++++ dandi/tests/test_dandiarchive.py | 3 ++- dandi/tests/test_download.py | 5 +++++ dandi/tests/test_utils.py | 5 ++--- tox.ini | 1 + 8 files changed, 26 insertions(+), 7 deletions(-) diff --git a/dandi/cli/tests/test_ls.py b/dandi/cli/tests/test_ls.py index b6d6ddf2..35f963ea 100644 --- a/dandi/cli/tests/test_ls.py +++ b/dandi/cli/tests/test_ls.py @@ -5,6 +5,8 @@ from dandischema.consts import DANDI_SCHEMA_VERSION import pytest +from dandi.tests.skip import mark + from ..command import ls from ...utils import yaml_load @@ -46,6 +48,7 @@ def load(s): assert metadata[f] == simple1_nwb_metadata[f] +@mark.skipif_no_network def test_ls_dandiset_url(): r = CliRunner().invoke( ls, ["-f", "yaml", "https://api.dandiarchive.org/api/dandisets/000027"] @@ -56,6 +59,7 @@ def test_ls_dandiset_url(): assert data[0]["path"] == "000027" +@mark.skipif_no_network def test_ls_dandiset_url_recursive(): r = CliRunner().invoke( ls, ["-f", "yaml", "-r", "https://api.dandiarchive.org/api/dandisets/000027"] @@ -67,6 +71,7 @@ def test_ls_dandiset_url_recursive(): assert data[1]["path"] == "sub-RAT123/sub-RAT123.nwb" +@mark.skipif_no_network def test_ls_path_url(): r = CliRunner().invoke( ls, diff --git a/dandi/tests/fixtures.py b/dandi/tests/fixtures.py index 41dfd05a..d667b750 100644 --- a/dandi/tests/fixtures.py +++ b/dandi/tests/fixtures.py @@ -126,9 +126,8 @@ def get_gitrepo_fixture(url, committish=None, scope="session"): @pytest.fixture(scope=scope) def fixture(): - # TODO: adapt reproman.tests.skip collection of skipif conditions - # skipif.no_network() - # skipif.no_git() + skipif.no_network() + skipif.no_git() path = tempfile.mktemp() # not using pytest's tmpdir fixture to not # collide in different scopes etc. But we diff --git a/dandi/tests/skip.py b/dandi/tests/skip.py index 5fbc8cae..7fed7583 100644 --- a/dandi/tests/skip.py +++ b/dandi/tests/skip.py @@ -121,6 +121,10 @@ def is_engine_running(): return "docker engine not running", not is_engine_running() +def no_git(): + return "Git not installed", shutil.which("git") is None + + # ### END MODIFIED CODE @@ -157,6 +161,7 @@ def on_windows(): # no_docker_dependencies, no_docker_commands, no_docker_engine, + no_git, no_network, # no_singularity, no_ssh, diff --git a/dandi/tests/test_dandiapi.py b/dandi/tests/test_dandiapi.py index 49344700..03e092fa 100644 --- a/dandi/tests/test_dandiapi.py +++ b/dandi/tests/test_dandiapi.py @@ -13,6 +13,7 @@ import pytest import responses +from .skip import mark from .. import dandiapi from ..consts import ( DRAFT, @@ -279,6 +280,7 @@ def test_authenticate_bad_key_keyring_good_key_input( confirm_mock.assert_called_once_with("API key is invalid; enter another?") +@mark.skipif_no_network def test_get_content_url(tmp_path): with DandiAPIClient.for_dandi_instance("dandi") as client: asset = client.get_dandiset("000027", "draft").get_asset_by_path( @@ -297,6 +299,7 @@ def test_get_content_url(tmp_path): fp.write(chunk) +@mark.skipif_no_network def test_get_content_url_regex(tmp_path): with DandiAPIClient.for_dandi_instance("dandi") as client: asset = client.get_dandiset("000027", "draft").get_asset_by_path( @@ -309,6 +312,7 @@ def test_get_content_url_regex(tmp_path): fp.write(chunk) +@mark.skipif_no_network def test_get_content_url_follow_one_redirects_strip_query(): with DandiAPIClient.for_dandi_instance("dandi") as client: asset = client.get_dandiset("000027", "draft").get_asset_by_path( diff --git a/dandi/tests/test_dandiarchive.py b/dandi/tests/test_dandiarchive.py index 25da881c..9969a85e 100644 --- a/dandi/tests/test_dandiarchive.py +++ b/dandi/tests/test_dandiarchive.py @@ -100,13 +100,14 @@ version_id="draft", ), ), - ( + pytest.param( "DANDI:000027", DandisetURL( api_url=known_instances["dandi"].api, dandiset_id="000027", version_id="draft", # TODO: why not None? ), + marks=mark.skipif_no_network, ), ( "http://localhost:8000/api/dandisets/000002/versions/draft", diff --git a/dandi/tests/test_download.py b/dandi/tests/test_download.py index 2ae12623..f8b9eab5 100644 --- a/dandi/tests/test_download.py +++ b/dandi/tests/test_download.py @@ -6,6 +6,7 @@ import pytest +from .skip import mark from ..consts import DRAFT from ..download import download from ..utils import find_files @@ -13,6 +14,7 @@ # both urls point to 000027 (lean test dataset), and both draft and "released" # version have only a single file ATM +@mark.skipif_no_network @pytest.mark.parametrize( "url", [ # Should go through API @@ -48,6 +50,7 @@ def test_download_000027(url, tmpdir): download(url, tmpdir, existing="refresh") # TODO: check that skipped (the same) +@mark.skipif_no_network @pytest.mark.parametrize( "url", [ # Should go through API @@ -64,6 +67,7 @@ def test_download_000027_metadata_only(url, tmpdir): assert sorted(downloads) == ["dandiset.yaml"] +@mark.skipif_no_network @pytest.mark.parametrize( "url", [ # Should go through API @@ -80,6 +84,7 @@ def test_download_000027_assets_only(url, tmpdir): assert sorted(downloads) == ["sub-RAT123", op.join("sub-RAT123", "sub-RAT123.nwb")] +@mark.skipif_no_network @pytest.mark.parametrize("resizer", [lambda sz: 0, lambda sz: sz // 2, lambda sz: sz]) @pytest.mark.parametrize("version", ["0.210831.2033", DRAFT]) def test_download_000027_resume(tmp_path, resizer, version): diff --git a/dandi/tests/test_utils.py b/dandi/tests/test_utils.py index 79973640..8e418d0f 100644 --- a/dandi/tests/test_utils.py +++ b/dandi/tests/test_utils.py @@ -8,6 +8,7 @@ import responses from semantic_version import Version +from .skip import mark from .. import __version__ from ..consts import DandiInstance, known_instances from ..exceptions import BadCliVersionError, CliVersionTooOldError @@ -325,9 +326,7 @@ def test_get_instance_actual_dandi(): if "DANDI_REDIRECTOR_BASE" in os.environ: using_docker = pytest.mark.usefixtures("local_dandi_api") else: - - def using_docker(f): - return f + using_docker = mark.skipif_no_network @pytest.mark.redirector diff --git a/tox.ini b/tox.ini index 132d89fd..5393d761 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = lint,py3 [testenv] setenv = DANDI_ALLOW_LOCALHOST_URLS=1 +passenv = DANDI_* extras = test commands = # Using pytest-cov instead of using coverage directly leaves a bunch of