mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
fixed a few instances of old-style string formatting
This commit is contained in:
@@ -80,8 +80,8 @@ class OrderedDict(dict, collections.MutableMapping):
|
||||
|
||||
def __repr__(self):
|
||||
if not self:
|
||||
return '%s()' % (self.__class__.__name__,)
|
||||
return '%s(%r)' % (self.__class__.__name__, list(self.items()))
|
||||
return '{0}()'.format(self.__class__.__name__,)
|
||||
return '{0}({1})'.format(self.__class__.__name__, repr(list(self.items())))
|
||||
|
||||
def copy(self):
|
||||
return self.__class__(self)
|
||||
|
||||
@@ -64,8 +64,8 @@ class OrderedDict(dict, MutableMapping):
|
||||
|
||||
def __repr__(self):
|
||||
if not self:
|
||||
return '%s()' % (self.__class__.__name__,)
|
||||
return '%s(%r)' % (self.__class__.__name__, list(self.items()))
|
||||
return '{0}()'.format(self.__class__.__name__,)
|
||||
return '{0}({1})'.format(self.__class__.__name__, repr(list(self.items())))
|
||||
|
||||
def copy(self):
|
||||
return self.__class__(self)
|
||||
|
||||
+51
-43
@@ -1,51 +1,59 @@
|
||||
"""Unit test for plural2.py
|
||||
"""Unit test for plural2.py"""
|
||||
|
||||
This program is part of "Dive Into Python", a free Python book for
|
||||
experienced programmers. Visit http://diveintopython.org/ for the
|
||||
latest version.
|
||||
"""
|
||||
|
||||
__author__ = "Mark Pilgrim (mark@diveintopython.org)"
|
||||
__version__ = "$Revision: 1.2 $"
|
||||
__date__ = "$Date: 2004/03/17 14:34:40 $"
|
||||
__copyright__ = "Copyright (c) 2004 Mark Pilgrim"
|
||||
__license__ = "Python"
|
||||
|
||||
from plural2 import plural
|
||||
import unittest, new
|
||||
import plural2
|
||||
import unittest
|
||||
|
||||
class KnownValues(unittest.TestCase):
|
||||
nouns = {'bass': 'basses',
|
||||
'bus': 'buses',
|
||||
'walrus': 'walruses',
|
||||
'box': 'boxes',
|
||||
'fax': 'faxes',
|
||||
'suffix': 'suffixes',
|
||||
'mailbox': 'mailboxes',
|
||||
'buzz': 'buzzes',
|
||||
'waltz': 'waltzes',
|
||||
'coach': 'coaches',
|
||||
'glitch': 'glitches',
|
||||
'rash': 'rashes',
|
||||
'watch': 'watches',
|
||||
'cheetah': 'cheetahs',
|
||||
'cough': 'coughs',
|
||||
'utility': 'utilities',
|
||||
'vacancy': 'vacancies',
|
||||
'boy': 'boys',
|
||||
'day': 'days',
|
||||
'computer': 'computers',
|
||||
'rock': 'rocks',
|
||||
'paper': 'papers',
|
||||
}
|
||||
def test_sxz(self):
|
||||
"words ending in S, X, and Z"
|
||||
nouns = {
|
||||
'bass': 'basses',
|
||||
'bus': 'buses',
|
||||
'walrus': 'walruses',
|
||||
'box': 'boxes',
|
||||
'fax': 'faxes',
|
||||
'suffix': 'suffixes',
|
||||
'mailbox': 'mailboxes',
|
||||
'buzz': 'buzzes',
|
||||
'waltz': 'waltzes'
|
||||
}
|
||||
for singular, plural in nouns.items():
|
||||
self.assertEqual(plural2.plural(singular), plural)
|
||||
|
||||
for noun, pluralnoun in KnownValues.nouns.items():
|
||||
func = lambda self, noun=noun, pluralnoun=pluralnoun: \
|
||||
KnownValues.failUnlessEqual(self, plural(noun), pluralnoun)
|
||||
func.__doc__ = "%s --> %s" % (noun, pluralnoun)
|
||||
instanceMethod = new.instancemethod(func, None, KnownValues)
|
||||
setattr(KnownValues, "test_%s" % noun, instanceMethod)
|
||||
def test_h(self):
|
||||
"words ending in H"
|
||||
nouns = {
|
||||
'coach': 'coaches',
|
||||
'glitch': 'glitches',
|
||||
'rash': 'rashes',
|
||||
'watch': 'watches',
|
||||
'cheetah': 'cheetahs',
|
||||
'cough': 'coughs'
|
||||
}
|
||||
for singular, plural in nouns.items():
|
||||
self.assertEqual(plural2.plural(singular), plural)
|
||||
|
||||
def test_y(self):
|
||||
"words ending in Y"
|
||||
nouns = {
|
||||
'utility': 'utilities',
|
||||
'vacancy': 'vacancies',
|
||||
'boy': 'boys',
|
||||
'day': 'days'
|
||||
}
|
||||
for singular, plural in nouns.items():
|
||||
self.assertEqual(plural2.plural(singular), plural)
|
||||
|
||||
def test_default(self):
|
||||
"unexceptional words"
|
||||
nouns = {
|
||||
'papaya': 'papayas',
|
||||
'whip': 'whips',
|
||||
'palimpsest': 'palimpsests'
|
||||
}
|
||||
for singular, plural in nouns.items():
|
||||
self.assertEqual(plural2.plural(singular), plural)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ FAILED (failures=1)</samp></pre>
|
||||
<a> if not s: <span>①</span></a>
|
||||
raise InvalidRomanNumeralError, 'Input can not be blank'
|
||||
if not re.search(romanNumeralPattern, s):
|
||||
raise InvalidRomanNumeralError, 'Invalid Roman numeral: %s' % s
|
||||
raise InvalidRomanNumeralError, 'Invalid Roman numeral: {0}'.format(s)
|
||||
|
||||
result = 0
|
||||
index = 0
|
||||
|
||||
Reference in New Issue
Block a user