tests.test_test_suite module

Tests for the declarative CLI test-suite engine and its test-suite command.

Covers three surfaces:

The host Python interpreter stands in for the command under test, so cases stay fast and platform-neutral.

tests.test_test_suite.test_parse_returns_cases()[source]

A well-formed YAML suite yields one CLITestCase per entry.

tests.test_test_suite.test_parse_returns_cases_per_format(suite_string, fmt)[source]

TOML (cases under [[cases]]) and JSON (bare array) yield the same cases.

tests.test_test_suite.test_parse_toml_requires_cases_key()[source]

A TOML mapping without a top-level ‘cases’ array of tables is rejected.

tests.test_test_suite.test_parse_rejects_non_suite_format()[source]

A format that cannot represent a list of cases is rejected.

tests.test_test_suite.test_parse_rejects_malformed(suite, exception)[source]

Empty, mapping-without-cases, and unknown-directive suites raise.

tests.test_test_suite.test_load_detects_format_from_extension(tmp_path, filename, content)[source]

The file extension selects the parser, so each format yields the case.

tests.test_test_suite.test_load_rejects_unknown_extension(tmp_path)[source]

An extension matching no suite format is rejected.

tests.test_test_suite.test_cases_from_data_builds_cases()[source]

A list of directive mappings becomes CLITestCase instances.

tests.test_test_suite.test_cases_from_data_rejects_invalid_directive(directive)[source]

An unknown directive is rejected, and so is the trace the runner fills.

tests.test_test_suite.test_case_execution_trace_stays_out_of_comparisons()[source]

A case that ran still compares equal to the same case, unrun.

tests.test_test_suite.test_split_args_honors_quotes(cli, expected)[source]

Quoting survives tokenization identically on POSIX and Windows.

shlex and CommandLineToArgvW are two different parsers, so the cases above are the subset of syntax on which they must agree.

Two corners stay out on purpose, because the parsers answer differently and each answer is right for its platform: a backslash escapes the next character for shlex but stands for itself on Windows (which is what keeps C:\Users intact), and a doubled quote inside a quoted run closes and reopens it for shlex while Windows folds it into one literal quote.

tests.test_test_suite.test_case_normalizes_scalars()[source]

String scalars are coerced: exit_code to int, cli_parameters to a tuple.

tests.test_test_suite.test_case_normalizes_timeout(value, expected)[source]

A timeout given as int, float, or numeric string becomes a float.

Plain integers are what every config format produces for a bare number, so they must be accepted (a timeout: 5 in any suite).

tests.test_test_suite.test_case_rejects_non_numeric_timeout(value)[source]

A boolean or non-scalar timeout is rejected as not-a-float.

tests.test_test_suite.test_case_accepts_compiled_regexes()[source]

A regex directive takes a compiled pattern as well as a string.

The field hints admit both: a compiled pattern is kept as is, a string is compiled with dots matching newlines, and the two mix in one directive.

tests.test_test_suite.test_case_survives_dataclass_replace()[source]

dataclasses.replace runs the normalization again over normalized values.

Every field family has to accept its own output for that: compiled regexes, resolved platform sets and split parameters all round-trip unchanged, and only the replaced field moves.

tests.test_test_suite.test_output_contains_sees_merged_stream()[source]

output_contains matches substrings from both stdout and stderr.

tests.test_test_suite.test_output_regex_preserves_cross_stream_order()[source]

output_regex_matches sees stdout and stderr interleaved in write order.

tests.test_test_suite.test_output_directive_mismatch_fails()[source]

A substring absent from the merged stream fails the case.

tests.test_test_suite.test_only_platforms_runs_on_member_platform()[source]

A case restricted to the current platform’s own id is not skipped.

tests.test_test_suite.test_only_platforms_skip_names_required_platforms(monkeypatch)[source]

The skip message names the case’s required platforms, not the current one.

Naming the current one would read “only runs on platform: macOS” for a case skipped on macOS.

tests.test_test_suite.test_non_utf8_output_does_not_crash_the_harness()[source]

Bytes that are not valid UTF-8 are escaped, not a reader-thread crash.

A binary emitting its platform’s legacy encoding (cp1252 on Windows) would otherwise kill the capture with a UnicodeDecodeError, failing the case with no hint of the cause. The escaped bytes flow into the captured stream, where assertions can see them.

tests.test_test_suite.test_child_inherits_utf8_io_encoding()[source]

The subprocess emits UTF-8 regardless of the platform’s default.

PYTHONIOENCODING is injected into the child environment so CPython-based binaries write UTF-8 on piped stdout, where Windows would pick cp1252 and desynchronize from the harness’s UTF-8 decoding.

tests.test_test_suite.test_output_and_stream_directives_are_mutually_exclusive()[source]

Combining output_* with stdout_*/stderr_* is rejected at construction.

tests.test_test_suite.ECHO_ENV = ('-c', "import os; print(os.environ.get('PROBE_VAR', '<absent>'))")

Command line printing one variable, or a marker when it is not set.

tests.test_test_suite.test_env_sets_a_variable_on_the_child()[source]

A variable a case declares reaches the command it runs.

tests.test_test_suite.test_unset_env_hides_an_inherited_variable(monkeypatch)[source]

A variable exported around the suite can be taken away for one case.

The half env cannot cover: assigning the empty string leaves the variable set, which a flag read by bare presence counts as activation.

tests.test_test_suite.test_env_directives_leave_the_runner_environment_alone(monkeypatch)[source]

Cases stay independent under --jobs: only the child is touched.

tests.test_test_suite.test_env_overrides_the_injected_io_encoding_default()[source]

A case pinning PYTHONIOENCODING wins over the harness’s own default.

The harness injects utf8 so a child’s piped stdout stays decodable (see test_child_inherits_utf8_io_encoding); a case declaring the variable itself must land after that. cp1252 is picked over latin-1 because Python reports the latter back under its iso8859-1 alias.

tests.test_test_suite.test_env_rejects_what_is_not_a_string_mapping(value, exception, match)[source]

An environment holds strings only, so anything else is refused loudly.

tests.test_test_suite.test_unset_env_normalizes_like_the_envvar_helpers()[source]

A single name is wrapped, duplicates collapse, blanks are dropped.

tests.test_test_suite.LIST_CWD = ('-c', "import os; print(sorted(os.listdir('.')))")

Command line printing the names the working directory holds.

tests.test_test_suite.test_work_directory_moves_the_command(tmp_path)[source]

The command runs where asked, not where the runner sits.

tests.test_test_suite.test_work_directory_defaults_to_the_runner_directory(tmp_path)[source]

Left unset, a case sees what it always saw.

tests.test_test_suite.test_work_directory_leaves_the_command_resolution_alone(tmp_path)[source]

The target is resolved before the move, so it is never looked for there.

run_cli_test resolves a PATH name (and .absolute()``s a path) against the runner's own directory first, which is what lets a relative target survive a ``work_directory pointing somewhere that does not hold it.

tests.test_test_suite.test_run_suite_applies_the_work_directory_to_every_case(tmp_path)[source]

The orchestrator hands it down, so a whole suite moves at once.

tests.test_test_suite.test_env_and_unset_env_are_valid_suite_directives()[source]

Both reach a case through a serialized suite, not just the Python API.

tests.test_test_suite.test_run_counts_pass_and_fail(jobs)[source]

Pass/fail tallies match regardless of the worker count.

tests.test_test_suite.test_run_select_test_skips_others()[source]

select_test runs only the chosen 1-based cases; the rest count as skipped.

tests.test_test_suite.test_run_exit_on_error_bails_sequentially()[source]

With one worker, exit_on_error stops before later cases run.

tests.test_test_suite.test_run_stats_echoes_summary(capsys)[source]

stats prints the worker line up front and the result tally at the end.

tests.test_test_suite.test_run_no_stats_is_quiet(capsys)[source]

Without stats, neither the worker line nor the tally is printed.

tests.test_test_suite.test_cli_runs_default_suite(invoke)[source]

With no suite source, the subcommand runs the built-in default suite.

tests.test_test_suite.test_cli_runs_suite_file(invoke, tmp_path)[source]

A –suite-file is parsed and run against the target command.

tests.test_test_suite.test_cli_runs_toml_suite_file(invoke, tmp_path)[source]

A TOML –suite-file runs without the yaml extra, since TOML is built in.

tests.test_test_suite.test_cli_reports_failure_exit_code(invoke, tmp_path)[source]

A failing case makes the subcommand exit non-zero.

tests.test_test_suite.test_cli_rejects_non_integer_jobs(invoke)[source]

–jobs is click-extra’s JobsOption, so a non-numeric value is refused.

tests.test_test_suite.test_cli_skip_platform_knows_every_platform_id(invoke)[source]

–skip-platform takes any extra_platforms ID and refuses anything else.

The IDs are loaded when the option is first parsed, so importing the CLI does not load the platform detection, and the check still happens.

tests.test_test_suite.test_cli_requires_command(invoke)[source]

Without –command/–binary, the subcommand errors with a usage message.

tests.test_test_suite.test_cli_resolves_suite_from_config(invoke, tmp_path, monkeypatch)[source]

With no –suite-file, the suite comes from [tool.click-extra.test-suite].

tests.test_test_suite.test_cli_resolves_native_cases_from_config(invoke, tmp_path, monkeypatch)[source]

Cases can be declared natively under [[tool.click-extra.test-suite.cases]].