Skip to content

Commit

Permalink
Define public API of datalad_next.tests
Browse files Browse the repository at this point in the history
This pretty much takes the role of `datalad_next.tests.utils`. The new
setup treats `tests` like any other sub-package and exposes reusable
tools as a public API at the top-level.

In doing so, `SkipTest` was made obsolete and excluded from that API.

The usage of `rmtree` is altered to import from `datalad_next.utils`.

#613
  • Loading branch information
mih committed Feb 5, 2024
1 parent 7e79ccf commit 23f02a9
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 45 deletions.
2 changes: 1 addition & 1 deletion datalad_next/annexbackends/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import io

from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_raises,
eq_,
)
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/annexremotes/tests/test_archivist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from datalad_next.datasets import Dataset
from datalad_next.runners import CommandError

from datalad_next.tests.utils import assert_result_count
from datalad_next.tests import assert_result_count


@pytest.fixture(autouse=False, scope="function")
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/annexremotes/tests/test_uncurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from datalad_next.consts import on_windows
from datalad_next.tests.utils import (
from datalad_next.tests import (
create_tree,
skip_if_on_windows,
skip_if_root,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_create_sibling_webdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)
from urllib.parse import quote as urlquote

from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_in,
assert_in_results,
assert_raises,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from datalad_next.exceptions import IncompleteResultsError
from datalad_next.utils import external_versions
from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_in,
assert_in_results,
assert_raises,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
credentials,
download,
)
from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_result_count,
assert_status,
)
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_ls_file_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from datalad_next.constraints.exceptions import CommandParametrizationError
# we need this fixture
from datalad_next.iter_collections.tests.test_iterzip import sample_zip
from datalad_next.tests.marker import skipif_no_network
from datalad_next.tests import skipif_no_network

from ..ls_file_collection import LsFileCollectionParamValidator

Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CommandParametrizationError,
ParameterConstraintContext,
)
from datalad_next.tests.utils import chpwd
from datalad_next.utils import chpwd

from ..status import (
opt_eval_subdataset_state_values,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/commands/tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os import sep

import pytest
from datalad_next.tests.utils import (
from datalad_next.tests import (
BasicGitTestRepo,
assert_raises,
create_tree,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/credman/tests/test_credman.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CredentialManager,
_get_cred_cfg_var,
)
from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_in,
assert_raises,
eq_,
Expand Down
4 changes: 2 additions & 2 deletions datalad_next/gitremotes/tests/test_datalad_annex.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
Dataset,
clone,
)
from datalad_next.tests.utils import (
from datalad_next.tests import (
DEFAULT_BRANCH,
DEFAULT_REMOTE,
assert_raises,
assert_status,
eq_,
rmtree,
skip_if_root,
)
from datalad_next.consts import on_windows
from datalad_next.exceptions import CommandError
from datalad_next.utils import rmtree
from ..datalad_annex import get_initremote_params_from_url


Expand Down
6 changes: 4 additions & 2 deletions datalad_next/iter_collections/tests/test_iterdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from pathlib import PurePath
import pytest

from datalad_next.tests.utils import (
from datalad_next.tests import (
create_tree,
)
from datalad_next.utils import (
check_symlink_capability,
rmtree,
)
from datalad_next.utils import check_symlink_capability

from ..directory import (
DirectoryItem,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/iter_collections/tests/test_itergitdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
import shutil

from datalad_next.tests.utils import rmtree
from datalad_next.tests import rmtree

from ..gitdiff import (
GitTreeItemType,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/iter_collections/tests/test_itergittree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from datalad_next.tests.utils import rmtree
from datalad_next.tests import rmtree

from ..gittree import (
GitTreeItem,
Expand Down
7 changes: 4 additions & 3 deletions datalad_next/iter_collections/tests/test_itergitworktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import pytest

from datalad_next.utils import check_symlink_capability

from datalad_next.tests.utils import rmtree
from datalad_next.utils import (
check_symlink_capability,
rmtree,
)

from ..gitworktree import (
GitWorktreeItem,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/iter_collections/tests/test_itertar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datalad.api import download

from datalad_next.tests.marker import skipif_no_network
from datalad_next.tests import skipif_no_network

from ..tarfile import (
TarfileItem,
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/iter_collections/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datalad_next.tests.utils import skip_wo_symlink_capability
from datalad_next.tests import skip_wo_symlink_capability

from ..utils import FileSystemItem

Expand Down
2 changes: 1 addition & 1 deletion datalad_next/patches/tests/test_cli_configoverrides.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datalad_next.utils import chpwd
from datalad_next.tests.utils import run_main
from datalad_next.tests import run_main


def test_cli_configoverrides(existing_dataset):
Expand Down
5 changes: 3 additions & 2 deletions datalad_next/patches/tests/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datalad_next.tests.utils import (
from datalad_next.tests import (
assert_in_results,
assert_raises,
chpwd,
)
from datalad_next.utils import chpwd

from datalad.api import configuration
from datalad_next.exceptions import IncompleteResultsError

Expand Down
2 changes: 1 addition & 1 deletion datalad_next/patches/tests/test_push.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datalad_next.tests.utils import (
from datalad_next.tests import (
DEFAULT_REMOTE,
assert_result_count,
)
Expand Down
6 changes: 3 additions & 3 deletions datalad_next/patches/tests/test_push_to_export_remote.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pathlib import Path
import pytest
from typing import Generator
from unittest.mock import (
MagicMock,
call,
patch,
)

from datalad_next.tests.utils import (
SkipTest,
from datalad_next.tests import (
assert_in,
assert_in_results,
eq_,
Expand Down Expand Up @@ -230,7 +230,7 @@ def get_export_records(self):


def test_is_valid_treeish():
raise SkipTest(
pytest.skip(
"this test is skipped until issue "
"https://github.com/datalad/datalad-next/issues/39 is solved")

Expand Down
7 changes: 2 additions & 5 deletions datalad_next/patches/tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import pytest

from datalad_next.exceptions import IncompleteResultsError
from datalad_next.tests.utils import (
SkipTest,
assert_result_count,
)
from datalad_next.tests import assert_result_count


def test_substitution_config_default(existing_dataset, no_result_rendering):
ds = existing_dataset

if ds.config.get('datalad.run.substitutions.python') is not None:
# we want to test default handling when no config is set
raise SkipTest(
pytest.skip(
'Test assumptions conflict with effective configuration')

# the {python} placeholder is not explicitly defined, but it has
Expand Down
26 changes: 26 additions & 0 deletions datalad_next/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .utils import (
BasicGitTestRepo,
DEFAULT_BRANCH,
DEFAULT_REMOTE,
assert_in,
assert_in_results,
assert_raises,
assert_result_count,
assert_status,
create_tree,
eq_,
get_deeply_nested_structure,
ok_,
ok_good_symlink,
ok_broken_symlink,
run_main,
skip_if_on_windows,
skip_if_root,
skip_wo_symlink_capability,
swallow_logs,
)


from .marker import (
skipif_no_network,
)
17 changes: 8 additions & 9 deletions datalad_next/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
call_git_lines,
call_git_success,
)
from datalad_next.tests.utils import (
from .utils import (
HTTPPath,
SkipTest,
WebDAVPath,
assert_ssh_access,
external_versions,
Expand Down Expand Up @@ -167,7 +166,7 @@ def datalad_cfg():
here was only introduced with that version.
"""
if external_versions['cmd:git'] < "2.32":
raise SkipTest(
pytest.skip(
"Git configuration redirect via GIT_CONFIG_GLOBAL "
"only supported since Git v2.32"
)
Expand Down Expand Up @@ -561,15 +560,15 @@ def httpbin(httpbin_service):
in some cases it is simply not desirable to run a test. For example,
the appveyor workers are more or less constantly unable to access the
public service. This fixture is evaluated at function-scope and
raises ``SkipTest`` whenever any of these undesired conditions is
skips the test whenever any of these undesired conditions is
detected. Otherwise it just relays ``httpbin_service``.
"""
if os.environ.get('DATALAD_TESTS_NONETWORK'):
raise SkipTest(
pytest.skip(
'Not running httpbin-based test: NONETWORK flag set'
)
if 'APPVEYOR' in os.environ and 'DEPLOY_HTTPBIN_IMAGE' not in os.environ:
raise SkipTest(
pytest.skip(
"Not running httpbin-based test on appveyor without "
"docker-deployed instance -- too unreliable"
)
Expand All @@ -591,7 +590,7 @@ def datalad_interactive_ui(monkeypatch):
> assert ... datalad_interactive_ui.log
"""
from datalad_next.uis import ui_switcher
from datalad_next.tests.utils import InteractiveTestUI
from .utils import InteractiveTestUI

with monkeypatch.context() as m:
m.setattr(ui_switcher, '_ui', InteractiveTestUI())
Expand All @@ -611,7 +610,7 @@ def datalad_noninteractive_ui(monkeypatch):
> assert ... datalad_interactive_ui.log
"""
from datalad_next.uis import ui_switcher
from datalad_next.tests.utils import TestUI
from .utils import TestUI

with monkeypatch.context() as m:
m.setattr(ui_switcher, '_ui', TestUI())
Expand All @@ -621,7 +620,7 @@ def datalad_noninteractive_ui(monkeypatch):
@pytest.fixture(autouse=False, scope="session")
def sshserver_setup(tmp_path_factory):
if not os.environ.get('DATALAD_TESTS_SSH'):
raise SkipTest(
pytest.skip(
"set DATALAD_TESTS_SSH=1 to enable")

# query a bunch of recognized configuration environment variables,
Expand Down
4 changes: 3 additions & 1 deletion datalad_next/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DEFAULT_BRANCH,
DEFAULT_REMOTE,
HTTPPath,
# TODO REMOVE FOR V2.0
SkipTest,
assert_in,
assert_in_results,
Expand All @@ -30,6 +31,7 @@
ok_broken_symlink,
ok_exists,
ok_good_symlink,
# TODO REMOVE FOR V2.0
rmtree,
skip_if_on_windows,
skip_if_root,
Expand Down Expand Up @@ -78,7 +80,7 @@ def __enter__(self):
from cheroot import wsgi
from wsgidav.wsgidav_app import WsgiDAVApp
except ImportError as e:
raise SkipTest('No WSGI capabilities. Install cheroot and/or wsgidav') from e
pytest.skip(f'No WSGI capabilities. Install cheroot and/or wsgidav ({e!r})')

if self.auth:
auth = {self.auth[0]: {'password': self.auth[1]}}
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/url_operations/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import requests

from datalad_next.tests.marker import skipif_no_network
from datalad_next.tests import skipif_no_network

from ..any import AnyUrlOperations
from ..http import (
Expand Down
2 changes: 1 addition & 1 deletion datalad_next/url_operations/tests/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from datalad_next.tests.utils import (
from datalad_next.tests import (
skip_if_on_windows,
)
from ..ssh import (
Expand Down

0 comments on commit 23f02a9

Please sign in to comment.