Miscellaneous utilities to assist with testing

class datalad.tests.utils.File(name, executable=False)[source]

Bases: object

Helper for a file entry in the create_tree/@with_tree

It allows to define additional settings for entries

class datalad.tests.utils.SilentHTTPHandler(*args, **kwargs)[source]

Bases: SimpleHTTPServer.SimpleHTTPRequestHandler

A little adapter to silence the handler

log_message(format, *args)[source]
datalad.tests.utils.assert_dict_equal(d1, d2)[source]
datalad.tests.utils.assert_in_results(results, **kwargs)[source]

Verify that the particular combination of keys and values is found in one of the results

datalad.tests.utils.assert_message(message, results)[source]

Verify that each status dict in the results has a message

This only tests the message template string, and not a formatted message with args expanded.

datalad.tests.utils.assert_no_errors_logged(func, skip_re=None)[source]

Decorator around function to assert that no errors logged during its execution

datalad.tests.utils.assert_not_in_results(results, **kwargs)[source]

Verify that the particular combination of keys and values is not in any of the results

datalad.tests.utils.assert_re_in(regex, c, flags=0, match=True, msg=None)[source]

Assert that container (list, str, etc) contains entry matching the regex

datalad.tests.utils.assert_result_count(results, n, **kwargs)[source]

Verify specific number of results (matching criteria, if any)

datalad.tests.utils.assert_result_values_cond(results, prop, cond)[source]

Verify that the values of all results for a given key in the status dicts fullfill condition cond.

  • results
  • prop (str) –
  • cond (callable) –
datalad.tests.utils.assert_result_values_equal(results, prop, values)[source]

Verify that the values of all results for a given key in the status dicts match the given sequence

datalad.tests.utils.assert_status(label, results)[source]

Verify that each status dict in the results has a given status label

label can be a sequence, in which case status must be one of the items in this sequence.

datalad.tests.utils.create_tree(path, tree, archives_leading_dir=True)[source]

Given a list of tuples (name, load) create such a tree

if load is a tuple itself – that would create either a subtree or an archive with that content and place it into the tree if name ends with .tar.gz

datalad.tests.utils.create_tree_archive(path, name, load, overwrite=False, archives_leading_dir=True)[source]

Given an archive name, create under path with specified load tree

datalad.tests.utils.dump_graph(graph, flatten=False)[source]

Delayed parsing so it could be monkey patched etc

datalad.tests.utils.get_most_obscure_supported_name(*arg, **kw)[source]

Return the most obscure filename that the filesystem would support under TEMPDIR

TODO: we might want to use it as a function where we would provide tdir


Return digests (md5) and mtimes for all the files under target_path


Decorator workaround for nose’s behaviour with redirecting sys.stdout

Needed for tests involving the runner and nose redirecting stdout. Counter-intuitively, that means it needed for nosetests without ‘-s’. See issue reported here:


Mark test as an “integration” test which generally is not needed to be run

Generally tend to be slower


Test decorator marking a test as known to fail

This combines probe_known_failure and skip_known_failure giving the skipping precedence over the probing.


Test decorator marking a test as known to fail in a direct mode test run

If is set to True behaves like known_failure. Otherwise the original (undecorated) function is returned.


Test decorator marking a test as known to fail in a v6 test run

If datalad.repo.version is set to 6 behaves like known_failure. Otherwise the original (undecorated) function is returned.

datalad.tests.utils.nok_startswith(s, prefix)[source]
datalad.tests.utils.ok_annex_get(ar, files, network=True)[source]

Helper to run .get decorated checking for correct operation

get passes through stderr from the ar to the user, which pollutes screen while running tests

Note: Currently not true anymore, since usage of –json disables progressbars

datalad.tests.utils.ok_archives_caches(repopath, n=1, persistent=None)[source]

Given a path to repository verify number of archives

  • repopath (str) – Path to the repository
  • n (int, optional) – Number of archives directories to expect
  • persistent (bool or None, optional) – If None – both persistent and not count.
datalad.tests.utils.ok_clean_git(path, annex=None, head_modified=[], index_modified=[], untracked=[], ignore_submodules=False)[source]

Verify that under given path there is a clean git repository

it exists, .git exists, nothing is uncommitted/dirty/staged


Parameters head_modified and index_modified currently work in pure git or indirect mode annex only and are ignored otherwise! Implementation is yet to do!

  • path (str or Repo) – in case of a str: path to the repository’s base dir; Note, that passing a Repo instance prevents detecting annex. This might be useful in case of a non-initialized annex, a GitRepo is pointing to.
  • annex (bool or None) – explicitly set to True or False to indicate, that an annex is (not) expected; set to None to autodetect, whether there is an annex. Default: None.
  • ignore_submodules (bool) – if True, submodules are not inspected
datalad.tests.utils.ok_endswith(s, suffix)[source]
datalad.tests.utils.ok_file_has_content(path, content, strip=False, re_=False, **kwargs)[source]

Verify that file exists and has expected content

datalad.tests.utils.ok_file_under_git(path, filename=None, annexed=False)[source]

Test if file is present and under git/annex control

If relative path provided, then test from current directory


Helper to verify that nothing rewritten the config file

datalad.tests.utils.ok_startswith(s, prefix)[source]

Checks whether path is either a working or broken symlink


Test decorator allowing the test to pass when it fails and vice versa

Setting config datalad.tests.knownfailures.probe to True tests, whether or not the test is still failing. If it’s not, an AssertionError is raised in order to indicate that the reason for failure seems to be gone.

datalad.tests.utils.put_file_under_git(path, filename=None, content=None, annexed=False)[source]

Place file under git/annex and return used Repo


Skips tests if datalad is configured to use direct mode (set DATALAD_REPO_DIRECT)


As discovered some httpretty bug causes a side-effect on other tests on some Pythons. So we skip the test if such problematic combination detected



Skip test completely in NONETWORK settings

If not used as a decorator, and just a function, could be used at the module level


Skip test completely under Windows


A little helper to skip some tests which require recent scrapy

datalad.tests.utils.skip_if_url_is_not_available(url, regex=None)[source]

Test decorator allowing to skip a test that is known to fail

Setting config datalad.tests.knownfailures.skip to a bool enables/disables skipping.


Skips SSH tests if on windows or if environment variable DATALAD_TESTS_SSH was not set


Skips tests if datalad is configured to use v6 mode (DATALAD_REPO_VERSION=6)


Mark test as a slow, although not necessarily integration or usecase test


Mark test as a usecase user ran into and which (typically) caused bug report to be filed/troubleshooted