Skip to content

Commit

Permalink
Additional logging for command line calls (like uv)
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-gupta committed Jul 25, 2024
1 parent bc2d78f commit d88db00
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
10 changes: 6 additions & 4 deletions edgetest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def _run_command(*args) -> Tuple[str, int]:
Error raised when the command is not successfully executed.
"""
LOG.debug(f"Running the following command: \n\n {' '.join(args)}")
popen = Popen(args, stdout=PIPE, universal_newlines=True)
out, _ = popen.communicate()
popen = Popen(args, stdout=PIPE, stderr=PIPE, universal_newlines=True)
out, err = popen.communicate()
if popen.returncode:
raise RuntimeError(
f"Unable to run the following command: \n\n {' '.join(args)}"
)
f"Unable to run the following command: \n\n {' '.join(args)} \n\n"
f"Returned the following stdout: \n\n {out} \n\n"
f"Returned the following stderr: \n\n {err} \n\n"
) from None

return out, popen.returncode

Expand Down
5 changes: 5 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_basic_setup(mock_popen, mock_path, tmpdir, plugin_manager):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -174,6 +175,7 @@ def test_setup_extras(mock_popen, mock_path, tmpdir, plugin_manager):
call(
("uv", "pip", "install", f"--python={py_loc!s}", ".[tests, complete]"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -217,11 +219,13 @@ def test_setup_pip_deps(mock_popen, mock_path, tmpdir, plugin_manager):
"otherpkg",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "install", f"--python={py_loc}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -265,6 +269,7 @@ def test_setup_pip_deps_error(mock_popen, mock_path, tmpdir, plugin_manager):
"otherpkg",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down
17 changes: 17 additions & 0 deletions tests/test_interface_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,19 @@ def test_cli_basic(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "install", f"--python={py_loc!s}", "myupgrade", "--upgrade"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "list", f"--python={py_loc!s}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -211,11 +214,13 @@ def test_cli_basic_lower(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "install", f"--python={py_loc!s}", "mylower==0.0.1"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -274,6 +279,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_myupgrade_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -286,11 +292,13 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "install", f"--python={py_allreq_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -303,6 +311,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -315,6 +324,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"json",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -327,6 +337,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"json",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -425,6 +436,7 @@ def test_cli_nosetup(mock_popen, mock_cpopen):
call(
("uv", "pip", "list", f"--python={py_loc}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -506,6 +518,7 @@ def test_cli_notest(mock_popen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -518,11 +531,13 @@ def test_cli_notest(mock_popen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "list", f"--python={py_loc!s}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -558,6 +573,7 @@ def test_cli_notest_lower(mock_popen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -569,6 +585,7 @@ def test_cli_notest_lower(mock_popen, mock_builder):
"mylower==0.0.1",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down
17 changes: 17 additions & 0 deletions tests/test_interface_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_cli_basic(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -154,11 +155,13 @@ def test_cli_basic(mock_popen, mock_cpopen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "list", f"--python={py_loc!s}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -210,6 +213,7 @@ def test_cli_basic_lower(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -221,6 +225,7 @@ def test_cli_basic_lower(mock_popen, mock_cpopen, mock_builder):
"mylower==0.0.1",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -279,6 +284,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_myupgrade_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -291,6 +297,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -302,6 +309,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
".",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -314,6 +322,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -326,6 +335,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"json",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -338,6 +348,7 @@ def test_cli_reqs(mock_popen, mock_cpopen, mock_builder):
"json",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -436,6 +447,7 @@ def test_cli_nosetup(mock_popen, mock_cpopen):
call(
("uv", "pip", "list", f"--python={py_loc}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -517,6 +529,7 @@ def test_cli_notest(mock_popen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -529,11 +542,13 @@ def test_cli_notest(mock_popen, mock_builder):
"--upgrade",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
("uv", "pip", "list", f"--python={py_loc!s}", "--format", "json"),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down Expand Up @@ -569,6 +584,7 @@ def test_cli_notest_lower(mock_popen, mock_builder):
call(
("uv", "pip", "install", f"--python={py_loc!s}", "."),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
call(
Expand All @@ -580,6 +596,7 @@ def test_cli_notest_lower(mock_popen, mock_builder):
"mylower==0.0.1",
),
stdout=-1,
stderr=-1,
universal_newlines=True,
),
]
Expand Down

0 comments on commit d88db00

Please sign in to comment.