From 24ec8bac8dc3a7a64c8632f98824679f953585c9 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sat, 9 Apr 2022 23:05:16 +0200 Subject: add a few more tests to make sure quantity uses the setting --- pint/testsuite/test_quantity.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index f4f6806..b3bb8e7 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -5,6 +5,7 @@ import math import operator as op import pickle import warnings +from contextlib import contextmanager from unittest.mock import patch import pytest @@ -21,6 +22,14 @@ from pint.testsuite import QuantityTestCase, helpers from pint.unit import UnitsContainer +@contextmanager +def assert_no_warnings(): + with warnings.catch_warnings(): + warnings.simplefilter("error") + + yield + + class FakeWrapper: # Used in test_upcast_type_rejection_on_creation def __init__(self, q): @@ -272,6 +281,10 @@ class TestQuantity(QuantityTestCase): with pytest.warns(DeprecationWarning): assert f"{x:d}" == "4 meter ** 2" + ureg.separate_format_defaults = True + with assert_no_warnings(): + assert f"{x:d}" == "4 m ** 2" + def test_formatting_override_default_magnitude(self): ureg = UnitRegistry() ureg.default_format = ".2f" @@ -281,6 +294,10 @@ class TestQuantity(QuantityTestCase): with pytest.warns(DeprecationWarning): assert f"{x:D}" == "4 meter ** 2" + ureg.separate_format_defaults = True + with assert_no_warnings(): + assert f"{x:D}" == "4.00 meter ** 2" + def test_exponent_formatting(self): ureg = UnitRegistry() x = ureg.Quantity(1e20, "meter") -- cgit v1.2.1