Skip to content

Commit ec15505

Browse files
committed
Add test for Basemap.arcgisimage with on-the-fly cachedir creation
1 parent 0131763 commit ec15505

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/basemap/test/mpl_toolkits/basemap/test_Basemap.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def test_arcgisimage_with_cyl(self, axs=None, axslen0=10):
149149
self.assertEqual(len(axs_children), axslen0 + 1)
150150

151151
@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):
153153
"""Test showing an ArcGIS image as background."""
154154

155155
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):
160160
llcrnrlon=-90, llcrnrlat=30,
161161
urcrnrlon=-60, urcrnrlat=60)
162162

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):
166167
self.assertEqual(len(os.listdir(cachedir)), 0)
168+
169+
try:
167170
# Check that the first call populates the cache.
168171
img = bmap.arcgisimage(verbose=False, cachedir=cachedir)
169172
self.assertEqual(len(os.listdir(cachedir)), 1)
@@ -179,7 +182,14 @@ def test_arcgisimage_with_cyl_using_cache(self, axs=None, axslen0=10):
179182
axs_children = axs_obj.get_children()
180183
self.assertEqual(len(axs_children), axslen0 + 2)
181184
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)
183193

184194
def _test_basemap_data_warpimage(self, method, axs=None, axslen0=10):
185195
"""Test drawing a map background from :mod:`basemap_data`."""

0 commit comments

Comments
 (0)