Skip to content

Commit

Permalink
Merge pull request #179 from datalad/rf-pytest
Browse files Browse the repository at this point in the history
nose -> pytest, isort imports in tests, unify requirements-devel to correspond to the form as in core
  • Loading branch information
yarikoptic authored Aug 30, 2022
2 parents e6face9 + 120bff7 commit ee4f7e4
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 121 deletions.
7 changes: 3 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@ test_script:
- cmd: md __testhome__
- sh: mkdir __testhome__
- cd __testhome__
# run test selecion (--traverse-namespace needed from Python 3.8 onwards)
- cmd: python -m nose --traverse-namespace -s -v -A "not (turtle)" --with-cov --cover-package datalad_container %DTS%
- sh: python -m nose --traverse-namespace -s -v -A "not (turtle)" --with-cov --cover-package datalad_container ${DTS}

# run test selecion (--traverse-namespace needed from Python 3.8 onwards)
- cmd: python -m pytest -s -v -m "not (turtle)" --doctest-modules --cov=datalad_container --pyargs %DTS%
- sh: python -m pytest -s -v -m "not (turtle)" --doctest-modules --cov=datalad_container --pyargs ${DTS}

after_test:
- python -m coverage xml
Expand Down
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ env:
- BOTO_CONFIG=/tmp/nowhere
- DATALAD_TESTS_SSH=1
- DATALAD_LOG_CMD_ENV=GIT_SSH_COMMAND
- TESTS_TO_PERFORM=
- NOSE_OPTS=-s
- NOSE_SELECTION_OP="not " # so it would be "not (integration or usecase)"
- TESTS_TO_PERFORM=datalad_container
- PYTEST_OPTS=-s
# Special settings/helper for combined coverage from special remotes execution
- COVERAGE=coverage
- DATALAD_DATASETS_TOPURL=http://datasets-tests.datalad.org
Expand Down Expand Up @@ -64,11 +63,11 @@ script:
# Run tests
- http_proxy=
PATH=$PWD/tools/coverage-bin:$PATH
$NOSE_WRAPPER python -m nose $NOSE_OPTS
-v -A "$NOSE_SELECTION_OP(integration or usecase or slow)"
--with-doctest
--with-cov --cover-package datalad_container
--logging-level=INFO
pytest $PYTEST_OPTS
-v
--cov datalad_container
--log-cli-level=INFO
--pyargs
$TESTS_TO_PERFORM
# Report WTF information using system wide installed version
- datalad wtf
Expand Down
3 changes: 0 additions & 3 deletions datalad_container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,3 @@
)
]
)

from datalad import setup_package
from datalad import teardown_package
13 changes: 7 additions & 6 deletions datalad_container/adapters/tests/test_docker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from distutils.spawn import find_executable
import os.path as op
import sys
from distutils.spawn import find_executable

import datalad_container.adapters.docker as da
from datalad.cmd import (
StdOutCapture,
WitlessRunner,
)
from datalad.support.exceptions import CommandError
from datalad.tests.utils import (
from datalad.tests.utils_pytest import (
SkipTest,
assert_in,
assert_raises,
Expand All @@ -18,6 +17,8 @@
with_tree,
)

import datalad_container.adapters.docker as da

if not find_executable("docker"):
raise SkipTest("'docker' not found on path")

Expand All @@ -39,7 +40,7 @@ def images_exist(args):


@with_tempfile
def test_docker_save_doesnt_exist(path):
def test_docker_save_doesnt_exist(path=None):
image_name = "idonotexistsurely"
if images_exist([image_name]):
raise SkipTest("Image wasn't supposed to exist, but does: {}"
Expand Down Expand Up @@ -69,7 +70,7 @@ def teardown_class(cls):
WitlessRunner().run(["docker", "rmi", cls.image_name])

@with_tempfile(mkdir=True)
def test_save_and_run(self, path):
def test_save_and_run(self, path=None):
image_dir = op.join(path, "image")
call(["save", self.image_name, image_dir])
ok_exists(op.join(image_dir, "manifest.json"))
Expand All @@ -88,7 +89,7 @@ def test_save_and_run(self, path):
assert_in("image", out["stdout"])

@with_tree({"foo": "content"})
def test_containers_run(self, path):
def test_containers_run(self, path=None):
if self.image_existed:
raise SkipTest(
"Not pulling with containers-run due to existing image: {}"
Expand Down
1 change: 1 addition & 0 deletions datalad_container/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from datalad.conftest import setup_package
29 changes: 15 additions & 14 deletions datalad_container/tests/test_add.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from datalad.api import Dataset
from datalad.api import clone
import pytest
from datalad.api import (
Dataset,
clone,
)
from datalad.consts import DATALAD_SPECIAL_REMOTE
from datalad.customremotes.base import init_datalad_remote
from datalad.tests.utils import assert_false
from datalad.tests.utils import assert_in
from datalad.tests.utils import assert_not_in
from datalad.tests.utils import with_tempfile
from datalad.tests.utils_pytest import (
assert_false,
assert_in,
assert_not_in,
with_tempfile,
)
from datalad.utils import Path

from datalad_container.containers_add import _ensure_datalad_remote
Expand All @@ -15,16 +20,17 @@


@with_tempfile
def test_ensure_datalad_remote_init_and_enable_needed(path):
def test_ensure_datalad_remote_init_and_enable_needed(path=None):
ds = Dataset(path).create(force=True)
repo = ds.repo
assert_false(repo.get_remotes())
_ensure_datalad_remote(repo)
assert_in("datalad", repo.get_remotes())


@pytest.mark.parametrize("autoenable", [False, True])
@with_tempfile
def check_ensure_datalad_remote_maybe_enable(autoenable, path):
def test_ensure_datalad_remote_maybe_enable(path=None, *, autoenable):
path = Path(path)
ds_a = Dataset(path / "a").create(force=True)
init_datalad_remote(ds_a.repo, DATALAD_SPECIAL_REMOTE,
Expand All @@ -35,9 +41,4 @@ def check_ensure_datalad_remote_maybe_enable(autoenable, path):
if not autoenable:
assert_not_in("datalad", repo.get_remotes())
_ensure_datalad_remote(repo)
assert_in("datalad", repo.get_remotes())


def test_ensure_datalad_remote_maybe_enable():
yield check_ensure_datalad_remote_maybe_enable, False
yield check_ensure_datalad_remote_maybe_enable, True
assert_in("datalad", repo.get_remotes())
61 changes: 32 additions & 29 deletions datalad_container/tests/test_containers.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import os.path as op

from datalad.api import Dataset
from datalad.api import install
from datalad.api import containers_add
from datalad.api import containers_remove
from datalad.api import containers_list

from datalad.utils import swallow_outputs
from datalad.tests.utils import SkipTest
from datalad.tests.utils import ok_clean_git
from datalad.tests.utils import with_tree
from datalad.tests.utils import ok_
from datalad.tests.utils import ok_file_has_content
from datalad.tests.utils import assert_equal
from datalad.tests.utils import assert_status
from datalad.tests.utils import assert_raises
from datalad.tests.utils import assert_result_count
from datalad.tests.utils import assert_in
from datalad.tests.utils import assert_in_results
from datalad.tests.utils import assert_not_in
from datalad.tests.utils import assert_re_in
from datalad.tests.utils import with_tempfile
from datalad.tests.utils import serve_path_via_http
from datalad.api import (
Dataset,
containers_add,
containers_list,
containers_remove,
install,
)
from datalad.support.network import get_local_file_url
from datalad.tests.utils_pytest import (
SkipTest,
assert_equal,
assert_in,
assert_in_results,
assert_not_in,
assert_raises,
assert_re_in,
assert_result_count,
assert_status,
ok_,
ok_clean_git,
ok_file_has_content,
serve_path_via_http,
with_tempfile,
with_tree,
)
from datalad.utils import swallow_outputs

from datalad_container.tests.utils import add_pyscript_image


@with_tempfile
def test_add_noop(path):
def test_add_noop(path=None):
ds = Dataset(path).create()
ok_clean_git(ds.path)
assert_raises(TypeError, ds.containers_add)
Expand All @@ -55,7 +58,7 @@ def test_add_noop(path):
@with_tempfile
@with_tree(tree={"foo.img": "doesn't matter 0",
"bar.img": "doesn't matter 1"})
def test_add_local_path(path, local_file):
def test_add_local_path(path=None, local_file=None):
ds = Dataset(path).create()
res = ds.containers_add(name="foobert",
url=op.join(local_file, "foo.img"))
Expand All @@ -82,7 +85,7 @@ def test_add_local_path(path, local_file):
@with_tempfile
@with_tree(tree={'some_container.img': "doesn't matter"})
@serve_path_via_http
def test_container_files(ds_path, local_file, url):
def test_container_files(ds_path=None, local_file=None, url=None):
# setup things to add
#
# Note: Since "adding" as a container doesn't actually call anything or use
Expand Down Expand Up @@ -133,7 +136,7 @@ def test_container_files(ds_path, local_file, url):
@with_tree(tree={'foo.img': "foo",
'bar.img': "bar"})
@serve_path_via_http
def test_container_update(ds_path, local_file, url):
def test_container_update(ds_path=None, local_file=None, url=None):
url_foo = get_local_file_url(op.join(local_file, 'foo.img'))
url_bar = get_local_file_url(op.join(local_file, 'bar.img'))
img = op.join(".datalad", "environments", "foo", "image")
Expand Down Expand Up @@ -177,7 +180,7 @@ def test_container_update(ds_path, local_file, url):
@with_tempfile
@with_tempfile
@with_tree(tree={'some_container.img': "doesn't matter"})
def test_container_from_subdataset(ds_path, src_subds_path, local_file):
def test_container_from_subdataset(ds_path=None, src_subds_path=None, local_file=None):

# prepare a to-be subdataset with a registered container
src_subds = Dataset(src_subds_path).create()
Expand Down Expand Up @@ -214,7 +217,7 @@ def test_container_from_subdataset(ds_path, src_subds_path, local_file):
sub2 = ds.create("sub2")
assert_result_count(ds.subdatasets(), 2, type="dataset")
ds.uninstall("sub2", check=False)
from datalad.tests.utils import assert_false
from datalad.tests.utils_pytest import assert_false
assert_false(sub2.is_installed())

# same results as before, not crashing or somehow confused by a not present
Expand All @@ -241,7 +244,7 @@ def test_container_from_subdataset(ds_path, src_subds_path, local_file):


@with_tempfile
def test_list_contains(path):
def test_list_contains(path=None):
ds = Dataset(path).create()
subds_a = ds.create("a")
subds_b = ds.create("b")
Expand Down
14 changes: 8 additions & 6 deletions datalad_container/tests/test_find.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os.path as op

from datalad.api import Dataset
from datalad.tests.utils import (
ok_clean_git,
from datalad.tests.utils_pytest import (
assert_in,
assert_is_instance,
assert_in_results,
assert_is_instance,
assert_raises,
assert_result_count,
assert_raises
ok_clean_git,
with_tree,
)
from datalad.tests.utils import with_tree

from datalad_container.find_container import find_container


@with_tree(tree={"sub": {"i.img": "doesn't matter"}})
def test_find_containers(path):
def test_find_containers(path=None):
ds = Dataset(path).create(force=True)
ds.save(path=[op.join('sub', 'i.img')], message="dummy container")
ds.containers_add("i", image=op.join('sub', 'i.img'))
Expand Down
2 changes: 1 addition & 1 deletion datalad_container/tests/test_register.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datalad.tests.utils import assert_result_count
from datalad.tests.utils_pytest import assert_result_count


def test_register():
Expand Down
Loading

0 comments on commit ee4f7e4

Please sign in to comment.