|
1 | 1 | importmatplotlib.pyplotasplt
|
| 2 | +frommatplotlib.testing.decoratorsimportimage_comparison |
2 | 3 | importmatplotlib.unitsasmunits
|
3 | 4 | importnumpyasnp
|
4 | 5 |
|
|
9 | 10 | frommockimportMagicMock
|
10 | 11 |
|
11 | 12 |
|
12 |
| -# Tests that the conversion machinery works properly for classes that |
13 |
| -# work as a facade over numpy arrays (like pint) |
14 |
| -deftest_numpy_facade(): |
15 |
| -# Basic class that wraps numpy array and has units |
16 |
| -classQuantity(object): |
17 |
| -def__init__(self,data,units): |
18 |
| -self.magnitude=data |
19 |
| -self.units=units |
| 13 | +# Basic class that wraps numpy array and has units |
| 14 | +classQuantity(object): |
| 15 | +def__init__(self,data,units): |
| 16 | +self.magnitude=data |
| 17 | +self.units=units |
20 | 18 |
|
21 |
| -defto(self,new_units): |
22 |
| -returnQuantity(self.magnitude,new_units) |
| 19 | +defto(self,new_units): |
| 20 | +returnQuantity(self.magnitude,new_units) |
23 | 21 |
|
24 |
| -def__getattr__(self,attr): |
25 |
| -returngetattr(self.magnitude,attr) |
| 22 | +def__getattr__(self,attr): |
| 23 | +returngetattr(self.magnitude,attr) |
26 | 24 |
|
27 |
| -def__getitem__(self,item): |
28 |
| -returnself.magnitude[item] |
| 25 | +def__getitem__(self,item): |
| 26 | +returnself.magnitude[item] |
29 | 27 |
|
| 28 | + |
| 29 | +# Tests that the conversion machinery works properly for classes that |
| 30 | +# work as a facade over numpy arrays (like pint) |
| 31 | +deftest_numpy_facade(): |
30 | 32 | # Create an instance of the conversion interface and
|
31 | 33 | # mock so we can check methods called
|
32 | 34 | qc=munits.ConversionInterface()
|
@@ -55,3 +57,15 @@ def convert(value, unit, axis):
|
55 | 57 | assertqc.convert.called
|
56 | 58 | assertqc.axisinfo.called
|
57 | 59 | assertqc.default_units.called
|
| 60 | + |
| 61 | + |
| 62 | +# Tests gh-8908 |
| 63 | +@image_comparison(baseline_images=['plot_masked_units'], |
| 64 | +extensions=['png'],remove_text=True) |
| 65 | +deftest_plot_masked_units(): |
| 66 | +data=np.linspace(-5,5) |
| 67 | +data_masked=np.ma.array(data,mask=(data>-2)& (data<2)) |
| 68 | +data_masked_units=Quantity(data_masked,'meters') |
| 69 | + |
| 70 | +fig,ax=plt.subplots() |
| 71 | +ax.plot(data_masked_units) |