From b40a67c34bcd3a13939f1463dfc9300a35114f6d Mon Sep 17 00:00:00 2001 From: hannah Date: Thu, 28 Sep 2023 16:14:04 -0400 Subject: [PATCH] test that table uses repr and doesn't try to convert unitized data Co-authored-by: Elliott Sales de Andrade Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --- lib/matplotlib/tests/test_table.py | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/matplotlib/tests/test_table.py b/lib/matplotlib/tests/test_table.py index 328fd020c1ee..ea31ac124e4a 100644 --- a/lib/matplotlib/tests/test_table.py +++ b/lib/matplotlib/tests/test_table.py @@ -1,3 +1,6 @@ +import datetime +from unittest.mock import Mock + import numpy as np import pytest @@ -7,6 +10,7 @@ from matplotlib.table import CustomCell, Table from matplotlib.testing.decorators import image_comparison, check_figures_equal from matplotlib.transforms import Bbox +import matplotlib.units as munits def test_non_square(): @@ -229,3 +233,34 @@ def test_table_bbox(fig_test, fig_ref): loc='center', bbox=Bbox.from_extents(0.1, 0.2, 0.9, 0.8) ) + + +@check_figures_equal(extensions=['png']) +def test_table_unit(fig_test, fig_ref): + # test that table doesn't participate in unit machinery, instead uses repr/str + + class FakeUnit: + def __init__(self, thing): + pass + def __repr__(self): + return "Hello" + + fake_convertor = munits.ConversionInterface() + # v, u, a = value, unit, axis + fake_convertor.convert = Mock(side_effect=lambda v, u, a: 0) + # not used, here for completeness + fake_convertor.default_units = Mock(side_effect=lambda v, a: None) + fake_convertor.axisinfo = Mock(side_effect=lambda u, a: munits.AxisInfo()) + + munits.registry[FakeUnit] = fake_convertor + + data = [[FakeUnit("yellow"), FakeUnit(42)], + [FakeUnit(datetime.datetime(1968, 8, 1)), FakeUnit(True)]] + + fig_test.subplots().table(data) + fig_ref.subplots().table([["Hello", "Hello"], ["Hello", "Hello"]]) + fig_test.canvas.draw() + fake_convertor.convert.assert_not_called() + + munits.registry.pop(FakeUnit) + assert not munits.registry.get_converter(FakeUnit) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy