Skip to content

Commit 74b0a01

Browse files
authored
Merge pull request #1170 from romainx/test_imp
Matplotlib test refactoring (Follow-on PR #1169)
2 parents 332db3d + e1b9773 commit 74b0a01

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

scipy-notebook/test/test_matplotlib.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,24 @@
99
LOGGER = logging.getLogger(__name__)
1010

1111

12-
def test_matplotlib(container):
13-
"""Test that matplotlib is able to plot a graph and write it as an image"""
14-
host_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")
15-
cont_data_dir = "/home/jovyan/data"
16-
test_file = "matplotlib_1.py"
17-
output_dir = "/tmp"
18-
LOGGER.info(f"Test that matplotlib is able to plot a graph and write it as an image ...")
19-
command = "sleep infinity"
20-
running_container = container.run(
21-
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
22-
tty=True,
23-
command=["start.sh", "bash", "-c", command],
24-
)
25-
command = f"python {cont_data_dir}/{test_file}"
26-
cmd = running_container.exec_run(command)
27-
assert cmd.exit_code == 0, f"Command {command} failed"
28-
LOGGER.debug(cmd.output.decode("utf-8"))
29-
# Checking if the file is generated
30-
# https://stackoverflow.com/a/15895594/4413446
31-
expected_file = f"{output_dir}/test.png"
32-
command = f"test -s {expected_file}"
33-
cmd = running_container.exec_run(command)
34-
assert cmd.exit_code == 0, f"Command {command} failed"
35-
LOGGER.debug(cmd.output.decode("utf-8"))
36-
12+
@pytest.mark.parametrize("test_file,expected_file,description",
13+
[
14+
("matplotlib_1.py", "test.png",
15+
"Test that matplotlib is able to plot a graph and write it as an image ..."),
16+
("matplotlib_fonts_1.py", "test_fonts.png",
17+
"Test cm-super latex labels in matplotlib ...")
18+
])
19+
def test_matplotlib(container, test_file, expected_file, description):
20+
"""Various tests performed on matplotlib
3721
38-
def test_matplotlib_fonts(container):
39-
"""Test matplotlib latex fonts, which depend on the cm-super package"""
40-
host_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
41-
"data")
22+
- Test that matplotlib is able to plot a graph and write it as an image
23+
- Test matplotlib latex fonts, which depend on the cm-super package
24+
"""
25+
host_data_dir = os.path.join(os.path.dirname(
26+
os.path.realpath(__file__)), "data")
4227
cont_data_dir = "/home/jovyan/data"
43-
test_file = "matplotlib_fonts_1.py"
4428
output_dir = "/tmp"
45-
LOGGER.info(f"Test cm-super latex labels in matplotlib ...")
29+
LOGGER.info(description)
4630
command = "sleep infinity"
4731
running_container = container.run(
4832
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
@@ -55,8 +39,7 @@ def test_matplotlib_fonts(container):
5539
LOGGER.debug(cmd.output.decode("utf-8"))
5640
# Checking if the file is generated
5741
# https://stackoverflow.com/a/15895594/4413446
58-
expected_file = f"{output_dir}/test_fonts.png"
59-
command = f"test -s {expected_file}"
42+
command = f"test -s {output_dir}/{expected_file}"
6043
cmd = running_container.exec_run(command)
6144
assert cmd.exit_code == 0, f"Command {command} failed"
6245
LOGGER.debug(cmd.output.decode("utf-8"))

0 commit comments

Comments
 (0)