new format_str option in vfield

This commit is contained in:
Benoît Sierro
2024-01-24 15:24:37 +01:00
parent 4e22d70193
commit 820dbbdea5
2 changed files with 30 additions and 2 deletions

View File

@@ -292,6 +292,21 @@ def test_unit_forammter():
assert fmt(np.zeros((2, 2, 2))) == "(((0, 0), (0, 0)), ((0, 0), (0, 0)))"
def test_format_str():
"""format_str takes precedence"""
@vdataclass
class Conf:
x: Variable = vfield(default=123456789)
y: Variable = vfield(default=123456789, decimals=2)
z: Variable = vfield(default=123456789, decimals=2, format_str="d")
conf = Conf()
assert conf.x.format(0) == "x=1.235e+08"
assert conf.y.format(0) == "y=1.2e+08"
assert conf.z.format(0) == "z=123456789"
def test_param_formatting():
"""formatting is always respected"""