Skip to content

Commit bc3046c

Browse files
authored
envoy.base.utils(0.5.10): Add directory output to fetch tool (#2539)
Signed-off-by: Ryan Northey <[email protected]>
1 parent 5c70573 commit bc3046c

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

envoy.base.utils/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.9
1+
0.5.10

envoy.base.utils/envoy/base/utils/fetch_runner.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def downloads(self) -> dict[str, dict]:
3131

3232
@cached_property
3333
def downloads_path(self) -> pathlib.Path:
34+
if self.args.output == "dir":
35+
return pathlib.Path(self.args.output_path)
3436
return pathlib.Path(self.tempdir.name).joinpath("downloads")
3537

3638
@cached_property
@@ -207,7 +209,8 @@ async def run(self) -> int | None:
207209
print(json.dumps(result))
208210
return 0
209211
exit_now = (
210-
not self.args.output_path
212+
self.args.output == "dir"
213+
or not self.args.output_path
211214
or not self.downloads_path.exists()
212215
or not any(self.downloads_path.iterdir()))
213216
if exit_now:

envoy.base.utils/tests/test_fetch_runner.py

+32-18
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,38 @@ def test_fetchrunner_downloads(patches):
5252
assert "downloads" in runner.__dict__
5353

5454

55-
def test_fetchrunner_downloads_path(patches):
55+
@pytest.mark.parametrize("output_dir", [True, False])
56+
def test_fetchrunner_downloads_path(patches, output_dir):
5657
runner = utils.FetchRunner()
5758
patched = patches(
5859
"pathlib",
60+
("FetchRunner.args",
61+
dict(new_callable=PropertyMock)),
5962
("FetchRunner.tempdir",
6063
dict(new_callable=PropertyMock)),
6164
prefix="envoy.base.utils.fetch_runner")
6265

63-
with patched as (m_plib, m_temp):
66+
with patched as (m_plib, m_args, m_temp):
67+
if output_dir:
68+
m_args.return_value.output = "dir"
6469
assert (
6570
runner.downloads_path
66-
== m_plib.Path.return_value.joinpath.return_value)
71+
== (m_plib.Path.return_value.joinpath.return_value
72+
if not output_dir
73+
else m_plib.Path.return_value))
6774

75+
assert "downloads_path" in runner.__dict__
6876
assert (
6977
m_plib.Path.call_args
70-
== [(m_temp.return_value.name, ), {}])
71-
assert (
72-
m_plib.Path.return_value.joinpath.call_args
73-
== [("downloads", ), {}])
74-
75-
assert "downloads_path" in runner.__dict__
78+
== [((m_temp.return_value.name
79+
if not output_dir
80+
else m_args.return_value.output_path), ), {}])
81+
if not output_dir:
82+
assert (
83+
m_plib.Path.return_value.joinpath.call_args
84+
== [("downloads", ), {}])
85+
else:
86+
assert not m_plib.Path.return_value.joinpath.called
7687

7788

7889
@pytest.mark.parametrize("excludes", ["", "EXCLUDE_PATH"])
@@ -593,7 +604,7 @@ def test_fetchrunner_hashed(patches):
593604
== [(), {}])
594605

595606

596-
@pytest.mark.parametrize("output", ["json", "NOTJSON"])
607+
@pytest.mark.parametrize("output", ["json", "dir", "OTHER"])
597608
@pytest.mark.parametrize("path", ["", "PATH"])
598609
@pytest.mark.parametrize("exists", [True, False])
599610
@pytest.mark.parametrize("empty", [True, False])
@@ -660,17 +671,20 @@ async def _concurrent():
660671
m_log.return_value.debug.call_args_list[:5]
661672
== [[(f"{m_elapsed.return_value} Received:\n {x}\n", ), {}]
662673
for x in items])
663-
664-
if output == "json":
674+
if output in ("json", "dir"):
665675
assert result == 0
666-
assert (
667-
m_print.call_args
668-
== [(m_json.dumps.return_value, ), {}])
669676
assert len(m_log.return_value.debug.call_args_list) == 5
670-
assert (
671-
m_json.dumps.call_args
672-
== [({k: v.decode() for k, v in items.items()},), {}])
673677
assert not m_asyncio.to_thread.called
678+
if output == "json":
679+
assert (
680+
m_print.call_args
681+
== [(m_json.dumps.return_value, ), {}])
682+
assert (
683+
m_json.dumps.call_args
684+
== [({k: v.decode() for k, v in items.items()},), {}])
685+
else:
686+
assert not m_print.called
687+
assert not m_json.dumps.called
674688
return
675689
if not path:
676690
assert result == 0

0 commit comments

Comments
 (0)