Testing Module
Helpers for unit tests
- author:
Doug Skrypa
- class cli_command_parser.testing.AssertRaisesWithStringContext(test_case: TestCase, expected_exc: Type[BaseException], text: OptStr = None, msg: OptStr = None)[source]
Bases:
object
Simplified version of the stdlib
_AssertRaisesContext
that tests whether the raised exception’s string contains the given text rather than matching it against a regex pattern. This avoids the regex overhead when it isn’t necessary, which is the majority of the time for such checks in this project.- test_case
- expected_exc
- expected_text
- msg
- class cli_command_parser.testing.ParserTest(methodName='runTest')[source]
Bases:
TestCase
- assert_raises_contains_str(expected_exc: Type[BaseException], expected_text: str, msg: str = None)[source]
- assert_parse_results(cmd_cls: CommandCls, argv: Argv, expected: Expected, msg: str = None) Command [source]
- assert_env_parse_results(cmd_cls: CommandCls, argv: Argv, env: Env, expected: Expected, msg: str = None) Command [source]
- assert_env_parse_results_cases(cmd_cls: CommandCls, cases: Iterable[EnvCase], msg: str = None)[source]
- assert_parse_fails(cmd_cls: CommandCls, argv: Argv, expected_exc: ExcType = <class 'cli_command_parser.exceptions.UsageError'>, expected_pattern: str = None, msg: str = None, regex: bool = False)[source]
- assert_parse_fails_cases(cmd_cls: CommandCls, cases: ExcCases, exc: ExcType = None, msg: str = None)[source]
- assert_argv_parse_fails_cases(cmd_cls: CommandCls, cases: Iterable[Argv], exc: ExcType = <class 'cli_command_parser.exceptions.UsageError'>, msg: str = None)[source]
Convenience method for calling
assert_parse_fails_cases()
with a default exception type.
- assert_call_fails(func: ~typing.Callable, kwargs: ~typing.Dict[str, ~typing.Any], exc: ~typing.Type[Exception] = <class 'Exception'>, expected_exc_msg: str = None, msg: str = None)[source]
- assert_call_fails_cases(func: Callable, cases: Iterable[Tuple[Dict[str, Any], Type[Exception]] | Tuple[Dict[str, Any], Type[Exception], str]], msg: str = None)[source]
- cli_command_parser.testing.format_diff(a: str, b: str, name_a: str = 'expected', name_b: str = ' actual', n: int = 3) str [source]
- class cli_command_parser.testing.RedirectStreams(stdin: IO | str | bytes | None = None)[source]
Bases:
AbstractContextManager
- cli_command_parser.testing.get_help_text(cmd: Type[Command] | Command, terminal_width: int = 199) str [source]
- cli_command_parser.testing.load_command(directory: Path, name: str, cmd_name: str, **kwargs) ContextManager[CommandCls] [source]
- class cli_command_parser.testing.TemporaryDir(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False, *, delete=True)[source]
Bases:
TemporaryDirectory