From e2698281c4148e70bd29fed5612cb55b1225a59d Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Mon, 21 Apr 2025 22:04:08 -0400 Subject: [PATCH] Add file deletion capability and tests --- src/maildirclean/filedir.py | 14 ++++++++++++++ tests/test_filedir.py | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/maildirclean/filedir.py create mode 100644 tests/test_filedir.py diff --git a/src/maildirclean/filedir.py b/src/maildirclean/filedir.py new file mode 100644 index 0000000..9fc8845 --- /dev/null +++ b/src/maildirclean/filedir.py @@ -0,0 +1,14 @@ +"""Module containing functionality to interact with the filesystem""" + +import os +from pathlib import Path + + +def delete_files(file_list: list[str | Path]): + """Delete all files in the provided file list + + Args: + file_list: List of file paths as either strings or Path + """ + for file in file_list: + os.remove(file) diff --git a/tests/test_filedir.py b/tests/test_filedir.py new file mode 100644 index 0000000..b369626 --- /dev/null +++ b/tests/test_filedir.py @@ -0,0 +1,10 @@ +from fixtures import * +from maildirclean.filedir import delete_files + + +def test_delete_files(sample_email_dir): + file_list = list(Path(sample_email_dir).glob("*")) + delete_files(file_list) + + for file in file_list: + assert not Path(file).is_file()