def test_discover_function_only(): # Alphabetical order regardless of order in the module. assert discover(discover_demo_module, match_func=inspect.isfunction) == [ discover_demo_module.foo_in_init, discover_demo_module.submodule_a.bar, discover_demo_module.submodule_a.foo, ]
def import_commands(source: Optional[ModuleType] = None, entry_point: Optional[str] = None) -> List[click.Command]: """ Returns a list of all commands. Commands can be defined locally in the module given in ``source``, or by third party extensions who define an entry point in the following format: :: <name (can be anything)> = <module name>:<command> :param source: :param entry_point: """ all_commands = [] if source is not None: all_commands.extend( discover(source, is_command, exclude_side_effects=False)) if entry_point is not None: all_commands.extend(discover_entry_points(entry_point, is_command)) return all_commands
def test_discover(): # Alphabetical order regardless of order in the module. assert discover(discover_demo_module) == [ discover_demo_module.foo_in_init, discover_demo_module.submodule_a.bar, discover_demo_module.submodule_a.foo, discover_demo_module.submodule_b.Alice, discover_demo_module.submodule_b.Bob, ]
def import_registered_functions() -> List[Type]: """ Returns a list of all registered functions. """ local_functions = discover(repo_helper.files, is_registered) third_party_commands = discover_entry_points("repo_helper.command", is_registered) return [*local_functions, *third_party_commands]
# 3rd party from domdf_python_tools.import_tools import discover # this package import repo_helper_bot.hooks discover(repo_helper_bot) # this package from repo_helper_bot.constants import app, github_app
def test_discover_hasattr(): def match_func(obj): return hasattr(obj, "foo") assert discover(discover_demo_module, match_func=match_func) == []
def test_discover_class_only(): # Alphabetical order regardless of order in the module. assert discover(discover_demo_module, match_func=inspect.isclass) == [ discover_demo_module.submodule_b.Alice, discover_demo_module.submodule_b.Bob, ]
def test_discover_errors(obj, expects): with expects: discover(obj)