Skip to content

toolr.testing

Utilities for testing ToolR and supported commands.

CommandsTester

Helper class to simplify testing command discovery.

collected_command_groups

collected_command_groups() -> dict[str, CommandGroup]

Get the collected command groups.

Source code in python/toolr/testing.py
def collected_command_groups(self) -> dict[str, CommandGroup]:
    """
    Get the collected command groups.
    """
    return {**self.command_group_collector}

__enter__

__enter__() -> Self

Enter the context manager.

Source code in python/toolr/testing.py
def __enter__(self) -> Self:
    """
    Enter the context manager.
    """
    sys.modules.clear()
    sys.modules.update(self.sys_modules)
    os.chdir(self.search_path)
    if self.skip_loading_entry_points:
        self.entry_points_patcher.start()
    self.command_group_patcher.start()
    sys.path.insert(0, str(self.search_path))
    return self

__exit__

__exit__(*args: object) -> None

Exit the context manager.

Source code in python/toolr/testing.py
def __exit__(self, *args: object) -> None:
    """
    Exit the context manager.
    """
    os.chdir(self.cwd)
    self.command_group_patcher.stop()
    if self.skip_loading_entry_points:
        self.entry_points_patcher.stop()
    self.command_group_collector.clear()
    sys.path[:] = self.sys_path