nose2.util

nose2.util.call_with_args_if_expected(func, *args)[source]

Take :func: and call it with supplied :args:, in case that signature expects any. Otherwise call the function without any arguments.

nose2.util.ensure_importable(dirname)[source]

Ensure a directory is on sys.path.

nose2.util.exc_info_to_string(err, test)[source]

Format exception info for output

nose2.util.format_traceback(test, err)[source]

Converts a sys.exc_info() -style tuple of values into a string.

nose2.util.has_module_fixtures(test)[source]

Does this test live in a module with module fixtures?

nose2.util.ispackage(path)[source]

Is this path a package directory?

nose2.util.ln(label, char='-', width=70)[source]

Draw a divider, with label in the middle.

>>> ln('hello there')
'---------------------------- hello there -----------------------------'

width and divider char may be specified. Defaults are 70 and '-', respectively.

nose2.util.module_from_name(name)[source]

Import module from name

nose2.util.name_from_args(name, index, args)[source]

Create test name from test args

nose2.util.name_from_path(path)[source]

Translate path into module name

Returns a two-element tuple:

  1. a dotted module name that can be used in an import statement (e.g., pkg1.test.test_things)

  2. a full path to filesystem directory, which must be on sys.path for the import to succeed.

nose2.util.num_expected_args(func)[source]

Return the number of arguments that :func: expects

nose2.util.object_from_name(name, module=None)[source]

Given a dotted name, return the corresponding object.

Getting the object can fail for two reason:

  • the object is a module that cannot be imported.

  • the object is a class or a function that does not exists.

Since we cannot distinguish between these two cases, we assume we are in the first one. We expect the stacktrace is explicit enough for the user to understand the error.

nose2.util.parse_log_level(lvl)[source]

Return numeric log level given a string

nose2.util.safe_decode(string)[source]

Safely decode a byte string into unicode

nose2.util.test_from_name(name, module)[source]

Import test from name

nose2.util.transplant_class(cls, module)[source]

Make cls appear to reside in module.

Parameters:
  • cls – A class

  • module – A module name

Returns:

A subclass of cls that appears to have been defined in module.

The returned class’s __name__ will be equal to cls.__name__, and its __module__ equal to module.

nose2.util.try_import_module_from_name(splitted_name)[source]

Try to find the longest importable from the splitted_name, and return the corresponding module, as well as the potential ImportError exception that occurs when trying to import a longer name.

For instance, if splitted_name is [‘a’, ‘b’, ‘c’] but only a.b is importable, this function:

  1. tries to import a.b.c and fails

  2. tries to import a.b and succeeds

  3. return a.b and the exception that occurred at step 1.

nose2.util.valid_module_name(path)[source]

Is path a valid module name?