Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit36c4beb

Browse files
story645rcomer
andcommitted
test that table uses repr and doesn't try to convert unitized data
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parentc16d7db commit36c4beb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎lib/matplotlib/tests/test_table.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
importdatetime
2+
fromunittest.mockimportMock
3+
14
importnumpyasnp
25
importpytest
36

@@ -7,6 +10,7 @@
710
frommatplotlib.tableimportCustomCell,Table
811
frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal
912
frommatplotlib.transformsimportBbox
13+
importmatplotlib.unitsasmunits
1014

1115

1216
deftest_non_square():
@@ -229,3 +233,33 @@ def test_table_bbox(fig_test, fig_ref):
229233
loc='center',
230234
bbox=Bbox.from_extents(0.1,0.2,0.9,0.8)
231235
)
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+
fake_convertor.convert=Mock(side_effect=lambdav,u,a:0)
250+
# not used, here for completeness
251+
fake_convertor.default_units=Mock(side_effect=lambdav,a:None)
252+
fake_convertor.axisinfo=Mock(side_effect=lambdau,a:munits.AxisInfo())
253+
254+
munits.registry[FakeUnit]=fake_convertor
255+
256+
data= [[FakeUnit("yellow"),FakeUnit(42)],
257+
[FakeUnit(datetime.datetime(1968,8,1)),FakeUnit(True)]]
258+
259+
fig_test.subplots().table(data)
260+
fig_ref.subplots().table([["Hello","Hello"], ["Hello","Hello"]])
261+
fig_test.canvas.draw()
262+
fake_convertor.convert.assert_not_called()
263+
264+
munits.registry.pop(FakeUnit)
265+
assertnotmunits.registry.get_converter(FakeUnit)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp