Skip to content

Avoid qsize for mac #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
dist: xenial
jobs:
include:
- os: linux
dist: xenial
python: 3.4
- os: linux
dist: xenial
python: 3.5
- os: linux
dist: xenial
python: 3.6
- os: linux
dist: xenial
python: 3.7
- os: osx
osx_image: xcode11
language: shell
language: python
sudo: false
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
install:
- pip install -r requirements-test.txt
- pip install flake8
- python setup.py install
- pip3 install -r requirements-test.txt
- pip3 install flake8
- python3 setup.py install
script:
- pytest
- flake8
46 changes: 29 additions & 17 deletions tests/test_wasapi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ def test_populate_downloads(self, mock_session):
mock_session.return_value.get.return_value = MockResponse200()
downloads = wc.Downloads(WASAPI_URL, download=True)
j_queue = downloads.get_q
assert j_queue.qsize() == 2

# Drain the JoinableQueue to avoid BrokenPipeError.
# There could be a better way to handle this...
while j_queue.qsize():
for _ in (1, 2):
q_item = j_queue.get()
assert isinstance(q_item, wc.DataFile)
j_queue.task_done()
# Verify it was two items on the queue.
assert j_queue.empty()

def test_populate_downloads_multi_page(self, mock_session):
"""Test the queue returned for multiple results pages."""
Expand All @@ -165,12 +167,14 @@ def test_populate_downloads_multi_page(self, mock_session):
mock_session.return_value.get.side_effect = responses
downloads = wc.Downloads(WASAPI_URL, download=True)
j_queue = downloads.get_q
assert j_queue.qsize() == 4

# Drain the JoinableQueue to avoid BrokenPipeError.
while j_queue.qsize():
for _ in range(4):
q_item = j_queue.get()
assert isinstance(q_item, wc.DataFile)
j_queue.task_done()
# Verify there were only 4 items on the queue.
assert j_queue.empty()

def test_populate_downloads_no_get_q(self, mock_session):
"""Test download=False prevents get_q attribute existing."""
Expand Down Expand Up @@ -599,39 +603,46 @@ def test_run(self):
get_q = multiprocessing.JoinableQueue()
for _ in (1, 2):
get_q.put(self.data_file)
result_q = multiprocessing.Queue()
log_q = multiprocessing.Queue()
manager = multiprocessing.Manager()
result_q = manager.Queue()
log_q = manager.Queue()
with patch('wasapi_client.verify_file', return_value=True), \
patch('wasapi_client.download_file', return_value=self.data_file):
p = wc.Downloader(get_q, result_q, log_q)
p.start()
p.run()
# If the join doesn't block, the queue is fully processed.
get_q.join()
assert result_q.qsize() == 2
assert log_q.qsize() == 0
# Verify there is nothing on the log_q.
assert log_q.empty()
for _ in (1, 2):
assert result_q.get() == ('success', self.filename)
# Verify those were the only two results on the result_q.
assert result_q.empty()

@patch('wasapi_client.download_file')
def test_run_WASAPIDownloadError(self, mock_download):
"""Test downloader when downloads fail."""
mock_download.side_effect = wc.WASAPIDownloadError()
expected_error = 'WD Error'
mock_download.side_effect = wc.WASAPIDownloadError(expected_error)
# Create a queue holding two sets of file data.
get_q = multiprocessing.JoinableQueue()
for _ in (1, 2):
get_q.put(self.data_file)
result_q = multiprocessing.Queue()
log_q = multiprocessing.Queue()
manager = multiprocessing.Manager()
result_q = manager.Queue()
log_q = manager.Queue()
p = wc.Downloader(get_q, result_q, log_q)
p.start()
p.run()
# If the join doesn't block, the queue is fully processed.
get_q.join()
assert result_q.qsize() == 2
assert log_q.qsize() == 2
for _ in (1, 2):
assert log_q.get().msg == expected_error
assert result_q.get() == ('failure', self.filename)
# Verify those were the only two results on the result_q.
# Sometimes `empty` needs a moment to register.
assert result_q.empty()

def test_run_file_already_verified(self):
"""Test a downloaded file is not verified twice."""
Expand All @@ -641,19 +652,20 @@ def test_run_file_already_verified(self):
get_q = multiprocessing.JoinableQueue()
for _ in (1, 2):
get_q.put(self.data_file)
result_q = multiprocessing.Queue()
log_q = multiprocessing.Queue()
manager = multiprocessing.Manager()
result_q = manager.Queue()
log_q = manager.Queue()
with patch('wasapi_client.verify_file', return_value=True) as mock_verify, \
patch('wasapi_client.download_file', return_value=return_data_file):
p = wc.Downloader(get_q, result_q, log_q)
p.start()
p.run()
# If the join doesn't block, the queue is fully processed.
get_q.join()
assert result_q.qsize() == 2
assert log_q.qsize() == 0
assert log_q.empty()
for _ in (1, 2):
assert result_q.get() == ('success', self.filename)
assert result_q.empty()
# Check verify_exists was not called, since it was called in `download_file`.
assert not mock_verify.called

Expand Down