Skip to content

Commit 57ce6e3

Browse files
authored
Reduce indirection when running docker commands (#2265)
1 parent 834b6c7 commit 57ce6e3

File tree

10 files changed

+35
-47
lines changed

10 files changed

+35
-47
lines changed

tests/by_image/all-spark-notebook/test_spark_notebooks.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ def test_nbconvert(container: TrackedContainer, test_file: str) -> None:
2323
output_dir = "/tmp"
2424
conversion_timeout_ms = 5000
2525
LOGGER.info(f"Test that {test_file} notebook can be executed ...")
26-
command = (
27-
"jupyter nbconvert --to markdown "
28-
+ f"--ExecutePreprocessor.timeout={conversion_timeout_ms} "
29-
+ f"--output-dir {output_dir} "
30-
+ f"--execute {cont_data_dir}/{test_file}.ipynb"
31-
)
26+
command = [
27+
"jupyter",
28+
"nbconvert",
29+
"--to",
30+
"markdown",
31+
f"--ExecutePreprocessor.timeout={conversion_timeout_ms}",
32+
"--output-dir",
33+
output_dir,
34+
"--execute",
35+
f"{cont_data_dir}/{test_file}.ipynb",
36+
]
3237
logs = container.run_and_wait(
3338
timeout=60,
3439
no_warnings=False,
3540
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
36-
command=["bash", "-c", command],
41+
command=command,
3742
)
3843
warnings = TrackedContainer.get_warnings(logs)
3944
assert len(warnings) == 1

tests/by_image/base-notebook/test_container_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
3535
container.run_detached(
3636
user="root",
3737
environment=[f"NB_USER={nb_user}", "CHOWN_HOME=yes"],
38-
command=["bash", "-c", "sleep infinity"],
38+
command=["sleep", "infinity"],
3939
)
4040

4141
# Give the chown time to complete.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
from tests.utils.run_command import run_command
43
from tests.utils.tracked_container import TrackedContainer
54

65

76
def test_julia(container: TrackedContainer) -> None:
8-
run_command(container, "julia --version")
7+
container.run_and_wait(timeout=5, command=["julia", "--version"])

tests/by_image/docker-stacks-foundation/test_package_managers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@
22
# Distributed under the terms of the Modified BSD License.
33
import pytest # type: ignore
44

5-
from tests.utils.run_command import run_command
65
from tests.utils.tracked_container import TrackedContainer
76

87

98
@pytest.mark.parametrize(
109
"package_manager_command",
11-
[
12-
"apt --version",
13-
"conda --version",
14-
"mamba --version",
15-
"pip --version",
16-
],
10+
["apt", "conda", "mamba", "pip"],
1711
)
1812
def test_package_manager(
1913
container: TrackedContainer, package_manager_command: str
2014
) -> None:
2115
"""Test that package managers are installed and run."""
22-
run_command(container, package_manager_command)
16+
container.run_and_wait(timeout=5, command=[package_manager_command, "--version"])

tests/by_image/docker-stacks-foundation/test_user_options.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_nb_user_change(container: TrackedContainer) -> None:
4040
container.run_detached(
4141
user="root",
4242
environment=[f"NB_USER={nb_user}", "CHOWN_HOME=yes"],
43-
command=["bash", "-c", "sleep infinity"],
43+
command=["sleep", "infinity"],
4444
)
4545

4646
# Give the chown time to complete.
@@ -92,9 +92,11 @@ def test_chown_extra(container: TrackedContainer) -> None:
9292
"CHOWN_EXTRA_OPTS=-R",
9393
],
9494
command=[
95-
"bash",
95+
"stat",
9696
"-c",
97-
"stat -c '%n:%u:%g' /home/jovyan/.bashrc /opt/conda/bin/jupyter",
97+
"%n:%u:%g",
98+
"/home/jovyan/.bashrc",
99+
"/opt/conda/bin/jupyter",
98100
],
99101
)
100102
assert "/home/jovyan/.bashrc:1010:101" in logs
@@ -114,7 +116,7 @@ def test_chown_home(container: TrackedContainer) -> None:
114116
"NB_UID=1010",
115117
"NB_GID=101",
116118
],
117-
command=["bash", "-c", "stat -c '%n:%u:%g' /home/kitten/.bashrc"],
119+
command=["stat", "-c", "%n:%u:%g", "/home/kitten/.bashrc"],
118120
)
119121
assert "/home/kitten/.bashrc:1010:101" in logs
120122

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
from tests.utils.run_command import run_command
43
from tests.utils.tracked_container import TrackedContainer
54

65

76
def test_julia(container: TrackedContainer) -> None:
8-
run_command(container, "julia --version")
7+
container.run_and_wait(timeout=5, command=["julia", "--version"])

tests/by_image/minimal-notebook/test_nbconvert.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ def test_nbconvert(
2323
LOGGER.info(
2424
f"Test that the example notebook {test_file} can be converted to {output_format} ..."
2525
)
26-
command = f"jupyter nbconvert {cont_data_dir}/{test_file}.ipynb --output-dir {output_dir} --to {output_format}"
26+
command = [
27+
"jupyter",
28+
"nbconvert",
29+
f"{cont_data_dir}/{test_file}.ipynb",
30+
"--output-dir",
31+
output_dir,
32+
"--to",
33+
output_format,
34+
]
2735
logs = container.run_and_wait(
2836
timeout=30,
2937
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
30-
command=["bash", "-c", command],
38+
command=command,
3139
)
3240
expected_file = f"{output_dir}/{test_file}.{output_format}"
3341
assert expected_file in logs, f"Expected file {expected_file} not generated"

tests/by_image/scipy-notebook/test_matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_matplotlib(
4040
LOGGER.info(description)
4141
container.run_detached(
4242
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
43-
command=["bash", "-c", "sleep infinity"],
43+
command=["sleep", "infinity"],
4444
)
4545

4646
command = f"python {cont_data_dir}/{test_file}"

tests/utils/conda_package_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CondaPackageHelper:
4141

4242
def __init__(self, container: TrackedContainer):
4343
self.container = container
44-
self.container.run_detached(command=["bash", "-c", "sleep infinity"])
44+
self.container.run_detached(command=["sleep", "infinity"])
4545

4646
self.requested: dict[str, set[str]] | None = None
4747
self.installed: dict[str, set[str]] | None = None

tests/utils/run_command.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)