tests.test_cli module¶
- tests.test_cli.acted_upon(result)[source]¶
The lines of a dry run’s action trail, one per mail it would act on.
- tests.test_cli.test_no_progress_bar_label_off_a_terminal(invoke, make_box, label)[source]¶
Off a terminal, a run prints no progress bar, and so none of its labels.
Click prints a hidden bar’s label once instead of the bar, which put a bare line repeating the step heading in every log, pipe and capture.
- tests.test_cli.test_no_log_line_is_left_empty(invoke, make_box)[source]¶
Every log line carries its message on the line of its level prefix.
- tests.test_cli.test_early_export_file_check(invoke, make_box, tmp_path)[source]¶
Ensures the export file is tested for existence before any process is ran.
See: https://github.com/kdeldycke/mail-deduplicate/issues/119
- tests.test_cli.test_theme_styles_runtime_output(invoke, make_box, theme_id)[source]¶
The active
--thememust style runtime output, not just the help screen.Regression test: the theme used to be captured once at import time via
get_default_theme(), so--themewas ignored everywhere but--help.
- tests.test_cli.test_cli_test_suite()[source]¶
Run the TOML black-box suite (cli-test-suite.toml) against the installed mdedup.
Each case is executed as a subprocess by click-extra’s test-suite runner, so this exercises the real entry point (version reporting, help screen rendering).
Marked
once: the CI matrix drives the same TOML suite in every cell through click-extra’s runner, so this Python-level wrapper only needs a single executor.
- tests.test_cli.test_parallel_run_matches_sequential(invoke, make_box, strategy)[source]¶
A run with –jobs > 1 must decide what the sequential default decides.
Both the hashing and the selection are handed to worker processes, and both yield their results in submission order, so the grouping, the statistics and the report must come out identical at any job count.
- tests.test_cli.test_sources_changed_between_steps(invoke, make_box, monkeypatch, jobs, change, found)[source]¶
A mail delivered or removed after the load step must not break the stats.
The hashing step lists each box again, so it can see more or fewer mails than the load step counted. The run must count the mails it hashed, and warn. See: https://github.com/kdeldycke/mail-deduplicate/issues/1143
- tests.test_cli.test_memory_stays_bounded_while_hashing(invoke, make_box, jobs)[source]¶
Peak memory must track the few mails in flight, not the whole corpus.
Regression test for the out-of-memory conditions reported on big boxes: mails used to be retained fully parsed for the whole run, so memory grew linearly with the corpus. They are now dehydrated as soon as they are hashed, and the parallel path materializes mails in bounded batches instead of the whole corpus. See: https://github.com/kdeldycke/mail-deduplicate/issues/761
- tests.test_cli.test_hash_only_prints_headers(invoke, make_box, box_type)[source]¶
--hash-onlymust print each mail’s canonical headers and hash, not crash.Regression test: the display loop referenced a non-existent
mail.pretty_headersattribute, so--hash-onlydied withAttributeErroron the first mail. See: https://github.com/kdeldycke/mail-deduplicate/issues/1004
- tests.test_cli.test_single_hash_header_needs_no_minimal_flag(invoke, make_box)[source]¶
A single
--hash-headermust work without a separate minimal-headers flag.Regression test: narrowing the hash below four headers used to raise “Provided number of headers to hash (1) is less than the minimal required number of headers (4)” and then reject every mail. The floor is now derived as
min(4, number of --hash-header values), so a lone header is enough. See: https://github.com/kdeldycke/mail-deduplicate/issues/974
- tests.test_cli.test_too_few_headers_leaves_mail_unhashed(invoke, make_box)[source]¶
A mail carrying fewer hash headers than the floor gets no hash.
The warning renders the headers that were found, so the mail can be inspected.
The floor is derived as
min(4, number of --hash-header values), so asking for four headers the mail does not carry leaves it one below the floor.
- tests.test_cli.applied_options(result, preset)[source]¶
The options a run says it applies for a preset.
They sit on the log line after the one announcing the preset.
- Return type:
- tests.test_cli.preset_args(preset)[source]¶
The options a preset stands for, as arguments of a command line.
- tests.test_cli.test_preset_is_an_alias_of_its_options(invoke, make_box, preset, duplicates)[source]¶
A run with a preset decides what a run with the options it stands for decides.
The box holds what tells the presets apart: two identical copies, a near copy sharing every hashed header, and a copy a gateway dated two days later. Each preset groups more of them than the one before.
- tests.test_cli.test_preset_yields_to_an_option_set_by_the_user(invoke, make_box, args, env, overriding, dropped)[source]¶
An option the user set keeps its value over the one its preset gives it.
The run names each option that overrides the preset, and leaves the preset’s value for it out of the options it applies.
- tests.test_cli.test_preset_takes_some_options_without_a_warning(invoke, make_box)[source]¶
Two kinds of options set over a preset raise no warning.
A value equal to the preset’s changes nothing. The strategy decides which copy stays, not what counts as a copy, so it replaces the preset’s in silence.
- tests.test_cli.test_preset_thresholds_stay_on_without_its_hashing(invoke, tmp_path)[source]¶
Replacing a hashing option of the conservative preset keeps the thresholds on.
Under
--hash-body skip, the hash covers the header block alone, so two mails with the same headers and different bodies share it. The preset turns the thresholds off only with its own hashing options, so here they stay on and skip the set.
- tests.test_cli.test_preset_thresholds_rely_on_its_hashing(invoke, make_box, args, kept)[source]¶
The thresholds of the conservative preset apply only with its hashing options.
Replacing a hashing option, directly or through the option linked to it, leaves the thresholds at their defaults. A user value equal to the preset’s keeps them.
- tests.test_cli.test_raw_headers_refuse_a_header_list(invoke, make_box)[source]¶
--raw-headersand--hash-headerset together contradict each other.
- tests.test_cli.test_conservative_preset_keeps_near_copies(invoke, make_box)[source]¶
Only identical copies are deduplicated: a near copy is left untouched.
The same three mails collapse into one set under the default hashing, as the near copy shares every hashed header and differs by a footer the thresholds allow. The footer sits on the body’s single line:
MailFactoryindents the first line of a body alone, so a second line would break the mail apart.
- tests.test_cli.test_raw_headers_hash_a_mail_lacking_headers(invoke, tmp_path)[source]¶
No minimal number of headers applies to the raw headers.
The same mail gets no hash under the default hashing: see
test_mail_with_too_few_headers_is_kept.
- tests.test_cli.test_raw_headers_hash_only_shows_every_header(invoke, make_box)[source]¶
Under
--raw-headers,--hash-onlylists every header of a mail.
- tests.test_cli.test_conservative_preset_parallel_run_matches_sequential(invoke, make_box)[source]¶
The conservative preset picks the same copies in a worker process.
- tests.test_cli.test_headers_table_rendered_only_when_logged(invoke, make_box, monkeypatch)[source]¶
The canonical-headers table is not built at the default verbosity.
Rendering it goes through
tabulateand costs more than the hash itself, yet any level above debug discards it.
- tests.test_cli.test_invalid_option_value_rejected(invoke, make_box, args, message)[source]¶
An option value that cannot work is refused at parse time.
- tests.test_cli.test_regexp_type_keeps_compiled_expression()[source]¶
A compiled expression goes through as is, as Click expects of a type.
- tests.test_cli.test_duplicate_source_rejected(invoke, make_box)[source]¶
The same mail source given twice is refused.
The source path is the key that ties a mail back to its origin.
- tests.test_cli.test_hash_only_warns_about_ignored_options(invoke, make_box)[source]¶
–hash-only ignores the options of the selection and action steps it skips.
Any of them the user set is reported.
- tests.test_cli.test_main_entrypoint_reports_version(monkeypatch, capsys)[source]¶
The
main()indirection runs the CLI end to end:--versionexits cleanly.
- tests.test_cli.test_main_refuses_to_run_in_a_worker(monkeypatch, enter_worker)[source]¶
main()exits before it imports the CLI, in both states a worker reaches it.
- tests.test_cli.UNGUARDED_LAUNCHER = 'import multiprocessing\nimport sys\n\nimport mail_deduplicate.__main__ as user_main\n\n# Each spawn worker imports this file again, which calls main() in it.\nmultiprocessing.set_start_method("spawn", force=True)\nsys.exit(user_main.main())\n'¶
A launcher shaped like the one Nuitka writes for
--main-entry-point, with no__name__ == "__main__"guard around its call.
- tests.test_cli.test_unguarded_launcher_stops_in_each_worker(tmp_path)[source]¶
A launcher calling
main()on import stops in each--jobsworker.It stops before the CLI there opens a box. The parent then fails on its broken pool.
The run cannot multiply processes, guard or not: CPython refuses to start a process from a worker that is still importing its parent’s main module.