2
2
Test Figure.tilemap.
3
3
"""
4
4
5
+ import importlib
6
+
5
7
import pytest
6
8
from pygmt import Figure
7
9
8
- contextily = pytest .importorskip ("contextily" )
9
- rioxarray = pytest .importorskip ("rioxarray" )
10
+ try :
11
+ import contextily
12
+
13
+ _HAS_CONTEXTILY = True
14
+ except ImportError :
15
+ _HAS_CONTEXTILY = False
16
+
17
+ _HAS_RIOXARRAY = bool (importlib .util .find_spec ("rioxarray" ))
10
18
11
19
12
20
@pytest .mark .mpl_image_compare
21
+ @pytest .mark .skipif (not _HAS_CONTEXTILY , reason = "contextily is not installed" )
13
22
def test_tilemap_web_mercator ():
14
23
"""
15
24
Create a tilemap plot in Spherical Mercator projection (EPSG:3857).
@@ -27,6 +36,10 @@ def test_tilemap_web_mercator():
27
36
28
37
@pytest .mark .benchmark
29
38
@pytest .mark .mpl_image_compare
39
+ @pytest .mark .skipif (
40
+ not (_HAS_CONTEXTILY and _HAS_RIOXARRAY ),
41
+ reason = "contextily and rioxarray are not installed" ,
42
+ )
30
43
def test_tilemap_ogc_wgs84 ():
31
44
"""
32
45
Create a tilemap plot using longitude/latitude coordinates (OGC:WGS84), centred on
@@ -45,6 +58,10 @@ def test_tilemap_ogc_wgs84():
45
58
46
59
@pytest .mark .mpl_image_compare
47
60
@pytest .mark .parametrize ("no_clip" , [False , True ])
61
+ @pytest .mark .skipif (
62
+ not (_HAS_CONTEXTILY and _HAS_RIOXARRAY ),
63
+ reason = "contextily and rioxarray are not installed" ,
64
+ )
48
65
def test_tilemap_no_clip (no_clip ):
49
66
"""
50
67
Create a tilemap plot clipped to the Southern Hemisphere when no_clip is False, but
@@ -60,3 +77,30 @@ def test_tilemap_no_clip(no_clip):
60
77
no_clip = no_clip ,
61
78
)
62
79
return fig
80
+
81
+
82
+ @pytest .mark .skipif (_HAS_CONTEXTILY , reason = "contextily is installed." )
83
+ def test_tilemap_no_contextily ():
84
+ """
85
+ Raise an ImportError when contextily is not installed.
86
+ """
87
+ fig = Figure ()
88
+ with pytest .raises (ImportError , match = "Package `contextily` is required" ):
89
+ fig .tilemap (
90
+ region = [- 20000000.0 , 20000000.0 , - 20000000.0 , 20000000.0 ],
91
+ zoom = 0 ,
92
+ lonlat = False ,
93
+ frame = "afg" ,
94
+ )
95
+ return fig
96
+
97
+
98
+ @pytest .mark .skipif (_HAS_RIOXARRAY , reason = "rioxarray is installed." )
99
+ def test_tilemap_no_rioxarray ():
100
+ """
101
+ Raise an ImportError when rioxarray is not installed.
102
+ """
103
+ fig = Figure ()
104
+ with pytest .raises (ImportError , match = "Package `rioxarray` is required" ):
105
+ fig .tilemap (region = [- 180.0 , 180.0 , - 90 , 90 ], zoom = 0 , lonlat = True , frame = "afg" )
106
+ return fig
0 commit comments