diff --git a/mailcom/inout.py b/mailcom/inout.py index bf2cb88..5997ea3 100644 --- a/mailcom/inout.py +++ b/mailcom/inout.py @@ -2,15 +2,17 @@ from email.parser import BytesParser import eml_parser from pathlib import Path +import os def list_of_files(directory_name: str) -> list[Path]: - """Get all the eml files in the directory and put them in a list.""" + if not os.path.exists(directory_name): # check if given dir exists raises error otherwise + raise OSError("Path {} does not exist".format(directory_name)) mypath = Path(directory_name) pattern = [".eml", ".html"] # we would not change the file type through user input email_list = [mp.resolve() for mp in mypath.glob("**/*") if mp.suffix in pattern] if len(email_list) == 0: - raise ValueError("The directory {} does not contain .eml or .html files".format(mypath)) + raise ValueError("The directory {} does not contain .eml or .html files. Please check that the directory is containing the email data files".format(mypath)) return email_list diff --git a/mailcom/test/test_inout.py b/mailcom/test/test_inout.py index 6e5bab2..bab34b5 100644 --- a/mailcom/test/test_inout.py +++ b/mailcom/test/test_inout.py @@ -10,6 +10,9 @@ def test_list_of_files_empty(tmp_path): with pytest.raises(ValueError): list_of_files(tmp_path) +def test_list_of_files_dir_not_existing(): + with pytest.raises(OSError): + list_of_files("nonexistingDir") def test_list_of_files_correct_format(tmp_path): p = tmp_path / "test.eml"