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
label
in the middle.>>> ln('hello there') '---------------------------- hello there -----------------------------'
width
and dividerchar
may be specified. Defaults are70
and'-'
, respectively.
- nose2.util.name_from_path(path)[source]
Translate
path
into 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.path
for 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
cls
appear to reside inmodule
.- Parameters
cls – A class
module – A module name
- Returns
A subclass of
cls
that 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 potentialImportError
exception that occurs when trying to import a longer name.For instance, if
splitted_name
is [‘a’, ‘b’, ‘c’] but onlya.b
is importable, this function:tries to import
a.b.c
and failstries to import
a.b
and succeedsreturn
a.b
and the exception that occurred at step 1.