Skip to content

Commit

Permalink
Merge pull request #330 from yarikoptic/enh-silent-tests
Browse files Browse the repository at this point in the history
WiP: a pass over tests to make them not spit out error msgs and possibly fasten them up
  • Loading branch information
yarikoptic committed Jan 2, 2016
2 parents a1f8db9 + 586d853 commit 2f53949
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
6 changes: 5 additions & 1 deletion datalad/interface/publish_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__docformat__ = 'restructuredtext'


from os import curdir, environ, geteuid, urandom
from os import curdir, environ, urandom
from os.path import exists, join as opj, abspath, expandvars, expanduser, isdir, basename
from .base import Interface
from ..support.param import Parameter
Expand All @@ -30,6 +30,8 @@
from datalad.cmdline.helpers import get_datalad_master
from six.moves.urllib.parse import urlparse

from ..utils import not_supported_on_windows


def parse_script_output(out, err):
"""parse out put of server setup script"""
Expand Down Expand Up @@ -146,6 +148,8 @@ def __call__(self, target, collection=curdir, baseurl=None,

# build control master:
from datalad.utils import assure_dir
not_supported_on_windows("TODO")
from os import geteuid # Linux specific import
var_run_user_datalad = "/var/run/user/%s/datalad" % geteuid()
assure_dir(var_run_user_datalad)
control_path = "%s/%s" % (var_run_user_datalad, host_name)
Expand Down
10 changes: 6 additions & 4 deletions datalad/tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,17 @@ def raise_AttributeError(*args):
os.unlink(tempfile2) # TODO: next two with_tempfile


@with_testrepos('.*annex.*', flavors=local_testrepo_flavors)
@with_tempfile(mkdir=True)
def test_runner_failure(dir_):

from ..support.annexrepo import AnnexRepo
repo = AnnexRepo(dir_, create=True)
runner = Runner()
failing_cmd = ['git-annex', 'add', 'notexistent.dat']
assert_raises(CommandError, runner.run, failing_cmd, cwd=dir_)

try:
runner.run(failing_cmd, cwd=dir_)
with swallow_logs():
runner.run(failing_cmd, cwd=dir_)
raise AssertionError("must not reach here -- should have thrown an exception")
except CommandError as e:
assert_equal(1, e.code)
assert_in('notexistent.dat not found', e.stderr)
10 changes: 6 additions & 4 deletions datalad/tests/test_collectionrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
on_windows, get_most_obscure_supported_name, ok_clean_git, ok_, eq_, \
ok_startswith
from ..utils import get_local_file_url
from ..utils import swallow_logs

# For now (at least) we would need to clone from the network
# since there are troubles with submodules on Windows.
Expand Down Expand Up @@ -79,10 +80,11 @@ def test_CollectionRepo_constructor(clean_path, clean_path2, clean_path3):
"Missing RDFS.label.")

# now, test Exceptions:
assert_raises(NoSuchPathError, CollectionRepo, clean_path3, create=False)
os.mkdir(clean_path3)
assert_raises(InvalidGitRepositoryError, CollectionRepo, clean_path3,
create=False)
with swallow_logs():
assert_raises(NoSuchPathError, CollectionRepo, clean_path3, create=False)
os.mkdir(clean_path3)
assert_raises(InvalidGitRepositoryError, CollectionRepo, clean_path3,
create=False)
gr = GitRepo(clean_path3)
ok_(os.path.exists(opj(clean_path3, '.git')))
assert_raises(CollectionBrokenError, CollectionRepo, clean_path3,
Expand Down
14 changes: 13 additions & 1 deletion datalad/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from ..utils import getpwd, chpwd
from ..utils import auto_repr
from ..utils import find_files
from ..utils import not_supported_on_windows
from ..support.annexrepo import AnnexRepo

from nose.tools import ok_, eq_, assert_false, assert_raises, assert_equal
Expand All @@ -37,6 +38,7 @@
from .utils import assure_dict_from_str, assure_list_from_str
from .utils import ok_generator
from .utils import assert_not_in
from .utils import assert_raises
from .utils import ok_startswith


Expand Down Expand Up @@ -309,4 +311,14 @@ def test_find_files_exclude_vcs(repo):
ff = find_files('.*', repo, dirs=True, exclude_vcs=False)
files = list(ff)
assert_equal({basename(f) for f in files}, {'d1', 'git', '.git', '1'})
assert_in(opj(repo, '.git'), files)
assert_in(opj(repo, '.git'), files)


def test_not_supported_on_windows():
with patch('datalad.utils.on_windows', True):
assert_raises(NotImplementedError, not_supported_on_windows)
assert_raises(NotImplementedError, not_supported_on_windows, "msg")

with patch('datalad.utils.on_windows', False):
assert_equal(not_supported_on_windows(), None)
assert_equal(not_supported_on_windows("msg"), None)
9 changes: 9 additions & 0 deletions datalad/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
# Little helpers
#

def not_supported_on_windows(msg=None):
"""A little helper to be invoked to consistently fail whenever functionality is
not supported (yet) on Windows
"""
if on_windows:
raise NotImplementedError("This functionality is not yet implemented for Windows OS"
+ (": %s" % msg if msg else ""))


def shortened_repr(value, l=30):
try:
if hasattr(value, '__repr__') and (value.__repr__ is not object.__repr__):
Expand Down

0 comments on commit 2f53949

Please sign in to comment.