Skip to content
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

envoy.base.utils(0.5.10): Add directory output to fetch tool #2539

Merged
merged 1 commit into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion envoy.base.utils/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.9
0.5.10
5 changes: 4 additions & 1 deletion envoy.base.utils/envoy/base/utils/fetch_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def downloads(self) -> dict[str, dict]:

@cached_property
def downloads_path(self) -> pathlib.Path:
if self.args.output == "dir":
return pathlib.Path(self.args.output_path)
return pathlib.Path(self.tempdir.name).joinpath("downloads")

@cached_property
Expand Down Expand Up @@ -207,7 +209,8 @@ async def run(self) -> int | None:
print(json.dumps(result))
return 0
exit_now = (
not self.args.output_path
self.args.output == "dir"
or not self.args.output_path
or not self.downloads_path.exists()
or not any(self.downloads_path.iterdir()))
if exit_now:
Expand Down
50 changes: 32 additions & 18 deletions envoy.base.utils/tests/test_fetch_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,38 @@ def test_fetchrunner_downloads(patches):
assert "downloads" in runner.__dict__


def test_fetchrunner_downloads_path(patches):
@pytest.mark.parametrize("output_dir", [True, False])
def test_fetchrunner_downloads_path(patches, output_dir):
runner = utils.FetchRunner()
patched = patches(
"pathlib",
("FetchRunner.args",
dict(new_callable=PropertyMock)),
("FetchRunner.tempdir",
dict(new_callable=PropertyMock)),
prefix="envoy.base.utils.fetch_runner")

with patched as (m_plib, m_temp):
with patched as (m_plib, m_args, m_temp):
if output_dir:
m_args.return_value.output = "dir"
assert (
runner.downloads_path
== m_plib.Path.return_value.joinpath.return_value)
== (m_plib.Path.return_value.joinpath.return_value
if not output_dir
else m_plib.Path.return_value))

assert "downloads_path" in runner.__dict__
assert (
m_plib.Path.call_args
== [(m_temp.return_value.name, ), {}])
assert (
m_plib.Path.return_value.joinpath.call_args
== [("downloads", ), {}])

assert "downloads_path" in runner.__dict__
== [((m_temp.return_value.name
if not output_dir
else m_args.return_value.output_path), ), {}])
if not output_dir:
assert (
m_plib.Path.return_value.joinpath.call_args
== [("downloads", ), {}])
else:
assert not m_plib.Path.return_value.joinpath.called


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


@pytest.mark.parametrize("output", ["json", "NOTJSON"])
@pytest.mark.parametrize("output", ["json", "dir", "OTHER"])
@pytest.mark.parametrize("path", ["", "PATH"])
@pytest.mark.parametrize("exists", [True, False])
@pytest.mark.parametrize("empty", [True, False])
Expand Down Expand Up @@ -660,17 +671,20 @@ async def _concurrent():
m_log.return_value.debug.call_args_list[:5]
== [[(f"{m_elapsed.return_value} Received:\n {x}\n", ), {}]
for x in items])

if output == "json":
if output in ("json", "dir"):
assert result == 0
assert (
m_print.call_args
== [(m_json.dumps.return_value, ), {}])
assert len(m_log.return_value.debug.call_args_list) == 5
assert (
m_json.dumps.call_args
== [({k: v.decode() for k, v in items.items()},), {}])
assert not m_asyncio.to_thread.called
if output == "json":
assert (
m_print.call_args
== [(m_json.dumps.return_value, ), {}])
assert (
m_json.dumps.call_args
== [({k: v.decode() for k, v in items.items()},), {}])
else:
assert not m_print.called
assert not m_json.dumps.called
return
if not path:
assert result == 0
Expand Down