Skip to content

Commit

Permalink
test: pass list of string to subprocess
Browse files Browse the repository at this point in the history
`subprocess.run` takes a list of strings. So convert `pathlib.Path` to
`str` before.

Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
  • Loading branch information
bdrung authored and schopin-pro committed Jun 11, 2024
1 parent 05c25d1 commit 840ef7a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_apport_checkreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _call(
expected_returncode: int = 0,
expected_stdout: str = "",
) -> None:
cmd = [self.data_dir / "apport-checkreports"]
cmd = [str(self.data_dir / "apport-checkreports")]
if args:
cmd += args
process = subprocess.run(
Expand Down
30 changes: 17 additions & 13 deletions tests/integration/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def tearDown(self):
def test_general_hook_generic(self) -> None:
"""Test running general-hooks/generic.py."""
process = subprocess.run(
[sys.executable, self.data_dir / "general-hooks" / "generic.py"],
[sys.executable, str(self.data_dir / "general-hooks" / "generic.py")],
check=True,
env=self.env,
encoding="utf-8",
Expand All @@ -63,7 +63,7 @@ def test_general_hook_generic(self) -> None:
def test_package_hook_nologs(self):
"""package_hook without any log files."""
ph = subprocess.run(
[self.data_dir / "package_hook", "-p", "bash"],
[str(self.data_dir / "package_hook"), "-p", "bash"],
check=False,
env=self.env,
input=b"something is wrong",
Expand All @@ -85,7 +85,7 @@ def test_package_hook_uninstalled(self):
"""package_hook on an uninstalled package (might fail to install)."""
pkg = apport.packaging.get_uninstalled_package()
ph = subprocess.run(
[self.data_dir / "package_hook", "-p", pkg],
[str(self.data_dir / "package_hook"), "-p", pkg],
check=False,
env=self.env,
input=b"something is wrong",
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_package_hook_logs(self):

ph = subprocess.run(
[
self.data_dir / "package_hook",
str(self.data_dir / "package_hook"),
"-p",
"bash",
"-l",
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_package_hook_logs(self):
def test_package_hook_tags(self):
"""package_hook with extra tags argument."""
cmd = [
self.data_dir / "package_hook",
str(self.data_dir / "package_hook"),
"-p",
"bash",
"-t",
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_kernel_crashdump_kexec(self):
log.write("vmcore successfully dumped")

self.assertEqual(
subprocess.call(self.data_dir / "kernel_crashdump", env=self.env),
subprocess.call([str(self.data_dir / "kernel_crashdump")], env=self.env),
0,
"kernel_crashdump finished successfully",
)
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_kernel_crashdump_kdump(self):
wrongly_named.write_bytes(b"2" * 80)

self.assertEqual(
subprocess.call(self.data_dir / "kernel_crashdump", env=self.env),
subprocess.call([str(self.data_dir / "kernel_crashdump")], env=self.env),
0,
"kernel_crashdump finished successfully",
)
Expand Down Expand Up @@ -306,7 +306,9 @@ def test_kernel_crashdump_kdump_log_symlink(self):

self.assertNotEqual(
subprocess.call(
self.data_dir / "kernel_crashdump", env=self.env, stderr=subprocess.PIPE
[str(self.data_dir / "kernel_crashdump")],
env=self.env,
stderr=subprocess.PIPE,
),
0,
"kernel_crashdump unexpectedly succeeded",
Expand All @@ -330,7 +332,9 @@ def test_kernel_crashdump_kdump_log_dir_symlink(self):

self.assertNotEqual(
subprocess.call(
self.data_dir / "kernel_crashdump", env=self.env, stderr=subprocess.PIPE
[str(self.data_dir / "kernel_crashdump")],
env=self.env,
stderr=subprocess.PIPE,
),
0,
"kernel_crashdump unexpectedly succeeded",
Expand Down Expand Up @@ -371,7 +375,7 @@ def test_gcc_ide_hook_file(self):

self.assertEqual(
subprocess.call(
[self.data_dir / "gcc_ice_hook", gcc_path, test_source.name],
[str(self.data_dir / "gcc_ice_hook"), gcc_path, test_source.name],
env=self.env,
),
0,
Expand Down Expand Up @@ -405,7 +409,7 @@ def test_gcc_ide_hook_file_binary(self):

self.assertEqual(
subprocess.call(
[self.data_dir / "gcc_ice_hook", gcc_path, test_source.name],
[str(self.data_dir / "gcc_ice_hook"), gcc_path, test_source.name],
env=self.env,
),
0,
Expand All @@ -427,7 +431,7 @@ def test_gcc_ide_hook_pipe(self):
test_source = "int f(int x);"

hook = subprocess.run(
[self.data_dir / "gcc_ice_hook", gcc_path, "-"],
[str(self.data_dir / "gcc_ice_hook"), gcc_path, "-"],
check=False,
env=self.env,
input=test_source.encode(),
Expand Down Expand Up @@ -462,7 +466,7 @@ def test_kernel_oops_hook(self):
ata_piix libata sd_mod scsi_mod ext3 jbd mbcache uhci_hcd ohci_hcd ehci_hcd
"""
hook = subprocess.run(
[self.data_dir / "kernel_oops"],
[str(self.data_dir / "kernel_oops")],
check=False,
env=self.env,
input=test_source.encode(),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_unkillable_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def tearDown(self):
shutil.rmtree(self.report_dir)

def _call(self, omit: list | None = None) -> None:
cmd = [self.data_dir / "unkillable_shutdown"]
cmd = [str(self.data_dir / "unkillable_shutdown")]
if omit:
cmd += [arg for pid in omit for arg in ("-o", str(pid))]
process = subprocess.run(
Expand Down

0 comments on commit 840ef7a

Please sign in to comment.