|
1 | 1 | """Import test for the :mod:`mpl_toolkits.basemap.Basemap` class."""
|
2 | 2 |
|
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import tempfile |
3 | 6 | import datetime as dt
|
4 | 7 | try:
|
5 | 8 | import unittest2 as unittest
|
@@ -145,6 +148,39 @@ def test_arcgisimage_with_cyl(self, axs=None, axslen0=10):
|
145 | 148 | axs_children = axs_obj.get_children()
|
146 | 149 | self.assertEqual(len(axs_children), axslen0 + 1)
|
147 | 150 |
|
| 151 | + @unittest.skipIf(PIL is None, reason="pillow unavailable") |
| 152 | + def test_arcgisimage_with_cyl_using_cache(self, axs=None, axslen0=10): |
| 153 | + """Test showing an ArcGIS image as background.""" |
| 154 | + |
| 155 | + axs_obj = plt.gca() if axs is None else axs |
| 156 | + axs_children = axs_obj.get_children() |
| 157 | + self.assertEqual(len(axs_children), axslen0) |
| 158 | + |
| 159 | + bmap = Basemap(ax=axs, projection="cyl", resolution=None, |
| 160 | + llcrnrlon=-90, llcrnrlat=30, |
| 161 | + urcrnrlon=-60, urcrnrlat=60) |
| 162 | + |
| 163 | + cachedir = tempfile.mkdtemp(prefix="tmp-basemap-cachedir-") |
| 164 | + try: |
| 165 | + # Check that the cache is initially empty. |
| 166 | + self.assertEqual(len(os.listdir(cachedir)), 0) |
| 167 | + # Check that the first call populates the cache. |
| 168 | + img = bmap.arcgisimage(verbose=False, cachedir=cachedir) |
| 169 | + self.assertEqual(len(os.listdir(cachedir)), 1) |
| 170 | + # Check output properties after the first call. |
| 171 | + self.assertIsInstance(img, AxesImage) |
| 172 | + axs_children = axs_obj.get_children() |
| 173 | + self.assertEqual(len(axs_children), axslen0 + 1) |
| 174 | + # Check that the second call does not update the cache. |
| 175 | + img = bmap.arcgisimage(verbose=False, cachedir=cachedir) |
| 176 | + self.assertEqual(len(os.listdir(cachedir)), 1) |
| 177 | + # Check output properties after the second call. |
| 178 | + self.assertIsInstance(img, AxesImage) |
| 179 | + axs_children = axs_obj.get_children() |
| 180 | + self.assertEqual(len(axs_children), axslen0 + 2) |
| 181 | + finally: |
| 182 | + shutil.rmtree(cachedir) |
| 183 | + |
148 | 184 | def _test_basemap_data_warpimage(self, method, axs=None, axslen0=10):
|
149 | 185 | """Test drawing a map background from :mod:`basemap_data`."""
|
150 | 186 |
|
|
0 commit comments