tests.test_mail module¶
- tests.test_mail.create_mail_from_bytes(raw)[source]¶
Parse raw bytes into a
DedupMailMixin, body and all.Keeps the parsed payload, so the body-derived properties (
body_lines,size, the body hashes) can be exercised.- Return type:
- tests.test_mail.create_mail_with_headers(*headers)[source]¶
Helper to create a DedupMailMixin object with custom headers.
- tests.test_mail.test_body_hashes_distinguish_and_normalize()[source]¶
hash_decoded_bodyreflects any difference in the decoded body.hash_normalized_bodyignores whitespace, but still separates different bodies.
- tests.test_mail.test_raw_body_hash_reads_the_bytes_of_the_box(tmp_path, config)[source]¶
hash_raw_bodyhashes the body bytes as stored, line endings aside.Two copies of a text in different transfer encodings hash apart under
rawand alike underdecoded. Two copies differing in their line endings alone hash alike under both, as every box format rewrites line endings.
- tests.test_mail.test_raw_headers_hash_the_header_block(tmp_path, config)[source]¶
Under
--raw-headers,hash_key()digests the header block as stored.Line endings are reduced to LF first. No header is required: a mail with none of the hashed headers still gets a hash, where the default hashing gives it none.
- tests.test_mail.test_raw_bytes_come_from_the_file_or_the_box(tmp_path)[source]¶
A worker reads a mail’s bytes from the path it opened, the parent from the box.
A mail attached to neither cannot be read again.
- tests.test_mail.test_raw_body_starts_where_the_parser_ends_the_headers(tmp_path, raw, body)[source]¶
raw_body()starts after the first blank line, or where a header line ends.The parser treats a line that is neither a header nor a continuation as the start of the body when the blank line is missing, and so does the raw body. A bare CR ends a line for both, so the body of a mail with CR line endings is not lost. The header block holds the rest: the two join back into the mail.
- tests.test_mail.test_size_counts_the_bytes_of_the_decoded_body()[source]¶
sizeis the UTF-8 byte length of the decoded body, not its character count.Copies of a mail that differ in their transfer encoding alone measure the same.
- tests.test_mail.test_body_lines_gathers_multipart_preamble_and_epilogue()[source]¶
body_linescollects the preamble, every leaf part and the epilogue.It skips the multipart container itself.
- tests.test_mail.multipart_mail(preamble=b'Forecast.', part=b'Sunny.', epilogue=b'End of forecast.')[source]¶
Wrap one 8-bit
text/plainpart in amultipart/mixedmail.- Return type:
- tests.test_mail.test_body_lines_decodes_each_part(raw, expected)[source]¶
Every part of a mail is decoded into its body lines, whatever its bytes.
Both body hashes are computed from them.
The parser keeps each non-ASCII byte as a lone surrogate.
get_payload()decodes the parts, andbody_linesdecodes the preamble and epilogue as UTF-8, instead of leaving surrogates that crash both body hashes with aUnicodeEncodeError. A byte that is not valid UTF-8 becomesU+FFFD.A non-text part is passed through undecoded. A text part with no charset is tried as ASCII, then as UTF-8. A text part its charset cannot decode comes back as its raw payload instead of crashing.
See: https://github.com/kdeldycke/mail-deduplicate/issues/1085
- tests.test_mail.test_header_normalization(header_name, values, expected)[source]¶
Test header value normalization.
- tests.test_mail.test_raw_8bit_headers_hash_apart()[source]¶
Two headers that differ in their raw 8-bit bytes alone hash apart.
get_all()hands such a header over with every non-ASCII byte replaced byU+FFFD, under whichNoëlandNoêlin latin-1 read alike.
- tests.test_mail.test_raw_8bit_date_parses()[source]¶
A
Dateholding raw 8-bit bytes parses like its ASCII spelling.get()hands such a header over as aHeader, whichparsedate_tz()cannot split. See: https://github.com/kdeldycke/mail-deduplicate/issues/1117
- tests.test_mail.test_normalizers_read_raw_8bit_bytes(header_id)[source]¶
Every header with its own normalization reads a value holding raw 8-bit bytes.
A normalizer that reads its header again with
get()gets aHeader, which string functions reject:header_values()gives the text instead.
- tests.test_mail.test_unparsable_date_returns_none(header)[source]¶
A missing, unparsable or out-of-range
Dategives no timestamp, not a crash.
- tests.test_mail.test_mail_path_derived_from_box(make_box, box_format)[source]¶
A mail’s location comes from its box’s own index, not from opening its file.
Its repr renders that location, ready to be copy-pasted for inspection.
Folder-based boxes give every mail its own file, so their mails carry distinct paths below the box’s directory, which their repr shows. File-based boxes pack every mail into the box’s single file, so their mails all share its path, and their repr adds the mail ID to tell them apart.
See: https://github.com/kdeldycke/mail-deduplicate/issues/157
- tests.test_mail.load_single_mail(make_box, config, box_format)[source]¶
Helper returning the single mail of a fresh test box, ready for dedup work.
- tests.test_mail.test_dehydrate_hydrate_roundtrip(make_box, config, box_format)[source]¶
Dehydration drops the parsed message, but keeps the scalars of the strategies.
Content-dependent properties must transparently restore the exact same content from the source box.
See: https://github.com/kdeldycke/mail-deduplicate/issues/761