unit_run.utils#

Module Contents#

Classes#

PathType

Functions#

inspect_by_path

Inspect a module and return a list of objects that passed a test by the filter funciton.

inspect_callables_by_path

Inspect a file and return a list of callables. This is a wrapper around inspect_by_path with the exception that we don’t want to inspect classes or functions that are in _tmp_module.

get_info_dict_from_callable

Get information about a callable. This is used to generate a JSON - serializable dictionary that can be serialized to JSON.

inspect_callable_infos_by_path

Inspects callable infos by path. This is a wrapper around inspect_callables_by_path that returns a list of dictionaries.

find_callable_by_name

Find callable by name. This is a wrapper around inspect_callables_by_path to search for callable with given name.

load_json

Load a JSON file from the given path.

save_as_json

Saves a python object as JSON. This is a convenience function for creating a file in the same directory as the json_path

auto_type_check

Decorator to check type of parameters. This decorator is used to check the type of parameters passed to a function by inspecting the function signature.

_test

This is a test function. It should be used in a unit test as the first argument to the function

API#

unit_run.utils.inspect_by_path(path: str, filter_func=None, with_name=False)[source]#

Inspect a module and return a list of objects that passed a test by the filter funciton.

Parameters:
  • path – The path to inspect.

  • filter_func – A function that takes a module member as parameter and returns whether one member should be included in the results.

  • with_name – If True the name of the object will be included in the result.

Returns:

A list of ( name object ) tuples. If no path is given an empty list is returned. >>> from machinery

unit_run.utils.inspect_callables_by_path(path)[source]#

Inspect a file and return a list of callables. This is a wrapper around inspect_by_path with the exception that we don’t want to inspect classes or functions that are in _tmp_module.

Parameters:

path – Path to the file to inspect. Can be a file or a directory.

Returns:

A list of inspect. Classes or inspect. Function objects in the file at the given path. If there are no calls to the file it returns an empty list

unit_run.utils.get_info_dict_from_callable(c)[source]#

Get information about a callable. This is used to generate a JSON - serializable dictionary that can be serialized to JSON.

Parameters:

c – The callable to get information about. Must be a callable

Returns:

A dictionary containing information about the

unit_run.utils.inspect_callable_infos_by_path(path)[source]#

Inspects callable infos by path. This is a wrapper around inspect_callables_by_path that returns a list of dictionaries.

Parameters:

path – Path to inspect callable infos. Can be a file path or a string containing globs.

Returns:

A list of dictionaries one for each callable that has been inspected. Each dictionary is a dictionary with keys corresponding to the callable’s name and values corresponding to the information returned by get_info_dict_from_callable

unit_run.utils.find_callable_by_name(path, name)[source]#

Find callable by name. This is a wrapper around inspect_callables_by_path to search for callable with given name.

Parameters:
  • path – Path to the callable in Celery.

  • name – Name of callable to find. It must be a string.

Returns:

Callable if found None otherwise. >>> from sympy. utilities. iterables import find_callable_by_name Traceback ( most recent call last ) : TypeError : name is

unit_run.utils.load_json(json_path)[source]#

Load a JSON file from the given path.

Parameters:

json_path – Path to the JSON file. Must be a string.

Returns:

An object of the JSON file that was loaded from the file at json_path. See : func : json. load for details

unit_run.utils.save_as_json(json_path, obj, indent=2)[source]#

Saves a python object as JSON. This is a convenience function for creating a file in the same directory as the json_path

Parameters:
  • json_path – Path to the JSON file

  • obj – Object to be saved as JSON. It can be any python object

  • indent – Number of spaces to indent JSON output default is

class unit_run.utils.PathType[source]#

Bases: enum.Enum

FILE#

1

DIRECTORY#

2

BOTH#

3

unit_run.utils.auto_type_check(func)[source]#

Decorator to check type of parameters. This decorator is used to check the type of parameters passed to a function by inspecting the function signature.

Parameters:

func – function to be wrapped. It must have at least one parameter

Returns:

wrapped function with type

unit_run.utils._test(a)[source]#

This is a test function. It should be used in a unit test as the first argument to the function

Parameters:

a – The object to test