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.format_traceback(test, err)[source]
Converts a
sys.exc_info()-style tuple of values into a string.
- nose2.util.ln(label, char='-', width=70)[source]
Draw a divider, with
labelin the middle.>>> ln('hello there') '---------------------------- hello there -----------------------------'
widthand dividercharmay be specified. Defaults are70and'-', respectively.
- nose2.util.name_from_path(path)[source]
Translate
pathinto module nameReturns a two-element tuple:
a dotted module name that can be used in an import statement (e.g.,
pkg1.test.test_things)a full path to filesystem directory, which must be on
sys.pathfor the import to succeed.
- 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.transplant_class(cls, module)[source]
Make
clsappear to reside inmodule.- Parameters:
cls – A class
module – A module name
- Returns:
A subclass of
clsthat appears to have been defined inmodule.
The returned class’s
__name__will be equal tocls.__name__, and its__module__equal tomodule.
- 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 potentialImportErrorexception that occurs when trying to import a longer name.For instance, if
splitted_nameis [‘a’, ‘b’, ‘c’] but onlya.bis importable, this function:tries to import
a.b.cand failstries to import
a.band succeedsreturn
a.band the exception that occurred at step 1.