3
3
from unittest .mock import MagicMock
4
4
5
5
import matplotlib .pyplot as plt
6
+ from matplotlib import cbook
6
7
from matplotlib .testing .decorators import check_figures_equal , image_comparison
7
8
import matplotlib .units as munits
8
9
import numpy as np
@@ -56,6 +57,9 @@ def convert(value, unit, axis):
56
57
else :
57
58
return Quantity (value , axis .get_units ()).to (unit ).magnitude
58
59
60
+ def un_convert (value , unit , axis ):
61
+ return Quantitfy (value , unit )
62
+
59
63
def default_units (value , axis ):
60
64
if hasattr (value , 'units' ):
61
65
return value .units
@@ -68,6 +72,7 @@ def default_units(value, axis):
68
72
qc .convert = MagicMock (side_effect = convert )
69
73
qc .axisinfo = MagicMock (side_effect = lambda u , a : munits .AxisInfo (label = u ))
70
74
qc .default_units = MagicMock (side_effect = default_units )
75
+ qc .un_convert = MagicMock (side_effect = un_convert )
71
76
return qc
72
77
73
78
@@ -124,7 +129,10 @@ def test_empty_set_limits_with_units(quantity_converter):
124
129
savefig_kwarg = {'dpi' : 120 }, style = 'mpl20' )
125
130
def test_jpl_bar_units ():
126
131
import matplotlib .testing .jpl_units as units
127
- units .register ()
132
+ # Catch warnings thrown whilst jpl unit converters don't have an
133
+ # un_convert() method
134
+ with pytest .warns (Warning , match = 'does not define an un_convert' ):
135
+ units .register ()
128
136
129
137
day = units .Duration ("ET" , 24.0 * 60.0 * 60.0 )
130
138
x = [0 * units .km , 1 * units .km , 2 * units .km ]
@@ -140,7 +148,10 @@ def test_jpl_bar_units():
140
148
savefig_kwarg = {'dpi' : 120 }, style = 'mpl20' )
141
149
def test_jpl_barh_units ():
142
150
import matplotlib .testing .jpl_units as units
143
- units .register ()
151
+ # Catch warnings thrown whilst jpl unit converters don't have an
152
+ # un_convert() method
153
+ with pytest .warns (Warning , match = 'does not define an un_convert' ):
154
+ units .register ()
144
155
145
156
day = units .Duration ("ET" , 24.0 * 60.0 * 60.0 )
146
157
x = [0 * units .km , 1 * units .km , 2 * units .km ]
@@ -175,3 +186,17 @@ class subdate(datetime):
175
186
176
187
fig_test .subplots ().plot (subdate (2000 , 1 , 1 ), 0 , "o" )
177
188
fig_ref .subplots ().plot (datetime (2000 , 1 , 1 ), 0 , "o" )
189
+
190
+
191
+ def test_no_conveter_warnings ():
192
+ class Converter (munits .ConversionInterface ):
193
+ pass
194
+
195
+ # Check that a converter without a manuallly defined convert() method
196
+ # warns
197
+ with pytest .warns (cbook .deprecation .MatplotlibDeprecationWarning ):
198
+ Converter .convert (0 , 0 , 0 )
199
+
200
+ # Check that manually defining a conveter doesn't warn
201
+ Converter .convert = lambda obj , unit , axis : obj
202
+ Converter .convert (0 , 0 , 0 )
0 commit comments