|
1 | 1 | """Test the `concat` module."""
|
2 | 2 |
|
3 | 3 | import pathlib
|
| 4 | +from sys import platform |
4 | 5 |
|
5 | 6 | import matplotlib as mpl
|
6 | 7 | import matplotlib.pyplot as plt
|
@@ -45,41 +46,57 @@ def test_help(capfd) -> None:
|
45 | 46 |
|
46 | 47 | def test_combine(tmp_path: pathlib.Path) -> None:
|
47 | 48 | """Test that the `combine` function works."""
|
48 |
| - plot() |
49 |
| - plt.savefig(tmp_path / "test1.png") |
50 |
| - plot() |
51 |
| - plt.savefig(tmp_path / "test2.png") |
52 |
| - plot() |
53 |
| - plt.savefig(tmp_path / "test3.png") |
54 |
| - plot() |
55 |
| - plt.savefig(tmp_path / "test4.png") |
56 |
| - cosmoplots.combine( |
57 |
| - tmp_path / "test1.png", |
58 |
| - tmp_path / "test2.png", |
59 |
| - tmp_path / "test3.png", |
60 |
| - tmp_path / "test4.png", |
61 |
| - ).in_grid(w=2, h=2).save(tmp_path / "out.png") |
62 |
| - first_img = tmp_path / "out.png" |
63 |
| - assert first_img.exists() |
64 |
| - |
65 | 49 |
|
66 |
| -def test_in_grid_not_specified(tmp_path: pathlib.Path) -> None: |
67 |
| - """Test error when `in_grid` has not been called.""" |
68 |
| - plot() |
69 |
| - plt.savefig(tmp_path / "test1.png") |
70 |
| - plot() |
71 |
| - plt.savefig(tmp_path / "test2.png") |
72 |
| - plot() |
73 |
| - plt.savefig(tmp_path / "test3.png") |
74 |
| - plot() |
75 |
| - plt.savefig(tmp_path / "test4.png") |
76 |
| - with pytest.raises(ValueError): |
| 50 | + def _combine() -> None: |
| 51 | + plot() |
| 52 | + plt.savefig(tmp_path / "test1.png") |
| 53 | + plot() |
| 54 | + plt.savefig(tmp_path / "test2.png") |
| 55 | + plot() |
| 56 | + plt.savefig(tmp_path / "test3.png") |
| 57 | + plot() |
| 58 | + plt.savefig(tmp_path / "test4.png") |
77 | 59 | cosmoplots.combine(
|
78 | 60 | tmp_path / "test1.png",
|
79 | 61 | tmp_path / "test2.png",
|
80 | 62 | tmp_path / "test3.png",
|
81 | 63 | tmp_path / "test4.png",
|
82 |
| - ).save(tmp_path / "out.png") |
| 64 | + ).in_grid(w=2, h=2).save(tmp_path / "out.png") |
| 65 | + |
| 66 | + if platform == "win32": |
| 67 | + with pytest.raises(ChildProcessError): |
| 68 | + _combine() |
| 69 | + else: |
| 70 | + _combine() |
| 71 | + first_img = tmp_path / "out.png" |
| 72 | + assert first_img.exists() |
| 73 | + |
| 74 | + |
| 75 | +def test_in_grid_not_specified(tmp_path: pathlib.Path) -> None: |
| 76 | + """Test error when `in_grid` has not been called.""" |
| 77 | + |
| 78 | + def _grid() -> None: |
| 79 | + plot() |
| 80 | + plt.savefig(tmp_path / "test1.png") |
| 81 | + plot() |
| 82 | + plt.savefig(tmp_path / "test2.png") |
| 83 | + plot() |
| 84 | + plt.savefig(tmp_path / "test3.png") |
| 85 | + plot() |
| 86 | + plt.savefig(tmp_path / "test4.png") |
| 87 | + with pytest.raises(ValueError): |
| 88 | + cosmoplots.combine( |
| 89 | + tmp_path / "test1.png", |
| 90 | + tmp_path / "test2.png", |
| 91 | + tmp_path / "test3.png", |
| 92 | + tmp_path / "test4.png", |
| 93 | + ).save(tmp_path / "out.png") |
| 94 | + |
| 95 | + if platform == "win32": |
| 96 | + with pytest.raises(ChildProcessError): |
| 97 | + _grid() |
| 98 | + else: |
| 99 | + _grid() |
83 | 100 |
|
84 | 101 |
|
85 | 102 | def test_output_not_found(tmp_path: pathlib.Path) -> None:
|
|
0 commit comments