summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeewis <keewis@posteo.de>2022-04-09 23:19:59 +0200
committerKeewis <keewis@posteo.de>2022-04-09 23:19:59 +0200
commita4c2279e9dba75fe07213c08371e62e415d11a9b (patch)
tree91011d3ba5ef9e75655c7e005bcde0ef31fba8e4
parent24ec8bac8dc3a7a64c8632f98824679f953585c9 (diff)
downloadpint-a4c2279e9dba75fe07213c08371e62e415d11a9b.tar.gz
same for the units (although the magnitude format is ignored)
-rw-r--r--pint/testsuite/__init__.py10
-rw-r--r--pint/testsuite/test_quantity.py11
-rw-r--r--pint/testsuite/test_unit.py14
3 files changed, 24 insertions, 11 deletions
diff --git a/pint/testsuite/__init__.py b/pint/testsuite/__init__.py
index 35b6c89..8c0cd09 100644
--- a/pint/testsuite/__init__.py
+++ b/pint/testsuite/__init__.py
@@ -2,6 +2,8 @@ import doctest
import math
import os
import unittest
+import warnings
+from contextlib import contextmanager
from pint import UnitRegistry
from pint.testsuite.helpers import PintOutputChecker
@@ -23,6 +25,14 @@ class QuantityTestCase:
cls.U_ = None
+@contextmanager
+def assert_no_warnings():
+ with warnings.catch_warnings():
+ warnings.simplefilter("error")
+
+ yield
+
+
def testsuite():
"""A testsuite that has all the pint tests."""
suite = unittest.TestLoader().discover(os.path.dirname(__file__))
diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py
index b3bb8e7..196d0c3 100644
--- a/pint/testsuite/test_quantity.py
+++ b/pint/testsuite/test_quantity.py
@@ -5,7 +5,6 @@ import math
import operator as op
import pickle
import warnings
-from contextlib import contextmanager
from unittest.mock import patch
import pytest
@@ -18,18 +17,10 @@ from pint import (
get_application_registry,
)
from pint.compat import np
-from pint.testsuite import QuantityTestCase, helpers
+from pint.testsuite import QuantityTestCase, assert_no_warnings, 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):
diff --git a/pint/testsuite/test_unit.py b/pint/testsuite/test_unit.py
index 992551c..e6ce581 100644
--- a/pint/testsuite/test_unit.py
+++ b/pint/testsuite/test_unit.py
@@ -15,7 +15,7 @@ from pint import (
)
from pint.compat import np
from pint.registry import LazyRegistry, UnitRegistry
-from pint.testsuite import QuantityTestCase, helpers
+from pint.testsuite import QuantityTestCase, assert_no_warnings, helpers
from pint.util import ParserHelper, UnitsContainer
@@ -80,6 +80,18 @@ class TestUnit(QuantityTestCase):
ureg.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, {result}"
+ def test_unit_formatting_defaults_warning(self):
+ ureg = UnitRegistry()
+ ureg.default_format = "~P"
+ x = ureg.Unit("m / s ** 2")
+
+ with pytest.warns(DeprecationWarning):
+ assert f"{x:.2f}" == "meter / second ** 2"
+
+ ureg.separate_format_defaults = True
+ with assert_no_warnings():
+ assert f"{x:.2f}" == "m/s²"
+
def test_unit_formatting_snake_case(self, subtests):
# Test that snake_case units are escaped where appropriate
ureg = UnitRegistry()