/usr/lib/python2.7/dist-packages/cartopy/tests/mpl/test_pseudo_color.py is in python-cartopy 0.14.2+dfsg1-2build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # (C) British Crown Copyright 2013 - 2016, Met Office
#
# This file is part of cartopy.
#
# cartopy is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cartopy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with cartopy. If not, see <https://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
import io
import matplotlib.pyplot as plt
try:
from unittest import mock
except ImportError:
import mock
from nose.tools import assert_equal
import numpy as np
import cartopy.crs as ccrs
def test_pcolormesh_fully_masked():
data = np.ma.masked_all((30, 40))
# Check that a fully masked data array doesn't trigger a pcolor call.
with mock.patch('cartopy.mpl.geoaxes.GeoAxes.pcolor') as pcolor:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.pcolormesh(np.linspace(-90, 90, 40), np.linspace(0, 360, 30), data)
assert_equal(pcolor.call_count, 0, ("pcolor shouldn't have been "
"called, but was."))
plt.close()
def test_pcolormesh_partially_masked():
data = np.ma.masked_all((30, 40))
data[0:100] = 10
# Check that a partially masked data array does trigger a pcolor call.
with mock.patch('cartopy.mpl.geoaxes.GeoAxes.pcolor') as pcolor:
ax = plt.axes(projection=ccrs.PlateCarree())
ax.pcolormesh(np.linspace(-90, 90, 40), np.linspace(0, 360, 30), data)
assert_equal(pcolor.call_count, 1, ("pcolor should have been "
"called exactly once."))
plt.close()
def test_savefig_tight():
nx, ny = 36, 18
xbnds = np.linspace(0, 360, nx, endpoint=True)
ybnds = np.linspace(-90, 90, ny, endpoint=True)
x, y = np.meshgrid(xbnds, ybnds)
data = np.exp(np.sin(np.deg2rad(x)) + np.cos(np.deg2rad(y)))
data = data[:-1, :-1]
ax = plt.subplot(211, projection=ccrs.Robinson())
plt.pcolormesh(xbnds, ybnds, data, transform=ccrs.PlateCarree())
buf = io.BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight')
plt.close()
if __name__ == '__main__':
import nose
nose.runmodule(argv=['-sv', '--with-doctest'], exit=False)
|