Miscellaneous utilities to assist with testing

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

Bases: http.server.SimpleHTTPRequestHandler

A little adapter to silence the handler

log_message(format, *args)[source]

Log an arbitrary message.

This is used by all other logging functions. Override it if you have specific logging wishes.

The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).

The client ip and current date/time are prefixed to every message.

reproman.tests.utils.assert_cwd_unchanged(func, ok_to_chdir=False)[source]

Decorator to test whether the current working directory remains unchanged

Parameters:ok_to_chdir (bool, optional) – If True, allow to chdir, so this decorator would not then raise exception if chdir’ed but only return to original directory
reproman.tests.utils.assert_equal(a, b, msg=None)[source]
reproman.tests.utils.assert_false(x, msg=None)[source]
reproman.tests.utils.assert_greater(a, b, msg=None)[source]
reproman.tests.utils.assert_greater_equal(a, b, msg=None)[source]
reproman.tests.utils.assert_in(x, collection, msg=None)[source]
reproman.tests.utils.assert_in_in(substr, lst)[source]

Verify that a substring is in an element of a list

reproman.tests.utils.assert_is(a, b, msg=None)[source]
reproman.tests.utils.assert_is_instance(a, b, msg=None)[source]
reproman.tests.utils.assert_is_subset_recur(a, b, subset_types=[])[source]

Asserts that ‘a’ is a subset of ‘b’ (recursive on dicts and lists)

  • a (dict or list) – The desired subset collection (items that must be in b)
  • b (dict or list) – The superset collection
  • subset_types (list) – List of classes (from list, dict) that allow subsets. Otherwise we use strict matching.
reproman.tests.utils.assert_not_equal(a, b, msg=None)[source]
reproman.tests.utils.assert_not_in(x, collection, msg=None)[source]
reproman.tests.utils.assert_re_in(regex, c, flags=0)[source]

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

reproman.tests.utils.assert_true(x, msg=None)[source]

Create a skeleton Python module in directory.

Parameters:directory (str) – Path to a non-existing directory.
reproman.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

reproman.tests.utils.eq_(a, b, msg=None)

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

reproman.tests.utils.in_(x, collection, msg=None)
reproman.tests.utils.neq_(a, b, msg=None)
reproman.tests.utils.nok_(x, msg=None)
reproman.tests.utils.nok_startswith(s, prefix)[source]
reproman.tests.utils.ok_(x, msg=None)
reproman.tests.utils.ok_endswith(s, suffix)[source]
reproman.tests.utils.ok_file_has_content(path, content)[source]

Verify that file exists and has expected content

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

Checks whether path is either a working or broken symlink

reproman.tests.utils.run_under_dir(func, newdir='.')[source]

Decorator to run tests under another directory

It is somewhat ugly since we can’t really chdir back to a directory which had a symlink in its path. So using this decorator has potential to move entire testing run under the dereferenced directory name – sideeffect.

The only way would be to instruct testing framework (i.e. nose in our case ATM) to run a test by creating a new process with a new cwd

reproman.tests.utils.serve_path_via_http(tfunc, *targs)[source]

Decorator which serves content of a directory via http url

reproman.tests.utils.with_tempfile(t, **tkwargs)[source]

Decorator function to provide a temporary file name and remove it at the end

  • change the used directory without providing keyword argument 'dir' set (To) –
  • mkdir (bool, optional (default: False)) – If True, temporary directory created using tempfile.mkdtemp()
  • content (str or bytes, optional) – Content to be stored in the file created
  • wrapped (function, optional) – If set, function name used to prefix temporary file name
  • **tkwargs – All other arguments are passed into the call to{,d}temp(), and resultant temporary filename is passed as the first argument into the function t. If no ‘prefix’ argument is provided, it will be constructed using module and function names (‘.’ replaced with ‘_’).


def test_write(tfile):
    open(tfile, 'w').write('silly test')
reproman.tests.utils.with_testsui(t, responses=None)[source]

Switch main UI to be ‘tests’ UI and possibly provide answers to be used

reproman.tests.utils.with_tree(t, tree=None, archives_leading_dir=True, delete=True, **tkwargs)[source]

Decorator to remove http*_proxy env variables for the duration of the test