diff --git a/AUTHORS.md b/AUTHORS.md index 04592e11cc..8c73455774 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -286,6 +286,7 @@ - Ahmet Yildirim - Yuta Nakamura - Adam Hawley +- Panagiotis Simakis ## Others whose work we've taken and included in NLTK, but who didn't directly contribute it: diff --git a/nltk/downloader.py b/nltk/downloader.py index e513435a5a..78b0d0ee01 100644 --- a/nltk/downloader.py +++ b/nltk/downloader.py @@ -695,9 +695,9 @@ def _download_package(self, info, download_dir, force): # Ensure the download_dir exists if not os.path.exists(download_dir): - os.mkdir(download_dir) + os.makedirs(download_dir) if not os.path.exists(os.path.join(download_dir, info.subdir)): - os.mkdir(os.path.join(download_dir, info.subdir)) + os.makedirs(os.path.join(download_dir, info.subdir)) # Download the file. This will raise an IOError if the url # is not found. diff --git a/nltk/test/unit/test_downloader.py b/nltk/test/unit/test_downloader.py new file mode 100644 index 0000000000..036b56bb4f --- /dev/null +++ b/nltk/test/unit/test_downloader.py @@ -0,0 +1,19 @@ +from nltk import download + + +def test_downloader_using_existing_parent_download_dir(tmp_path): + """Test that download works properly when the parent folder of the download_dir exists""" + + download_dir = str(tmp_path.joinpath("another_dir")) + download_status = download("mwa_ppdb", download_dir) + assert download_status is True + + +def test_downloader_using_non_existing_parent_download_dir(tmp_path): + """Test that download works properly when the parent folder of the download_dir does not exist""" + + download_dir = str( + tmp_path.joinpath("non-existing-parent-folder", "another-non-existing-folder") + ) + download_status = download("mwa_ppdb", download_dir) + assert download_status is True