Kaydet (Commit) 84e19f71 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

improve tests

üst 26f1dc60
...@@ -1215,9 +1215,7 @@ class UserString(_collections_abc.Sequence): ...@@ -1215,9 +1215,7 @@ class UserString(_collections_abc.Sequence):
def __mod__(self, args): def __mod__(self, args):
return self.__class__(self.data % args) return self.__class__(self.data % args)
def __rmod__(self, template): def __rmod__(self, template):
if isinstance(template, str): return self.__class__(str(template) % self)
return self.__class__(template % self)
return NotImplemented
# the following methods are defined in alphabetical order: # the following methods are defined in alphabetical order:
def capitalize(self): return self.__class__(self.data.capitalize()) def capitalize(self): return self.__class__(self.data.capitalize())
def casefold(self): def casefold(self):
......
...@@ -71,10 +71,17 @@ class TestUserObjects(unittest.TestCase): ...@@ -71,10 +71,17 @@ class TestUserObjects(unittest.TestCase):
self._copy_test(obj) self._copy_test(obj)
def test_str_rmod(self): def test_str_rmod(self):
arg = UserString("python") class ustr2(UserString):
template = "I love %s" pass
self.assertEqual(arg.__rmod__(template), "I love python")
self.assertIs(arg.__rmod__(type('Dummy', (), {})), NotImplemented)
class ustr3(ustr2):
def __rmod__(self, other):
return super().__rmod__(other)
fmt2 = ustr2('value is %s')
str3 = ustr3('TEST')
self.assertEqual(fmt2 % str3, 'value is TEST')
################################################################################ ################################################################################
### ChainMap (helper class for configparser and the string module) ### ChainMap (helper class for configparser and the string module)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment