summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorKeewis <keewis@posteo.de>2021-08-17 18:18:21 +0200
committerKeewis <keewis@posteo.de>2021-08-17 18:18:21 +0200
commitad660f4a6592b30ab066c53e7645c4fcbd504dc4 (patch)
treed3e076e4b08e19b79cee245279434f44b6250529 /pint
parentae3ee9bf0c0e792f5442ef631aeb36858c793833 (diff)
downloadpint-ad660f4a6592b30ab066c53e7645c4fcbd504dc4.tar.gz
add a test to check whether custom formats work with units
Diffstat (limited to 'pint')
-rw-r--r--pint/testsuite/test_unit.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/pint/testsuite/test_unit.py b/pint/testsuite/test_unit.py
index e55e90e..5b8ea5a 100644
--- a/pint/testsuite/test_unit.py
+++ b/pint/testsuite/test_unit.py
@@ -97,6 +97,19 @@ class TestUnit(QuantityTestCase):
ureg.default_format = spec
assert f"{x}" == result, f"Failed for {spec}, {result}"
+ def test_unit_formatting_custom(self, monkeypatch):
+ from pint import formatting, register_unit_format
+
+ monkeypatch.setattr(formatting, "_FORMATTERS", formatting._FORMATTERS.copy())
+
+ @register_unit_format("new")
+ def format_new(unit, **options):
+ return "new format"
+
+ ureg = UnitRegistry()
+
+ assert "{:new}".format(ureg.m) == "new format"
+
def test_ipython(self):
alltext = []