|
1 | 1 | import os.path
|
2 | 2 | from .utils import build_figure, clean_dir
|
| 3 | +import pytest |
3 | 4 |
|
4 |
| -base = os.path.normpath(os.path.dirname(__file__)) |
| 5 | +srcdir = os.path.join(os.path.normpath(os.path.dirname(__file__)), "sources", "external") |
5 | 6 |
|
6 |
| -try: |
7 |
| - import cartopy |
8 |
| -except ImportError: |
9 |
| - cartopy = None |
10 | 7 |
|
11 |
| -try: |
12 |
| - import seaborn |
13 |
| -except ImportError: |
14 |
| - seaborn = None |
| 8 | +def test_cartopy(): |
| 9 | + """Check a cartopy figure can be generated...""" |
| 10 | + try: |
| 11 | + import cartopy |
| 12 | + except ImportError: |
| 13 | + pytest.skip("cartopy not available for testing") |
15 | 14 |
|
| 15 | + res = build_figure(srcdir, "cartopy_figure.py") |
| 16 | + assert res.returncode == 0, "tests/sources/external/cartopy_figure.py could not be built." |
| 17 | + clean_dir(srcdir) |
16 | 18 |
|
17 |
| -if cartopy: |
18 |
| - def test_cartopy(): |
19 |
| - """Check a cartopy figure can be generated...""" |
20 |
| - dir = os.path.join(base, "sources", "external") |
21 |
| - res = build_figure(dir, "cartopy_figure.py") |
22 |
| - assert res.returncode == 0, "tests/sources/external/cartopy_figure.py could not be built." |
23 |
| - clean_dir(dir) |
24 | 19 |
|
| 20 | +def test_seaborn(): |
| 21 | + """Check a seaborn figure can be generated...""" |
| 22 | + try: |
| 23 | + import seaborn |
| 24 | + except ImportError: |
| 25 | + pytest.skip("seaborn not available for testing") |
25 | 26 |
|
26 |
| -if seaborn: |
27 |
| - def test_seaborn(): |
28 |
| - """Check a seaborn figure can be generated...""" |
29 |
| - dir = os.path.join(base, "sources", "external") |
30 |
| - res = build_figure(dir, "seaborn_figure.py") |
31 |
| - assert res.returncode == 0, "tests/sources/external/seaborn_figure.py could not be built." |
32 |
| - clean_dir(dir) |
| 27 | + res = build_figure(srcdir, "seaborn_figure.py") |
| 28 | + assert res.returncode == 0, "tests/sources/external/seaborn_figure.py could not be built." |
| 29 | + clean_dir(srcdir) |
33 | 30 |
|
0 commit comments