summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-08-31 17:18:55 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-08-31 17:18:55 (GMT)
commitfb13721b1b48b814dd8efbececfbb1e6c52c1c5d (patch)
tree05bf8cb54ec4ae89548f481b074fea3ab4267bc5 /Lib/test/test_unicode.py
parent08548f4a750b6f378c58decdcaf2ac6778103fe1 (diff)
downloadcpython-fb13721b1b48b814dd8efbececfbb1e6c52c1c5d.zip
cpython-fb13721b1b48b814dd8efbececfbb1e6c52c1c5d.tar.gz
cpython-fb13721b1b48b814dd8efbececfbb1e6c52c1c5d.tar.bz2
Close #18780: %-formatting now prints value for int subclasses with %d, %i, and %u codes.
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 9e53213..daab79d 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1124,6 +1124,53 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual('%.1s' % "a\xe9\u20ac", 'a')
self.assertEqual('%.2s' % "a\xe9\u20ac", 'a\xe9')
+ def test_formatting_with_enum(self):
+ # issue18780
+ import enum
+ class Float(float, enum.Enum):
+ PI = 3.1415926
+ class Int(enum.IntEnum):
+ IDES = 15
+ class Str(str, enum.Enum):
+ ABC = 'abc'
+ # Testing Unicode formatting strings...
+ self.assertEqual(
+ "%s, %s" % (Str.ABC, Str.ABC),
+ 'Str.ABC, Str.ABC',
+ )
+ self.assertEqual(
+ "%s, %s, %d, %i, %u, %f, %5.2f" %
+ (Str.ABC, Str.ABC,
+ Int.IDES, Int.IDES, Int.IDES,
+ Float.PI, Float.PI),
+ 'Str.ABC, Str.ABC, 15, 15, 15, 3.141593, 3.14')
+
+ # formatting jobs delegated from the string implementation:
+ self.assertEqual(
+ '...%(foo)s...' % {'foo':Str.ABC},
+ '...Str.ABC...',
+ )
+ self.assertEqual(
+ '...%(foo)s...' % {'foo':Int.IDES},
+ '...Int.IDES...',
+ )
+ self.assertEqual(
+ '...%(foo)i...' % {'foo':Int.IDES},
+ '...15...',
+ )
+ self.assertEqual(
+ '...%(foo)d...' % {'foo':Int.IDES},
+ '...15...',
+ )
+ self.assertEqual(
+ '...%(foo)u...' % {'foo':Int.IDES, 'def':Float.PI},
+ '...15...',
+ )
+ self.assertEqual(
+ '...%(foo)f...' % {'foo':Float.PI,'def':123},
+ '...3.141593...',
+ )
+
@support.cpython_only
def test_formatting_huge_precision(self):
from _testcapi import INT_MAX