diff options
Diffstat (limited to 'pint/testsuite/test_formatting.py')
-rw-r--r-- | pint/testsuite/test_formatting.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pint/testsuite/test_formatting.py b/pint/testsuite/test_formatting.py index d287948..48e770b 100644 --- a/pint/testsuite/test_formatting.py +++ b/pint/testsuite/test_formatting.py @@ -52,3 +52,18 @@ def test_split_format(format, default, flag, expected): result = fmt.split_format(format, default, flag) assert result == expected + + +def test_register_unit_format(func_registry): + @fmt.register_unit_format("custom") + def format_custom(unit, registry, **options): + return "<formatted unit>" + + quantity = 1.0 * func_registry.meter + assert f"{quantity:custom}" == "1.0 <formatted unit>" + + with pytest.raises(ValueError, match="format 'custom' already exists"): + + @fmt.register_unit_format("custom") + def format_custom_redefined(unit, registry, **options): + return "<overwritten>" |