Skip to content

Commit 2766279

Browse files
committed
Unify how we use volumes: mount files, use pathlib.Path without str
1 parent 1af2bfc commit 2766279

File tree

7 files changed

+33
-34
lines changed

7 files changed

+33
-34
lines changed

tests/by_image/base-notebook/test_ips.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ def ipv6_network(docker_client: docker.DockerClient) -> Generator[str, None, Non
3535

3636
def test_ipv46(container: TrackedContainer, ipv6_network: str) -> None:
3737
"""Check server is listening on the expected IP families"""
38-
host_data_dir = THIS_DIR / "data"
39-
cont_data_dir = "/home/jovyan/data"
38+
file_name = "check_listening.py"
39+
host_file = THIS_DIR / "data" / file_name
40+
cont_file = f"/home/jovyan/data/{file_name}"
4041
LOGGER.info("Testing that server is listening on IPv4 and IPv6 ...")
4142
container.run_detached(
4243
network=ipv6_network,
43-
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro,z"}},
44+
volumes={host_file: {"bind": cont_file, "mode": "ro"}},
4445
)
45-
container.exec_cmd(f"python {cont_data_dir}/check_listening.py")
46+
container.exec_cmd(f"python {cont_file}")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run_source_in_dir(
8585
)
8686
return container.run_and_wait(
8787
timeout=5,
88-
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
88+
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
8989
no_failure=no_failure,
9090
command=["bash", "-c", command],
9191
)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def test_units(container: TrackedContainer) -> None:
2626
if not host_data_dir.exists():
2727
continue
2828

29-
for test_file in host_data_dir.iterdir():
30-
test_file_name = test_file.name
31-
LOGGER.info(f"Running unit test: {test_file_name}")
29+
for host_file in host_data_dir.iterdir():
30+
cont_file = f"{cont_data_dir}/{host_file.name}"
31+
LOGGER.info(f"Running unit test: {host_file}")
3232

3333
container.run_and_wait(
3434
timeout=30,
35-
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
36-
command=["python", f"{cont_data_dir}/{test_file_name}"],
35+
volumes={host_file: {"bind": cont_file, "mode": "ro"}},
36+
command=["python", cont_file],
3737
)

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ def test_container_not_delete_bind_mount(
210210
"""Container should not delete host system files when using the (docker)
211211
-v bind mount flag and mapping to /home/jovyan.
212212
"""
213-
d = tmp_path / "data"
214-
d.mkdir()
215-
p = d / "foo.txt"
216-
p.write_text("some-content")
213+
host_data_dir = tmp_path / "data"
214+
host_data_dir.mkdir()
215+
host_file = host_data_dir / "foo.txt"
216+
host_file.write_text("some-content")
217217

218218
container.run_and_wait(
219219
timeout=5,
@@ -223,10 +223,10 @@ def test_container_not_delete_bind_mount(
223223
"NB_USER=user",
224224
"CHOWN_HOME=yes",
225225
],
226-
volumes={d: {"bind": "/home/jovyan/data", "mode": "rw"}},
226+
volumes={host_data_dir: {"bind": "/home/jovyan/data", "mode": "rw"}},
227227
command=["ls"],
228228
)
229-
assert p.read_text() == "some-content"
229+
assert host_file.read_text() == "some-content"
230230
assert len(list(tmp_path.iterdir())) == 1
231231

232232

@@ -259,16 +259,16 @@ def test_secure_path(container: TrackedContainer, tmp_path: pathlib.Path) -> Non
259259
"""Make sure that the sudo command has conda's python (not system's) on PATH.
260260
See <https://github.com/jupyter/docker-stacks/issues/1053>.
261261
"""
262-
d = tmp_path / "data"
263-
d.mkdir()
264-
p = d / "wrong_python.sh"
265-
p.write_text('#!/bin/bash\necho "Wrong python executable invoked!"')
266-
p.chmod(0o755)
262+
host_data_dir = tmp_path / "data"
263+
host_data_dir.mkdir()
264+
host_file = host_data_dir / "wrong_python.sh"
265+
host_file.write_text('#!/bin/bash\necho "Wrong python executable invoked!"')
266+
host_file.chmod(0o755)
267267

268268
logs = container.run_and_wait(
269269
timeout=5,
270270
user="root",
271-
volumes={p: {"bind": "/usr/bin/python", "mode": "ro"}},
271+
volumes={host_file: {"bind": "/usr/bin/python", "mode": "ro"}},
272272
command=["python", "--version"],
273273
)
274274
assert "Wrong python" not in logs

tests/by_image/scipy-notebook/test_cython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_cython(container: TrackedContainer) -> None:
1313

1414
logs = container.run_and_wait(
1515
timeout=10,
16-
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
16+
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
1717
command=[
1818
"bash",
1919
"-c",

tests/by_image/scipy-notebook/test_matplotlib.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ def test_matplotlib(
3434
- Test that matplotlib is able to plot a graph and write it as an image
3535
- Test matplotlib latex fonts, which depend on the cm-super package
3636
"""
37-
host_data_dir = THIS_DIR / "data/matplotlib"
38-
cont_data_dir = "/home/jovyan/data"
37+
host_file = THIS_DIR / "data/matplotlib" / test_file
38+
cont_file = f"/home/jovyan/data/{test_file}"
3939
output_dir = "/tmp"
4040
LOGGER.info(description)
4141
container.run_detached(
42-
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
42+
volumes={host_file: {"bind": cont_file, "mode": "ro"}},
4343
command=["sleep", "infinity"],
4444
)
45-
46-
command = f"python {cont_data_dir}/{test_file}"
47-
container.exec_cmd(command)
45+
container.exec_cmd(f"python {cont_file}")
4846

4947
# Checking if the file is generated
5048
# https://stackoverflow.com/a/15895594/4413446

tests/shared_checks/nbconvert_check.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
def check_nbconvert(
1212
container: TrackedContainer,
13-
host_data_file: Path,
13+
host_file: Path,
1414
output_format: str,
1515
*,
1616
execute: bool,
1717
no_warnings: bool = True,
1818
) -> str:
1919
"""Check if nbconvert is able to convert a notebook file"""
20-
cont_data_file = "/home/jovyan/data/" + host_data_file.name
20+
cont_data_file = "/home/jovyan/data/" + host_file.name
2121

2222
output_dir = "/tmp"
2323
LOGGER.info(
24-
f"Test that the example notebook {host_data_file.name} can be converted to {output_format} ..."
24+
f"Test that the example notebook {host_file.name} can be converted to {output_format} ..."
2525
)
2626
command = [
2727
"jupyter",
@@ -40,12 +40,12 @@ def check_nbconvert(
4040
]
4141
logs = container.run_and_wait(
4242
timeout=60,
43-
volumes={str(host_data_file): {"bind": cont_data_file, "mode": "ro"}},
43+
volumes={host_file: {"bind": cont_data_file, "mode": "ro"}},
4444
command=command,
4545
no_warnings=no_warnings,
4646
)
4747
output_ext = "md" if output_format == "markdown" else output_format
48-
expected_file = f"{output_dir}/{host_data_file.stem}.{output_ext}"
48+
expected_file = f"{output_dir}/{host_file.stem}.{output_ext}"
4949
assert expected_file in logs, f"Expected file {expected_file} not generated"
5050

5151
return logs

0 commit comments

Comments
 (0)