summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorMartijn Pieters <github.com@zopatista.com>2017-02-27 16:07:27 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2017-02-27 16:07:27 (GMT)
commitbc144f0abff2b36595171377ee847c0266596ab2 (patch)
tree2455d1bd789d8a78d0e1384b8cf6850bed05a914 /Lib/test/test_unicode.py
parentb945e0784f8b64f9dba41c47844cadf483168a0f (diff)
downloadcpython-bc144f0abff2b36595171377ee847c0266596ab2.zip
cpython-bc144f0abff2b36595171377ee847c0266596ab2.tar.gz
cpython-bc144f0abff2b36595171377ee847c0266596ab2.tar.bz2
bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (#94)
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 3136ea1..9dbded2 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1424,6 +1424,15 @@ class UnicodeTest(string_tests.CommonTest,
with self.assertRaises(ValueError):
result = format_string % 2.34
+ def test_issue28598_strsubclass_rhs(self):
+ # A subclass of str with an __rmod__ method should be able to hook
+ # into the % operator
+ class SubclassedStr(str):
+ def __rmod__(self, other):
+ return 'Success, self.__rmod__({!r}) was called'.format(other)
+ self.assertEqual('lhs %% %r' % SubclassedStr('rhs'),
+ "Success, self.__rmod__('lhs %% %r') was called")
+
@support.cpython_only
def test_formatting_huge_precision_c_limits(self):
from _testcapi import INT_MAX