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_is_generator(gen)
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.

Parameters: 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.clone_url(url)[source]
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]
datalad.tests.utils.get_datasets_topdir()[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

datalad.tests.utils.get_mtimes_and_digests(target_path)[source]

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

datalad.tests.utils.ignore_nose_capturing_stdout(func)[source]

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: https://code.google.com/p/python-nose/issues/detail?id=243&can=1&sort=-id&colspec=ID%20Type%20Status%20Priority%20Stars%20Milestone%20Owner%20Summary

datalad.tests.utils.integration(f)[source]

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

Generally tend to be slower

datalad.tests.utils.known_failure(func)[source]

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.

datalad.tests.utils.known_failure_direct_mode(func)[source]

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

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

datalad.tests.utils.known_failure_v6(func)[source]

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

Parameters: 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

Note

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!

Parameters: 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_exists(path)[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

datalad.tests.utils.ok_generator(gen)[source]
datalad.tests.utils.ok_git_config_not_empty(ar)[source]

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

datalad.tests.utils.probe_known_failure(func)[source]

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

datalad.tests.utils.skip_direct_mode(func)[source]

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

datalad.tests.utils.skip_httpretty_on_problematic_pythons(func)[source]

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

datalad.tests.utils.skip_if_no_module(module)[source]
datalad.tests.utils.skip_if_no_network(func=None)[source]

Skip test completely in NONETWORK settings

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

datalad.tests.utils.skip_if_on_windows(func)[source]

Skip test completely under Windows

datalad.tests.utils.skip_if_scrapy_without_selector()[source]

A little helper to skip some tests which require recent scrapy

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

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

datalad.tests.utils.skip_ssh(func)[source]

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

datalad.tests.utils.skip_v6(func)[source]

datalad.tests.utils.slow(f)[source]
datalad.tests.utils.usecase(f)[source]