tests.test_mail_box moduleΒΆ
- tests.test_mail_box.stdlib_box_types()[source]ΒΆ
Yields all mailbox types defined in the standard library.
Only collect direct subclasses of the
mailbox.Mailboxinterface. Ignoremailbox.Mailboxitself and all others starting with an underscore.
- tests.test_mail_box.LOCKING_FORMATS = MarkDecorator(mark=Mark(name='parametrize', args=('box_format', (<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'>)>)), kwargs={'ids': <class 'str'>}))ΒΆ
Sweeps a test over the formats that lock their box: maildir and eml take no lock.
- tests.test_mail_box.test_box_format_definition(box_format)[source]ΒΆ
Ensures each box format is correctly defined.
- tests.test_mail_box.test_box_formats_cover_stdlib()[source]ΒΆ
Box formats cover every box type of the standard library, plus custom ones.
Custom formats like eml come on top, and each format has one structure.
- tests.test_mail_box.test_box_roundtrip(make_box, box_format, mails)[source]ΒΆ
Mails survive a build/read round-trip in each format.
Each format opens through its own custom DedupMail factory.
The duplicates of the mixed box check that no layer collapses identical mails.
- tests.test_mail_box.test_dedup_across_formats(invoke, make_box, box_format)[source]ΒΆ
A full dedup run succeeds on every supported format.
Babyl guards a regression: its
get_file()hands back a nameless in-memory buffer, which used to crash the extraction of a mailβs path metadata.
- tests.test_mail_box.test_run_cut_short_unlocks_boxes(invoke, make_box, monkeypatch, box_format, error)[source]ΒΆ
A run cut short by an error or an interrupt still unlocks its source box.
The next run needs no
--force-unlock. A single-file box is left as the run found it, and a warning names it.
- tests.test_mail_box.STOP_POINT = 'Removals queued, waiting to be stopped.'ΒΆ
Line printed by
STOPPABLE_RUNonce its action has queued its removals.The ID of the interpreter process follows it, on the same line.
- tests.test_mail_box.STOPPABLE_RUN = "\nimport os\nimport sys\nimport time\n\nfrom mail_deduplicate.action import Action\nfrom mail_deduplicate.cli import mdedup\n\nperform = Action.perform\n\n\ndef perform_then_wait(self, dedup):\n perform(self, dedup)\n print('Removals queued, waiting to be stopped.', os.getpid(), flush=True)\n time.sleep(60)\n\n\nAction.perform = perform_then_wait\nmdedup(sys.argv[1:])\n"ΒΆ
An
mdeduprun that waits to be stopped while it holds the locks of its boxes.
- tests.test_mail_box.test_killed_run_needs_force_unlock(invoke, make_box, box_format, stop)[source]ΒΆ
A run stopped by
SIGTERMorSIGKILLexits before any cleanup.Its box stays locked, and only
--force-unlocklets the next run through.On Windows,
os.kill()callsTerminateProcess()for any signal, which skips the cleanup too.
- tests.test_mail_box.test_refused_lock_keeps_no_file_open(make_box, box_format)[source]ΒΆ
A box refused for an existing lock keeps no file open.
MH.lock()opens.mh_sequencesbefore it takes the lock, andMH.close()only closes that file for a locked box.
- tests.test_mail_box.test_refused_subfolder_lock_unlocks_the_folders_before_it(invoke, make_box)[source]ΒΆ
A subfolder locked by another program stops the run.
The folders locked before it are unlocked again: the next run needs no
--force-unlock.
- tests.test_mail_box.test_create_box_refuses_to_clobber_existing(tmp_path)[source]ΒΆ
create_box refuses an existing path unless append is requested.
This guards a destination box even when reached directly.
- tests.test_mail_box.test_unusable_source(invoke, args, messages)[source]ΒΆ
A source that cannot be opened in its format stops the run.
No mail is touched.
- tests.test_mail_box.test_file_autodetect(tmp_path, content, box_format)[source]ΒΆ
A file that starts like a
babylbox, anmmdfbox or one mail is one.Any other file is an
mbox.
- tests.test_mail_box.test_every_format_is_autodetected(make_box, box_format)[source]ΒΆ
A box written in a format is detected in that format.
- tests.test_mail_box.test_mh_detection_needs_sequences_file(make_box)[source]ΒΆ
Numbered mails alone do not make an
mhfolder: its.mh_sequencesdoes.An empty one is enough, as the documentation tells users to create.
- tests.test_mail_box.test_dedup_mixes_autodetected_formats(invoke, make_box)[source]ΒΆ
One run reads a box of each format, each in the format detected for it.
The same mail is in every box. Only the copy whose path sorts first is kept.
- tests.test_mail_box.test_source_without_mail_warns(invoke, tmp_path, autodetected)[source]ΒΆ
A source in which no mail is found gets a warning.
- tests.test_mail_box.test_verbatim_nested_maildirs(invoke, tmp_path)[source]ΒΆ
Nested plain-directory maildir folders (isyncβs Verbatim style) are discovered.
They are found at any depth, without requiring the root to be a maildir itself.
See: https://github.com/kdeldycke/mail-deduplicate/issues/973
- tests.test_mail_box.test_verbatim_forced_maildir_format(invoke, tmp_path)[source]ΒΆ
Forcing maildir on a Verbatim-style tree does not crash on the mail-less root.
- tests.test_mail_box.test_mixed_maildir_folder_conventions(invoke, tmp_path)[source]ΒΆ
Maildir++ dot-folders and Verbatim plain folders coexist under one root.
Each opens exactly once. Guards against subfolders being skipped so only the root INBOX is processed.
See: https://github.com/kdeldycke/mail-deduplicate/issues/123
- tests.test_mail_box.test_maildir_without_tmp_warns(invoke, tmp_path, forced)[source]ΒΆ
A maildir folder that lost its empty
tmpis skipped with a warning.gitand other tools that skip empty folders leave a maildir this way. The warning names each such folder, at any depth, and the run still reads the complete maildir beside them.
- tests.test_mail_box.test_eml_autodetect_and_dedup(invoke, tmp_path)[source]ΒΆ
A folder of loose
.emlfiles is autodetected and deduplicated.Nested directories are included.
See: https://github.com/kdeldycke/mail-deduplicate/issues/760
- tests.test_mail_box.test_eml_export_format(invoke, tmp_path)[source]ΒΆ
Deduplicated mails can be exported as a folder of
.emlfiles.
- tests.test_mail_box.test_eml_add_keeps_header_folding(tmp_path)[source]ΒΆ
EML.add()writes a message with its headers folded as they were parsed.Message.as_bytes()refolds every header past 78 columns, where the stdlib boxes write them as they are.
- tests.test_mail_box.test_eml_nonexistent_box_raises(tmp_path)[source]ΒΆ
Opening a missing
emlfolder without creating it fails cleanly.
- tests.test_mail_box.test_eml_membership(tmp_path)[source]ΒΆ
inmatches existing.emlkeys only, and short-circuits on other names.
- tests.test_mail_box.test_eml_missing_key_raises_keyerror(tmp_path)[source]ΒΆ
Every accessor raises
KeyErrorfor an unknown key, like the stdlib boxes.
- tests.test_mail_box.test_eml_folders_unsupported(tmp_path)[source]ΒΆ
emlfolders are walked recursively, so the subfolder API is inert.
- tests.test_mail_box.test_eml_single_mail_box(tmp_path)[source]ΒΆ
An
emlbox opened on a file holds that one mail, under the fileβs name.Its accessors refuse any other key, even the name of a mail file beside it, and the box takes no other mail.
- tests.test_mail_box.test_single_mail_files_dedup(invoke, tmp_path)[source]ΒΆ
Mail files given one by one are each a source of one mail, and deduplicated.
The content of a file decides, not its name: a file that starts with a header is one mail. Deleting a mail deletes its file.
- tests.test_mail_box.THUNDERBIRD_SUMMARY = '// <!-- <mdb:mork:z v="1.4"/> -->\n'ΒΆ
First line of the
.msfsummary Thunderbird keeps beside each folder.
- tests.test_mail_box.THUNDERBIRD_FILTERS = 'version="9"\nlogging="no"\n'ΒΆ
The
msgFilterRules.datfile Thunderbird writes for an account with no filter.
- tests.test_mail_box.build_thunderbird_tree(root, folders)[source]ΒΆ
Lay out a tree of
mboxfolders as Thunderbird stores an account.foldersmaps the path of each folder file to its mails: the sub-folders of a folder are in its<folder>.sbddirectory. Each folder gets an.msfsummary beside it, and the account gets the file of its filters.- Return type:
- tests.test_mail_box.test_thunderbird_tree_autodetect_and_dedup(invoke, tmp_path)[source]ΒΆ
A Thunderbird account is detected as a tree of
mboxfolders and deduplicated.The folders of
.sbddirectories are read too. The.msfsummaries and the file of filters are not mails, and are left as they are.
- tests.test_mail_box.test_mbox_tree_skips_names_thunderbird_hides(tmp_path, name)[source]ΒΆ
A copy of a folder is not read under a name Thunderbird never shows as a folder.
Read, the copy would join a duplicate set with the folder it copies, and could be kept in place of the folder Thunderbird shows.
- tests.test_mail_box.test_mbox_tree_refused_lock_unlocks_the_folders_before_it(invoke, tmp_path)[source]ΒΆ
A folder of the tree locked by another program stops the run.
The folders locked before it are unlocked again: the next run needs no
--force-unlock, and no.lockfile stays in the tree, where Thunderbird would show it as a folder.
- tests.test_mail_box.test_mbox_tree_past_the_limit_of_open_files(invoke, tmp_path)[source]ΒΆ
A tree of more folders than the limit of open files stops the run.
Each
mboxbox keeps its file open until the end of the run. The error says how to get past the limit, and no.lockfile stays in the tree.
- tests.test_mail_box.HOLD_PROFILE_LOCK = 'import sys\n\nlock = sys.argv[1]\nif sys.platform == "win32":\n import ctypes\n from ctypes import wintypes\n\n kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)\n kernel32.CreateFileW.argtypes = (\n wintypes.LPCWSTR,\n wintypes.DWORD,\n wintypes.DWORD,\n wintypes.LPVOID,\n wintypes.DWORD,\n wintypes.DWORD,\n wintypes.HANDLE,\n )\n kernel32.CreateFileW.restype = wintypes.HANDLE\n # Read and write access, OPEN_EXISTING, and no sharing, as Thunderbird opens it.\n handle = kernel32.CreateFileW(lock, 0xC0000000, 0, None, 3, 0, None)\n if handle == wintypes.HANDLE(-1).value:\n raise ctypes.WinError(ctypes.get_last_error())\nelse:\n import fcntl\n import os\n\n fcntl.lockf(os.open(lock, os.O_WRONLY), fcntl.LOCK_EX)\nprint("held", flush=True)\nsys.stdin.read()\n'ΒΆ
Holds the lock of a profile the way a running Thunderbird does, until killed.
A lock of the test process itself would not do:
fcntllocks never conflict within one process.
- tests.test_mail_box.thunderbird_running(profile)[source]ΒΆ
Hold the lock of profile from another process, as a running Thunderbird.
- tests.test_mail_box.build_thunderbird_profile(tmp_path)[source]ΒΆ
A Thunderbird profile with its lock file, and an account holding a duplicate.
Returns the profile and the
Local Foldersaccount in it.
- tests.test_mail_box.test_thunderbird_open_refuses_to_remove_mails(invoke, tmp_path, args)[source]ΒΆ
A run that deletes or moves mails refuses a profile Thunderbird has open.
No mail is touched.
- tests.test_mail_box.test_thunderbird_open_allows_runs_that_remove_no_mail(invoke, tmp_path, args)[source]ΒΆ
A run that leaves the boxes as they are goes on while Thunderbird runs.
- tests.test_mail_box.test_thunderbird_closed_lets_the_run_remove_mails(invoke, tmp_path, read_only)[source]ΒΆ
The lock file Thunderbird leaves in its profile after it quits stops nothing.
A lock file that cannot be tried, here a read-only one, counts as free too.
- tests.test_mail_box.test_thunderbird_forced_mbox_format(invoke, tmp_path)[source]ΒΆ
The
mboxformat can be forced on a directory of mbox files.
- tests.test_mail_box.build_thunderbird_maildir_tree(root, folders)[source]ΒΆ
Lay out an account that Thunderbird stores as one file per message.
foldersmaps the path of each folder to its mails: the sub-folders of a folder are in its<folder>.sbddirectory. Each folder is a maildir with thecurandtmpdirectories Thunderbird creates, and nonew. Its mails are incur, under names of the form Thunderbird gives them. Each folder gets an.msfsummary beside it, and the account gets the file of its filters.- Return type:
- tests.test_mail_box.test_thunderbird_maildir_tree_autodetect_and_dedup(invoke, tmp_path)[source]ΒΆ
An account of one file per message is read as maildir boxes, with no
new.The folders of
.sbddirectories are read too. A run that deletes mails says to repair the changed folders in Thunderbird, which does not re-read them.