Skip to content

Commit

Permalink
envoy.base.utils: Minor fix for empty output dir (fetch)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax committed Aug 17, 2024
1 parent 441a4cd commit adc9e3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions envoy.base.utils/envoy/base/utils/fetch_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ async def run(self) -> Optional[int]:

if not self.args.output_path:
return 0
if not any(self.downloads_path.iterdir()):
return 0
self.log.debug(
f"{self.time_elapsed} "
f"Packing:\n"
Expand Down
19 changes: 17 additions & 2 deletions envoy.base.utils/tests/test_fetch_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,11 @@ def test_fetchrunner_hashed(patches):

@pytest.mark.parametrize("output", ["json", "NOTJSON"])
@pytest.mark.parametrize("path", ["", "PATH"])
async def test_fetchrunner_run(patches, iters, output, path):
@pytest.mark.parametrize("empty", [True, False])
async def test_fetchrunner_run(patches, iters, output, path, empty):
runner = utils.FetchRunner()
patched = patches(
"any",
"asyncio",
"concurrent",
"json",
Expand All @@ -603,9 +605,10 @@ async def _concurrent():
yield item, items[item]

with patched as patchy:
(m_asyncio, m_concurrent, m_json, m_print,
(m_any, m_asyncio, m_concurrent, m_json, m_print,
m_utils, m_excluded, m_fetch, m_args,
m_downloads, m_path, m_log, m_elapsed) = patchy
m_any.return_value = not empty
m_args.return_value.output = output
m_args.return_value.output_path = path
_to_thread = AsyncMock()
Expand Down Expand Up @@ -650,6 +653,18 @@ async def _concurrent():
assert result == 0
assert len(m_log.return_value.debug.call_args_list) == 5
assert not m_asyncio.to_thread.called
assert not m_any.called
return
if empty:
assert result == 0
assert len(m_log.return_value.debug.call_args_list) == 5
assert not m_asyncio.to_thread.called
assert (
m_any.call_args
== [(m_path.return_value.iterdir.return_value, ), {}])
assert (
m_path.return_value.iterdir.call_args
== [(), {}])
return
assert (
m_log.return_value.debug.call_args_list[5]
Expand Down

0 comments on commit adc9e3f

Please sign in to comment.