[pypy-svn] r71995 - in pypy/release/1.2.x: lib-python/modified-2.5.2/test lib-python/modified-2.5.2/test/output pypy/objspace/std pypy/objspace/std/test

arigo at codespeak.net arigo at codespeak.net
Tue Mar 9 19:44:44 CET 2010


Author: arigo
Date: Tue Mar  9 19:44:43 2010
New Revision: 71995

Added:
   pypy/release/1.2.x/lib-python/modified-2.5.2/test/output/test_format
      - copied unchanged from r71994, pypy/trunk/lib-python/modified-2.5.2/test/output/test_format
Modified:
   pypy/release/1.2.x/lib-python/modified-2.5.2/test/regrtest.py
   pypy/release/1.2.x/lib-python/modified-2.5.2/test/test_format.py
   pypy/release/1.2.x/pypy/objspace/std/formatting.py
   pypy/release/1.2.x/pypy/objspace/std/test/test_stringformat.py
Log:
svn merge svn+ssh://codespeak.net/svn/pypy/trunk -r71986:71994


Modified: pypy/release/1.2.x/lib-python/modified-2.5.2/test/regrtest.py
==============================================================================
--- pypy/release/1.2.x/lib-python/modified-2.5.2/test/regrtest.py	(original)
+++ pypy/release/1.2.x/lib-python/modified-2.5.2/test/regrtest.py	Tue Mar  9 19:44:43 2010
@@ -491,8 +491,13 @@
 
 def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
     """Return a list of all applicable test modules."""
-    if not testdir: testdir = findtestdir()
-    names = os.listdir(testdir)
+    if testdir:
+        testdirs = [testdir]
+    else:
+        testdirs = findtestdirs()
+    names = {}
+    for testdir in testdirs:
+        names.update(dict.fromkeys(os.listdir(testdir)))
     tests = []
     for name in names:
         if name[:5] == "test_" and name[-3:] == os.extsep+"py":
@@ -529,10 +534,18 @@
 def runtest_inner(test, generate, verbose, quiet,
                      testdir=None, huntrleaks=False):
     test_support.unload(test)
-    if not testdir:
-        testdir = findtestdir()
-    outputdir = os.path.join(testdir, "output")
-    outputfile = os.path.join(outputdir, test)
+    if testdir:
+        testdirs = [testdir]
+    else:
+        testdirs = findtestdirs()
+    outputfiles = []
+    for testdir in testdirs:
+        outputdir = os.path.join(testdir, "output")
+        outputfile = os.path.join(outputdir, test)
+        if os.path.exists(outputfile):
+            outputfiles.append(outputfile)
+    if outputfiles:
+        outputfile = outputfiles[-1]
     if verbose:
         cfp = None
     else:
@@ -763,13 +776,23 @@
 
     print "*" * 70
 
-def findtestdir():
+def findtestdirs():
+    # XXX hacking: returns a list of both the '2.5.2/test' and the
+    # 'modified-2.5.2/test' directories, as full paths.
     if __name__ == '__main__':
         file = sys.argv[0]
     else:
         file = __file__
-    testdir = os.path.dirname(file) or os.curdir
-    return testdir
+    testdir = os.path.abspath(os.path.dirname(file) or os.curdir)
+    assert os.path.basename(testdir).lower() == 'test'
+    maindir = os.path.dirname(testdir)
+    libpythondir = os.path.dirname(maindir)
+    maindirname = os.path.basename(maindir).lower()
+    if maindirname.startswith('modified-'):
+        maindirname = maindirname[len('modified-'):]
+    testdir1 = os.path.join(libpythondir, maindirname, 'test')
+    testdir2 = os.path.join(libpythondir, 'modified-'+maindirname, 'test')
+    return [testdir1, testdir2]
 
 def removepy(name):
     if name.endswith(os.extsep + "py"):

Modified: pypy/release/1.2.x/lib-python/modified-2.5.2/test/test_format.py
==============================================================================
--- pypy/release/1.2.x/lib-python/modified-2.5.2/test/test_format.py	(original)
+++ pypy/release/1.2.x/lib-python/modified-2.5.2/test/test_format.py	Tue Mar  9 19:44:43 2010
@@ -216,7 +216,7 @@
     try:
         testformat(formatstr, args)
     except exception, exc:
-        if str(exc) == excmsg:
+        if excmsg is None or str(exc) == excmsg:
             if verbose:
                 print "yes"
         else:
@@ -235,8 +235,9 @@
     test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError,
              "unsupported format character '?' (0x3000) at index 5")
 
-test_exc('%d', '1', TypeError, "int argument required")
-test_exc('%g', '1', TypeError, "float argument required")
+# the exact error message may vary in the next two examples
+test_exc('%d', '1', TypeError, None)  # "int argument required"
+test_exc('%g', '1', TypeError, None)  # "float argument required"
 test_exc('no format', '1', TypeError,
          "not all arguments converted during string formatting")
 test_exc('no format', u'1', TypeError,

Modified: pypy/release/1.2.x/pypy/objspace/std/formatting.py
==============================================================================
--- pypy/release/1.2.x/pypy/objspace/std/formatting.py	(original)
+++ pypy/release/1.2.x/pypy/objspace/std/formatting.py	Tue Mar  9 19:44:43 2010
@@ -38,7 +38,7 @@
                space.wrap('not all arguments converted '
                             'during string formatting'))
 
-    def std_wp_int(self, r, prefix=''):
+    def std_wp_int(self, r, prefix='', keep_zero=False):
         # use self.prec to add some '0' on the left of the number
         if self.prec >= 0:
             sign = r[0] == '-'
@@ -48,7 +48,7 @@
                     r = '-' + '0'*padding + r[1:]
                 else:
                     r = '0'*padding + r
-            elif self.prec == 0 and r == '0':
+            elif self.prec == 0 and r == '0' and not keep_zero:
                 r = ''
         self.std_wp_number(r, prefix)
 
@@ -78,11 +78,15 @@
     def fmt_o(self, w_value):
         "oct formatting"
         r = oct_num_helper(self.space, w_value)
-        if self.f_alt and (r != '0' or self.prec == 0):
-            prefix = '0'
-        else:
-            prefix = ''
-        self.std_wp_int(r, prefix)
+        keep_zero = False
+        if self.f_alt:
+            if r == '0':
+                keep_zero = True
+            elif r.startswith('-'):
+                r = '-0' + r[1:]
+            else:
+                r = '0' + r
+        self.std_wp_int(r, keep_zero=keep_zero)
 
     fmt_i = fmt_d
     fmt_u = fmt_d
@@ -318,7 +322,7 @@
             else:
                 s = c
             msg = "unsupported format character '%s' (0x%x) at index %d" % (
-                s, ord(c), self.fmtpos)
+                s, ord(c), self.fmtpos - 1)
             raise OperationError(space.w_ValueError, space.wrap(msg))
 
         def std_wp(self, r):

Modified: pypy/release/1.2.x/pypy/objspace/std/test/test_stringformat.py
==============================================================================
--- pypy/release/1.2.x/pypy/objspace/std/test/test_stringformat.py	(original)
+++ pypy/release/1.2.x/pypy/objspace/std/test/test_stringformat.py	Tue Mar  9 19:44:43 2010
@@ -15,7 +15,8 @@
         assert 'a23b23c' == 'a%(i)sb%(i)sc' % d
 
     def test_format_percent(self):
-        assert 'a%b' == 'a%%b' % {} 
+        d = {}
+        assert 'a%b' == 'a%%b' % d
 
     def test_format_empty_key(self):
         d = {'':42}
@@ -30,8 +31,10 @@
         raises(KeyError, 'a%(x)sb'.__mod__, d) 
 
     def test_format_error(self):
-        assert '' % {} == ''
-        raises(TypeError, "'' % 5")
+        d = {}
+        assert '' % d == ''
+        n = 5
+        raises(TypeError, "'' % n")
         class MyMapping(object):
             def __getitem__(self, key):
                 py.test.fail('should not be here')
@@ -45,16 +48,18 @@
 class AppTestStringObject:
 
     def test_format_item(self):
-        assert 'a23b' == 'a%sb' % 23
-        assert '23b' == '%sb' % 23
-        assert 'a23' == 'a%s' % 23
-        assert '23' == '%s' % 23
+        n = 23
+        assert 'a23b' == 'a%sb' % n
+        assert '23b' == '%sb' % n
+        assert 'a23' == 'a%s' % n
+        assert '23' == '%s' % n
 
     def test_format_percent(self):
-        assert 'a%b' == 'a%%b' % ()
-        assert '%b' == '%%b' % ()
-        assert 'a%' == 'a%%' % ()
-        assert '%' == '%%' % ()
+        t = ()
+        assert 'a%b' == 'a%%b' % t
+        assert '%b' == '%%b' % t
+        assert 'a%' == 'a%%' % t
+        assert '%' == '%%' % t
 
     def test_format_too_much(self):
         raises(TypeError, '%s%s'.__mod__, ())
@@ -65,47 +70,69 @@
         raises(TypeError, '%s%s'.__mod__, (23,)*4)
 
     def test_format_string(self):
-        assert '23' == '%s' % '23'
-        assert "'23'" == '%r' % '23'
-        raises(TypeError, '%d'.__mod__, "23")
+        s = '23'
+        assert '23' == '%s' % s
+        assert "'23'" == '%r' % s
+        raises(TypeError, '%d'.__mod__, s)
 
     def test_format_float(self):
-        assert '23' == '%d' % 23.456
-        assert '17' == '%x' % 23.456
-        assert '23.456' == '%s' % 23.456
+        f = 23.456
+        assert '23' == '%d' % f
+        assert '17' == '%x' % f
+        assert '23.456' == '%s' % f
         # for 'r' use a float that has an exact decimal rep:
-        assert '23.125' == '%r' % 23.125
-        assert '0.028' == '%.3f' % 0.0276    # should work on most platforms...
-        assert '   inf' == '%6g' % (1E200 * 1E200)
+        g = 23.125
+        assert '23.125' == '%r' % g
+        h = 0.0276
+        assert '0.028' == '%.3f' % h    # should work on most platforms...
+        big = 1E200
+        assert '   inf' == '%6g' % (big * big)
 
     def test_format_int(self):
         import sys
-        assert '23' == '%d' % 23
-        assert '17' == '%x' % 23
-        assert '0x17' == '%#x' % 23
-        assert '0x0' == '%#x' % 0
-        assert '23' == '%s' % 23
-        assert '23' == '%r' % 23
+        n = 23
+        z = 0
+        assert '23' == '%d' % n
+        assert '17' == '%x' % n
+        assert '0x17' == '%#x' % n
+        assert '0x0' == '%#x' % z
+        assert '23' == '%s' % n
+        assert '23' == '%r' % n
         assert ('%d' % (-sys.maxint-1,) == '-' + str(sys.maxint+1)
                                         == '-%d' % (sys.maxint+1,))
-        assert '1C' == '%X' % 28
-        assert '0X1C' == '%#X' % 28
-        assert '10' == '%o' % 8
-        assert '010' == '%#o' % 8
-        assert '-010' == '%#o' % -8
-        assert '0' == '%o' % 0
-        assert '0' == '%#o' % 0
-
-        assert '-0x017' == '%#06x' % -23
-        assert '0' == '%#.0o' % 0
+        n = 28
+        m = 8
+        assert '1C' == '%X' % n
+        assert '0X1C' == '%#X' % n
+        assert '10' == '%o' % m
+        assert '010' == '%#o' % m
+        assert '-010' == '%#o' % -m
+        assert '0' == '%o' % z
+        assert '0' == '%#o' % z
+
+        n = 23
+        f = 5
+        assert '-0x017' == '%#06x' % -n
+        assert '' == '%.0o' % z
+        assert '0' == '%#.0o' % z
+        assert '5' == '%.0o' % f
+        assert '05' == '%#.0o' % f
+        assert '000' == '%.3o' % z
+        assert '000' == '%#.3o' % z
+        assert '005' == '%.3o' % f
+        assert '005' == '%#.3o' % f
+        assert '27' == '%.2o' % n
+        assert '027' == '%#.2o' % n
 
     def test_format_list(self):
-        assert '<[1, 2]>' == '<%s>' % [1,2]
-        assert '<[1, 2]-[3, 4]>' == '<%s-%s>' % ([1,2], [3,4])
+        l = [1,2]
+        assert '<[1, 2]>' == '<%s>' % l
+        assert '<[1, 2]-[3, 4]>' == '<%s-%s>' % (l, [3,4])
 
     def test_format_tuple(self):
-        assert '<(1, 2)>' == '<%s>' % ((1,2),)
-        assert '<(1, 2)-(3, 4)>' == '<%s-%s>' % ((1,2), (3,4))
+        t = (1,2)
+        assert '<(1, 2)>' == '<%s>' % (t,)
+        assert '<(1, 2)-(3, 4)>' == '<%s-%s>' % (t, (3,4))
 
     def test_format_dict(self):
 
@@ -119,9 +146,10 @@
         #     \character{\%} character.
 
         # It is what CPython *does*, however.  All software sucks.
-        
-        assert '<{1: 2}>' == '<%s>' % {1:2}
-        assert '<{1: 2}-{3: 4}>' == '<%s-%s>' % ({1:2}, {3:4})
+
+        d = {1:2}
+        assert '<{1: 2}>' == '<%s>' % d
+        assert '<{1: 2}-{3: 4}>' == '<%s-%s>' % (d, {3:4})
 
     def test_format_wrong_char(self):
         raises(ValueError, 'a%Zb'.__mod__, ((23,),))
@@ -132,8 +160,10 @@
 
     def test_format_char(self):
         import sys
-        assert '%c' % 65 == 'A'
-        assert '%c' % 'e' == 'e'
+        A = 65
+        e = 'e'
+        assert '%c' % A == 'A'
+        assert '%c' % e == 'e'
         raises(OverflowError, '%c'.__mod__, (256,))
         raises(OverflowError, '%c'.__mod__, (-1,))
         raises(OverflowError, u'%c'.__mod__, (sys.maxunicode+1,))
@@ -143,52 +173,63 @@
 
 class AppTestWidthPrec:
     def test_width(self):
-        assert "%3s" %'a' == '  a'
-        assert "%-3s"%'a' == 'a  '
+        a = 'a'
+        assert "%3s" % a == '  a'
+        assert "%-3s"% a == 'a  '
 
     def test_prec_cornercase(self):
-        assert "%.0x" % 0 == ''
-        assert "%.x" % 0 == ''
-        assert "%.0d" % 0 == ''
-        assert "%.i" % 0 == ''
-        assert "%.0o" % 0 == ''
-        assert "%.o" % 0 == ''
+        z = 0
+        assert "%.0x" % z == ''
+        assert "%.x" % z == ''
+        assert "%.0d" % z == ''
+        assert "%.i" % z == ''
+        assert "%.0o" % z == ''
+        assert "%.o" % z == ''
 
     def test_prec_string(self):
-        assert "%.3s"%'a' ==     'a'
-        assert "%.3s"%'abcde' == 'abc'
+        a = 'a'
+        abcde = 'abcde'
+        assert "%.3s"% a ==     'a'
+        assert "%.3s"% abcde == 'abc'
 
     def test_prec_width_string(self):
-        assert "%5.3s" %'a' ==     '    a'
-        assert "%5.3s" %'abcde' == '  abc'
-        assert "%-5.3s"%'a' ==     'a    '
-        assert "%-5.3s"%'abcde' == 'abc  '
+        a = 'a'
+        abcde = 'abcde'
+        assert "%5.3s" % a ==     '    a'
+        assert "%5.3s" % abcde == '  abc'
+        assert "%-5.3s"% a ==     'a    '
+        assert "%-5.3s"% abcde == 'abc  '
 
     def test_zero_pad(self):
-        assert "%02d"%1 ==   "01"
-        assert "%05d"%1 ==   "00001"
-        assert "%-05d"%1 ==  "1    "
-        assert "%04f"%2.25 == "2.250000"
-        assert "%05g"%2.25 == "02.25"
-        assert "%-05g"%2.25 =="2.25 "
-        assert "%05s"%2.25 == " 2.25"
+        one = 1
+        ttf = 2.25
+        assert "%02d" % one ==   "01"
+        assert "%05d" % one ==   "00001"
+        assert "%-05d" % one ==  "1    "
+        assert "%04f" % ttf == "2.250000"
+        assert "%05g" % ttf == "02.25"
+        assert "%-05g" % ttf =="2.25 "
+        assert "%05s" % ttf == " 2.25"
 
         
     def test_star_width(self):
-        assert "%*s" %( 5, 'abc') ==  '  abc'
-        assert "%*s" %(-5, 'abc') ==  'abc  '
-        assert "%-*s"%( 5, 'abc') ==  'abc  '
-        assert "%-*s"%(-5, 'abc') ==  'abc  '
+        f = 5
+        assert "%*s" %( f, 'abc') ==  '  abc'
+        assert "%*s" %(-f, 'abc') ==  'abc  '
+        assert "%-*s"%( f, 'abc') ==  'abc  '
+        assert "%-*s"%(-f, 'abc') ==  'abc  '
 
     def test_star_prec(self):
-        assert "%.*s"%( 3, 'abc') ==  'abc'
-        assert "%.*s"%( 3, 'abcde') ==  'abc'
-        assert "%.*s"%(-3, 'abc') ==  ''
+        t = 3
+        assert "%.*s"%( t, 'abc') ==  'abc'
+        assert "%.*s"%( t, 'abcde') ==  'abc'
+        assert "%.*s"%(-t, 'abc') ==  ''
 
     def test_star_width_prec(self):
-        assert "%*.*s"%( 5, 3, 'abc') ==    '  abc'
-        assert "%*.*s"%( 5, 3, 'abcde') ==  '  abc'
-        assert "%*.*s"%(-5, 3, 'abcde') ==  'abc  '
+        f = 5
+        assert "%*.*s"%( f, 3, 'abc') ==    '  abc'
+        assert "%*.*s"%( f, 3, 'abcde') ==  '  abc'
+        assert "%*.*s"%(-f, 3, 'abcde') ==  'abc  '
 
     def test_too_long(self):
         def f(fmt, x):
@@ -206,7 +247,8 @@
 
 class AppTestUnicodeObject:
     def test_unicode_convert(self):
-        assert isinstance("%s" % (u"x"), unicode)
+        u = u"x"
+        assert isinstance("%s" % u, unicode)
 
     def test_unicode_nonascii(self):
         """
@@ -214,12 +256,14 @@
         a string format should decode the format string as ascii and return
         unicode.
         """
-        result = "%s" % u'\x80'
+        u = u'\x80'
+        result = "%s" % u
         assert isinstance(result, unicode)
-        assert result == u'\x80'
+        assert result == u
 
     def test_unicode_d(self):
-        assert u"%.1d" % 3 == '3'
+        t = 3
+        assert u"%.1d" % t == '3'
 
     def test_unicode_overflow(self):
         skip("nicely passes on top of CPython but requires > 2GB of RAM")
@@ -227,14 +271,18 @@
         raises((OverflowError, MemoryError), 'u"%.*d" % (sys.maxint, 1)')
 
     def test_unicode_format_a(self):
-        assert u'%x' % 10L == 'a'
+        ten = 10L
+        assert u'%x' % ten == 'a'
 
     def test_long_no_overflow(self):
-        assert "%x" % 100000000000L == "174876e800"
+        big = 100000000000L
+        assert "%x" % big == "174876e800"
 
     def test_missing_cases(self):
-        print '%032d' % -123456789012345678901234567890L
-        assert '%032d' % -123456789012345678901234567890L == '-0123456789012345678901234567890'
+        big = -123456789012345678901234567890L
+        print '%032d' % big
+        assert '%032d' % big == '-0123456789012345678901234567890'
 
     def test_invalid_char(self):
-        raises(ValueError, 'u"%\u1234" % (4,)')
+        f = 4
+        raises(ValueError, 'u"%\u1234" % (f,)')



More information about the Pypy-commit mailing list