From e94f917226c566ea13e2f65ce9e68f977ede0f1e Mon Sep 17 00:00:00 2001 From: enkore Date: Sun, 4 Aug 2013 17:49:43 +0200 Subject: [PATCH] core.util.formatp add test for complex fields --- tests/test_core_util.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_core_util.py b/tests/test_core_util.py index 9ebf884..f40071c 100644 --- a/tests/test_core_util.py +++ b/tests/test_core_util.py @@ -263,6 +263,16 @@ class FormatPTests(unittest.TestCase): assert util.formatp("grml[{title}]") == "grml" assert util.formatp("[{t}]grml") == "grml" - def test_generic(self): + def test_side_by_side(self): s = "{status} [{artist} / [{album} / ]]{title}[ {song_elapsed}/{song_length}]" assert util.formatp(s, status="▷", title="Only For The Weak", song_elapsed="1:41", song_length="4:55") == "▷ Only For The Weak 1:41/4:55" + + def test_complex_field(self): + class NS: + pass + obj = NS() + obj.attr = "bar" + + s = "[{a:.3f} m]{obj.attr}" + assert util.formatp(s, a=3.14123456789, obj=obj) == "3.141 mbar" + assert util.formatp(s, a=0.0, obj=obj) == "bar"