summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeewis <keewis@posteo.de>2022-04-09 23:05:16 +0200
committerKeewis <keewis@posteo.de>2022-04-09 23:05:16 +0200
commit24ec8bac8dc3a7a64c8632f98824679f953585c9 (patch)
treeef9d6d66d52817af96465d532dbbcf3f0af3e6cd
parentc477292113e2b88f6084e5b010e4fc9459765dc4 (diff)
downloadpint-24ec8bac8dc3a7a64c8632f98824679f953585c9.tar.gz
add a few more tests to make sure quantity uses the setting
-rw-r--r--pint/testsuite/test_quantity.py17
1 files changed, 17 insertions, 0 deletions
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")