Commit 74b0a01a authored by Romain's avatar Romain Committed by GitHub

Merge pull request #1170 from romainx/test_imp

Matplotlib test refactoring (Follow-on PR #1169)
parents 332db3db e1b97737
...@@ -9,40 +9,24 @@ import os ...@@ -9,40 +9,24 @@ import os
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
def test_matplotlib(container): @pytest.mark.parametrize("test_file,expected_file,description",
"""Test that matplotlib is able to plot a graph and write it as an image""" [
host_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") ("matplotlib_1.py", "test.png",
cont_data_dir = "/home/jovyan/data" "Test that matplotlib is able to plot a graph and write it as an image ..."),
test_file = "matplotlib_1.py" ("matplotlib_fonts_1.py", "test_fonts.png",
output_dir = "/tmp" "Test cm-super latex labels in matplotlib ...")
LOGGER.info(f"Test that matplotlib is able to plot a graph and write it as an image ...") ])
command = "sleep infinity" def test_matplotlib(container, test_file, expected_file, description):
running_container = container.run( """Various tests performed on matplotlib
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
tty=True,
command=["start.sh", "bash", "-c", command],
)
command = f"python {cont_data_dir}/{test_file}"
cmd = running_container.exec_run(command)
assert cmd.exit_code == 0, f"Command {command} failed"
LOGGER.debug(cmd.output.decode("utf-8"))
# Checking if the file is generated
# https://stackoverflow.com/a/15895594/4413446
expected_file = f"{output_dir}/test.png"
command = f"test -s {expected_file}"
cmd = running_container.exec_run(command)
assert cmd.exit_code == 0, f"Command {command} failed"
LOGGER.debug(cmd.output.decode("utf-8"))
def test_matplotlib_fonts(container): - Test that matplotlib is able to plot a graph and write it as an image
"""Test matplotlib latex fonts, which depend on the cm-super package""" - Test matplotlib latex fonts, which depend on the cm-super package
host_data_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), """
"data") host_data_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "data")
cont_data_dir = "/home/jovyan/data" cont_data_dir = "/home/jovyan/data"
test_file = "matplotlib_fonts_1.py"
output_dir = "/tmp" output_dir = "/tmp"
LOGGER.info(f"Test cm-super latex labels in matplotlib ...") LOGGER.info(description)
command = "sleep infinity" command = "sleep infinity"
running_container = container.run( running_container = container.run(
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}}, volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},
...@@ -55,8 +39,7 @@ def test_matplotlib_fonts(container): ...@@ -55,8 +39,7 @@ def test_matplotlib_fonts(container):
LOGGER.debug(cmd.output.decode("utf-8")) LOGGER.debug(cmd.output.decode("utf-8"))
# Checking if the file is generated # Checking if the file is generated
# https://stackoverflow.com/a/15895594/4413446 # https://stackoverflow.com/a/15895594/4413446
expected_file = f"{output_dir}/test_fonts.png" command = f"test -s {output_dir}/{expected_file}"
command = f"test -s {expected_file}"
cmd = running_container.exec_run(command) cmd = running_container.exec_run(command)
assert cmd.exit_code == 0, f"Command {command} failed" assert cmd.exit_code == 0, f"Command {command} failed"
LOGGER.debug(cmd.output.decode("utf-8")) LOGGER.debug(cmd.output.decode("utf-8"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment