9
9
LOGGER = logging .getLogger (__name__ )
10
10
11
11
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
37
21
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" )
42
27
cont_data_dir = "/home/jovyan/data"
43
- test_file = "matplotlib_fonts_1.py"
44
28
output_dir = "/tmp"
45
- LOGGER .info (f"Test cm-super latex labels in matplotlib ..." )
29
+ LOGGER .info (description )
46
30
command = "sleep infinity"
47
31
running_container = container .run (
48
32
volumes = {host_data_dir : {"bind" : cont_data_dir , "mode" : "ro" }},
@@ -55,8 +39,7 @@ def test_matplotlib_fonts(container):
55
39
LOGGER .debug (cmd .output .decode ("utf-8" ))
56
40
# Checking if the file is generated
57
41
# 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 } "
60
43
cmd = running_container .exec_run (command )
61
44
assert cmd .exit_code == 0 , f"Command { command } failed"
62
45
LOGGER .debug (cmd .output .decode ("utf-8" ))
0 commit comments