summaryrefslogtreecommitdiff
path: root/tests/test_messages.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_messages.py')
-rw-r--r--tests/test_messages.py35
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')
+
+