tests.conftest moduleΒΆ

tests.conftest.BOX_TYPES = (<class 'mailbox.Maildir'>, <class 'mailbox.mbox'>, <class 'mailbox.MH'>, <class 'mailbox.Babyl'>, <class 'mailbox.MMDF'>, <class 'mail_deduplicate.mail_box.EML'>)ΒΆ

All box classes the make_box/check_box helpers know how to build and read.

Covers every format in BoxFormat, so tests can parametrize over the whole set.

tests.conftest.ALL_FORMATS = MarkDecorator(mark=Mark(name='parametrize', args=('box_format', (<BoxFormat.MAILDIR: (<class 'mailbox.Maildir'>, <BoxStructure.FOLDER: 1>, <class 'mail_deduplicate.mail_box.MaildirDedupMail'>)>, <BoxFormat.MBOX: (<class 'mailbox.mbox'>, <BoxStructure.FILE: 2>, <class 'mail_deduplicate.mail_box.mboxDedupMail'>)>, <BoxFormat.MH: (<class 'mailbox.MH'>, <BoxStructure.FOLDER: 1>, <class 'mail_deduplicate.mail_box.MHDedupMail'>)>, <BoxFormat.BABYL: (<class 'mailbox.Babyl'>, <BoxStructure.FILE: 2>, <class 'mail_deduplicate.mail_box.BabylDedupMail'>)>, <BoxFormat.MMDF: (<class 'mailbox.MMDF'>, <BoxStructure.FILE: 2>, <class 'mail_deduplicate.mail_box.MMDFDedupMail'>)>, <BoxFormat.EML: (<class 'mail_deduplicate.mail_box.EML'>, <BoxStructure.FOLDER: 1>, <class 'mail_deduplicate.mail_box.EMLDedupMail'>)>)), kwargs={'ids': <class 'str'>}))ΒΆ

Sweeps a test over every BoxFormat, to check a behavior shared by all of them.

tests.conftest.DEDUP_ARGS = ('--strategy=select-newest', '--action=delete-discarded', '--dry-run')ΒΆ

A run that exercises every step without touching the mails on disk.

tests.conftest.cache_home(tmp_path)[source]ΒΆ

Point the cache directory of mdedup to a folder of the test.

A run that ends with a bug report saves it in the cache directory. Pointing XDG_CACHE_HOME and LOCALAPPDATA here keeps every test out of the cache of the user running the suite: the tests inside the runner fixture, the tests that call the code directly, and the subprocesses they start.

The variables go through a MonkeyPatch of its own. The monkeypatch fixture would then outlive the runner fixture of each test, and restore a working directory that the runner already removed.

tests.conftest.invoke(runner)[source]ΒΆ
tests.conftest.config()[source]ΒΆ

A fully-populated Config carrying the CLI defaults.

Lets unit tests instantiate Deduplicate and friends without going through the Click command. Mutate the returned mapping to exercise a specific setting.

Return type:

Config

class tests.conftest.MailFactory(**custom_fields)[source]ΒΆ

Bases: object

Create fake mail messages to serve as unittest fixtures.

Help production of either random, customized or deterministic mail message.

Init the mail with custom fields.

You can bypass data normalization by passing the pre-formatted date string with date_rfc2822 custom field instead of date.

render()[source]ΒΆ

Returns the full, rendered content of the mail.

No blank line separates the headers from the body: the parser then ends the headers on the first body line and records a MissingHeaderBodySeparatorDefect, so every fixture built here exercises that path. A test that needs the separator writes its bytes by hand.

static random_string(length)[source]ΒΆ
tests.conftest.make_box(tmp_path)[source]ΒΆ

A generic fixture to produce a temporary box of mails.

The mail container can be created in any format supported by Python’s standard library, plus the custom eml format, via the box_type parameter. Supported values are listed in BOX_TYPES.

tests.conftest.metrics(output)[source]ΒΆ

Extracts the name and value of every metric of a run’s report tables.

Return type:

dict[str, str]

tests.conftest.mail_files(box_path)[source]ΒΆ

Every mail file of a folder-based box, in a stable order.

Dot-prefixed files are left out, as every folder-based format skips them when listing its mails: the temporary link the hardlinking action goes through is one of them.

Return type:

list[Path]

tests.conftest.check_box(box_path, box_type, content=None)[source]ΒΆ

Check the content of a mail box, in any of the BOX_TYPES formats.

Compares the bytes of each mail, as its box hands them out, with the bytes the expected mail was rendered from: a mail rewritten on its way into the box fails the check, where comparing parsed messages would hide the rewrite. An mbox ends every mail with a line break, so an expected mail lacking one gets it.

Counts the occurrences of each mail, so a copy missing from the box or added to it fails the check, where comparing sets would silently deduplicate them.

tests.conftest.assert_one_line_error(result, *messages)[source]ΒΆ

Check that a problem the user can fix ended the run with a one-line error.

The stderr of the run holds each of the messages. It holds no traceback and no invitation to file a bug report, which belong to the errors that are bugs.

Return type:

None