diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-01-24 10:59:31 +0000 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-01-24 10:59:31 +0000 |
commit | d108c4c729ac945d48ca4b9d5ebeb5f790d3d983 (patch) | |
tree | 53a0aa33a4366041da56138c07c652d8f4cc12f8 /tests/test_messages.py | |
parent | 14f26112d8088fa84072b3c0a18878ead768bd69 (diff) | |
download | logutils-d108c4c729ac945d48ca4b9d5ebeb5f790d3d983.tar.gz |
More changes for 0.3.
Diffstat (limited to 'tests/test_messages.py')
-rw-r--r-- | tests/test_messages.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_messages.py b/tests/test_messages.py new file mode 100644 index 0000000..6ceed42 --- /dev/null +++ b/tests/test_messages.py @@ -0,0 +1,35 @@ +import logutils +import sys +import unittest + +class MessageTest(unittest.TestCase): + if sys.version_info[:2] >= (2, 6): + def test_braces(self): + "Test whether brace-formatting works." + __ = logutils.BraceMessage + m = __('Message with {0} {1}', 2, 'placeholders') + self.assertEqual(str(m), 'Message with 2 placeholders') + m = __('Message with {0:d} {1}', 2, 'placeholders') + self.assertEqual(str(m), 'Message with 2 placeholders') + m = __('Message without {0:x} {1}', 16, 'placeholders') + self.assertEqual(str(m), 'Message without 10 placeholders') + + class Dummy: + pass + + dummy = Dummy() + dummy.x, dummy.y = 0.0, 1.0 + m = __('Message with coordinates: ({point.x:.2f}, {point.y:.2f})', + point=dummy) + self.assertEqual(str(m), 'Message with coordinates: (0.00, 1.00)') + + def test_dollars(self): + "Test whether dollar-formatting works." + __ = logutils.DollarMessage + m = __('Message with $num ${what}', num=2, what='placeholders') + self.assertEqual(str(m), 'Message with 2 placeholders') + ignored = object() + self.assertRaises(TypeError, __, 'Message with $num ${what}', + ignored, num=2, what='placeholders') + + |