|
| 1 | +importdatetime |
| 2 | +fromunittest.mockimportMock |
| 3 | + |
1 | 4 | importnumpyasnp
|
2 | 5 | importpytest
|
3 | 6 |
|
|
7 | 10 | frommatplotlib.tableimportCustomCell,Table
|
8 | 11 | frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal
|
9 | 12 | frommatplotlib.transformsimportBbox
|
| 13 | +importmatplotlib.unitsasmunits |
10 | 14 |
|
11 | 15 |
|
12 | 16 | deftest_non_square():
|
@@ -229,3 +233,34 @@ def test_table_bbox(fig_test, fig_ref):
|
229 | 233 | loc='center',
|
230 | 234 | bbox=Bbox.from_extents(0.1,0.2,0.9,0.8)
|
231 | 235 | )
|
| 236 | + |
| 237 | + |
| 238 | +@check_figures_equal(extensions=['.png']) |
| 239 | +deftest_table_unit(fig_test,fig_ref): |
| 240 | +# test that table doesn't participate in unit machinery, instead uses repr/str |
| 241 | + |
| 242 | +classFakeUnit: |
| 243 | +def__init__(self,thing): |
| 244 | +pass |
| 245 | +def__repr__(self): |
| 246 | +return"Hello" |
| 247 | + |
| 248 | +fake_convertor=munits.ConversionInterface() |
| 249 | +# v, u, a = value, unit, axis |
| 250 | +fake_convertor.convert=Mock(side_effect=lambdav,u,a:0) |
| 251 | +# not used, here for completeness |
| 252 | +fake_convertor.default_units=Mock(side_effect=lambdav,a:None) |
| 253 | +fake_convertor.axisinfo=Mock(side_effect=lambdau,a:munits.AxisInfo()) |
| 254 | + |
| 255 | +munits.registry[FakeUnit]=fake_convertor |
| 256 | + |
| 257 | +data= [[FakeUnit("yellow"),FakeUnit(42)], |
| 258 | + [FakeUnit(datetime.datetime(1968,8,1)),FakeUnit(True)]] |
| 259 | + |
| 260 | +fig_test.subplots().table(data) |
| 261 | +fig_ref.subplots().table([["Hello","Hello"], ["Hello","Hello"]]) |
| 262 | +fig_test.canvas.draw() |
| 263 | +fake_convertor.convert.assert_not_called() |
| 264 | + |
| 265 | +munits.registry.pop(FakeUnit) |
| 266 | +assertnotmunits.registry.get_converter(FakeUnit) |