Skip to content

Commit

Permalink
Adds a test that a warning is raised
Browse files Browse the repository at this point in the history
Adds a test that a warning is raised when download has been started in a thread which is not the main thread.
  • Loading branch information
AthKouloumvakos authored and Cadair committed Oct 9, 2023
1 parent fb15ddb commit 47f269a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion parfive/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def _add_shutdown_signals(loop, task):

if threading.current_thread() != threading.main_thread():
warnings.warn(
"This download has been started in a thread which is not the main thread. You will not be able to interrupt the download."
"This download has been started in a thread which is not the main thread. You will not be able to interrupt the download.",
UserWarning
)
return

Expand Down
6 changes: 4 additions & 2 deletions parfive/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def __init__(self, *args, **kwargs):
def run(self):
self.result = self._target(*self._args, **self._kwargs)


import warnings
def test_download_out_of_main_thread(httpserver, tmpdir):
tmpdir = str(tmpdir)
httpserver.serve_content(
Expand All @@ -486,6 +486,8 @@ def test_download_out_of_main_thread(httpserver, tmpdir):

thread = CustomThread(target=dl.download)
thread.start()
thread.join()

with pytest.warns(UserWarning, match="This download has been started in a thread which is not the main thread. You will not be able to interrupt the download."):
thread.join()

validate_test_file(thread.result)

0 comments on commit 47f269a

Please sign in to comment.