diff options
author | Keewis <keewis@posteo.de> | 2021-08-17 18:18:21 +0200 |
---|---|---|
committer | Keewis <keewis@posteo.de> | 2021-08-17 18:18:21 +0200 |
commit | ad660f4a6592b30ab066c53e7645c4fcbd504dc4 (patch) | |
tree | d3e076e4b08e19b79cee245279434f44b6250529 /pint | |
parent | ae3ee9bf0c0e792f5442ef631aeb36858c793833 (diff) | |
download | pint-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.py | 13 |
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 = [] |