@@ -149,7 +149,7 @@ def test_arcgisimage_with_cyl(self, axs=None, axslen0=10):
149
149
self .assertEqual (len (axs_children ), axslen0 + 1 )
150
150
151
151
@unittest .skipIf (PIL is None , reason = "pillow unavailable" )
152
- def test_arcgisimage_with_cyl_using_cache (self , axs = None , axslen0 = 10 ):
152
+ def test_arcgisimage_with_cyl_using_cache (self , existing = False , axs = None , axslen0 = 10 ):
153
153
"""Test showing an ArcGIS image as background."""
154
154
155
155
axs_obj = plt .gca () if axs is None else axs
@@ -160,10 +160,13 @@ def test_arcgisimage_with_cyl_using_cache(self, axs=None, axslen0=10):
160
160
llcrnrlon = - 90 , llcrnrlat = 30 ,
161
161
urcrnrlon = - 60 , urcrnrlat = 60 )
162
162
163
- cachedir = tempfile .mkdtemp (prefix = "tmp-basemap-cachedir-" )
164
- try :
165
- # Check that the cache is initially empty.
163
+ # Create cache directory string and check it is empty.
164
+ tmpdir = tempfile .mkdtemp (prefix = "tmp-basemap-cachedir-" )
165
+ cachedir = tmpdir if existing else os .path .join (tmpdir , "cachedir" )
166
+ if os .path .isdir (cachedir ):
166
167
self .assertEqual (len (os .listdir (cachedir )), 0 )
168
+
169
+ try :
167
170
# Check that the first call populates the cache.
168
171
img = bmap .arcgisimage (verbose = False , cachedir = cachedir )
169
172
self .assertEqual (len (os .listdir (cachedir )), 1 )
@@ -179,7 +182,14 @@ def test_arcgisimage_with_cyl_using_cache(self, axs=None, axslen0=10):
179
182
axs_children = axs_obj .get_children ()
180
183
self .assertEqual (len (axs_children ), axslen0 + 2 )
181
184
finally :
182
- shutil .rmtree (cachedir )
185
+ if os .path .isdir (tmpdir ):
186
+ shutil .rmtree (tmpdir )
187
+
188
+ @unittest .skipIf (PIL is None , reason = "pillow unavailable" )
189
+ def test_arcgisimage_with_cyl_using_cache_already_existing (self ):
190
+ """Test showing an ArcGIS image as background."""
191
+
192
+ self .test_arcgisimage_with_cyl_using_cache (existing = True )
183
193
184
194
def _test_basemap_data_warpimage (self , method , axs = None , axslen0 = 10 ):
185
195
"""Test drawing a map background from :mod:`basemap_data`."""
0 commit comments