From 004d5e6880940ddbb38460986ac62ee0f1bae97d Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 23 Oct 2000 17:22:08 +0000 Subject: Make reindent.py happy (convert everything to 4-space indents!). --- Lib/test/pystone.py | 364 +++++++++++++++++++++---------------------- Lib/test/regex_tests.py | 24 ++- Lib/test/regrtest.py | 6 +- Lib/test/test_MimeWriter.py | 6 +- Lib/test/test_al.py | 1 - Lib/test/test_array.py | 321 +++++++++++++++++++------------------- Lib/test/test_augassign.py | 200 ++++++++++++------------ Lib/test/test_b2.py | 164 +++++++++---------- Lib/test/test_binhex.py | 2 +- Lib/test/test_bsddb.py | 2 +- Lib/test/test_cfgparser.py | 2 +- Lib/test/test_cgi.py | 6 +- Lib/test/test_class.py | 17 +- Lib/test/test_contains.py | 130 ++++++++-------- Lib/test/test_cookie.py | 6 +- Lib/test/test_crypt.py | 2 +- Lib/test/test_dospath.py | 25 ++- Lib/test/test_extcall.py | 12 +- Lib/test/test_fcntl.py | 4 +- Lib/test/test_gc.py | 10 +- Lib/test/test_gdbm.py | 4 +- Lib/test/test_gettext.py | 10 +- Lib/test/test_gl.py | 2 +- Lib/test/test_grammar.py | 180 ++++++++++----------- Lib/test/test_grp.py | 2 +- Lib/test/test_gzip.py | 5 +- Lib/test/test_hash.py | 15 +- Lib/test/test_imageop.py | 36 ++--- Lib/test/test_imgfile.py | 24 +-- Lib/test/test_largefile.py | 20 +-- Lib/test/test_long.py | 1 - Lib/test/test_longexp.py | 4 +- Lib/test/test_math.py | 18 +-- Lib/test/test_md5.py | 16 +- Lib/test/test_minidom.py | 26 ++-- Lib/test/test_mmap.py | 21 ++- Lib/test/test_ntpath.py | 25 ++- Lib/test/test_opcodes.py | 26 ++-- Lib/test/test_openpty.py | 1 - Lib/test/test_operations.py | 18 +-- Lib/test/test_pickle.py | 2 +- Lib/test/test_pkg.py | 8 +- Lib/test/test_poll.py | 2 +- Lib/test/test_posixpath.py | 23 ++- Lib/test/test_pow.py | 48 +++--- Lib/test/test_pty.py | 1 - Lib/test/test_pwd.py | 2 +- Lib/test/test_pyexpat.py | 10 +- Lib/test/test_re.py | 2 +- Lib/test/test_regex.py | 6 +- Lib/test/test_rgbimg.py | 36 ++--- Lib/test/test_sax.py | 33 ++-- Lib/test/test_select.py | 49 +++--- Lib/test/test_signal.py | 62 ++++---- Lib/test/test_string.py | 3 +- Lib/test/test_strop.py | 2 +- Lib/test/test_struct.py | 2 +- Lib/test/test_support.py | 94 +++++------ Lib/test/test_thread.py | 140 ++++++++--------- Lib/test/test_tokenize.py | 1 - Lib/test/test_types.py | 26 ++-- Lib/test/test_ucn.py | 27 ++-- Lib/test/test_unicode.py | 85 +++++----- Lib/test/test_unicodedata.py | 10 +- Lib/test/test_urllib.py | 2 - Lib/test/test_winreg.py | 1 - Lib/test/test_winsound.py | 1 - Lib/test/test_xmllib.py | 6 +- Lib/test/test_zipfile.py | 33 ++-- Lib/test/test_zlib.py | 15 +- 70 files changed, 1229 insertions(+), 1261 deletions(-) diff --git a/Lib/test/pystone.py b/Lib/test/pystone.py index bef67d0..6c04b55 100755 --- a/Lib/test/pystone.py +++ b/Lib/test/pystone.py @@ -3,32 +3,32 @@ """ "PYSTONE" Benchmark Program -Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes) +Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes) -Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013. +Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013. - Translated from ADA to C by Rick Richardson. - Every method to preserve ADA-likeness has been used, - at the expense of C-ness. + Translated from ADA to C by Rick Richardson. + Every method to preserve ADA-likeness has been used, + at the expense of C-ness. - Translated from C to Python by Guido van Rossum. + Translated from C to Python by Guido van Rossum. Version History: - Version 1.1 corrects two bugs in version 1.0: + Version 1.1 corrects two bugs in version 1.0: - First, it leaked memory: in Proc1(), NextRecord ends - up having a pointer to itself. I have corrected this - by zapping NextRecord.PtrComp at the end of Proc1(). + First, it leaked memory: in Proc1(), NextRecord ends + up having a pointer to itself. I have corrected this + by zapping NextRecord.PtrComp at the end of Proc1(). - Second, Proc3() used the operator != to compare a - record to None. This is rather inefficient and not - true to the intention of the original benchmark (where - a pointer comparison to None is intended; the != - operator attempts to find a method __cmp__ to do value - comparison of the record). Version 1.1 runs 5-10 - percent faster than version 1.0, so benchmark figures - of different versions can't be compared directly. + Second, Proc3() used the operator != to compare a + record to None. This is rather inefficient and not + true to the intention of the original benchmark (where + a pointer comparison to None is intended; the != + operator attempts to find a method __cmp__ to do value + comparison of the record). Version 1.1 runs 5-10 + percent faster than version 1.0, so benchmark figures + of different versions can't be compared directly. """ @@ -42,30 +42,30 @@ __version__ = "1.1" class Record: - def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0, - IntComp = 0, StringComp = 0): - self.PtrComp = PtrComp - self.Discr = Discr - self.EnumComp = EnumComp - self.IntComp = IntComp - self.StringComp = StringComp + def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0, + IntComp = 0, StringComp = 0): + self.PtrComp = PtrComp + self.Discr = Discr + self.EnumComp = EnumComp + self.IntComp = IntComp + self.StringComp = StringComp - def copy(self): - return Record(self.PtrComp, self.Discr, self.EnumComp, - self.IntComp, self.StringComp) + def copy(self): + return Record(self.PtrComp, self.Discr, self.EnumComp, + self.IntComp, self.StringComp) TRUE = 1 FALSE = 0 def main(): - benchtime, stones = pystones() - print "Pystone(%s) time for %d passes = %g" % \ - (__version__, LOOPS, benchtime) - print "This machine benchmarks at %g pystones/second" % stones + benchtime, stones = pystones() + print "Pystone(%s) time for %d passes = %g" % \ + (__version__, LOOPS, benchtime) + print "This machine benchmarks at %g pystones/second" % stones def pystones(loops=LOOPS): - return Proc0(loops) + return Proc0(loops) IntGlob = 0 BoolGlob = FALSE @@ -77,176 +77,176 @@ PtrGlb = None PtrGlbNext = None def Proc0(loops=LOOPS): - global IntGlob - global BoolGlob - global Char1Glob - global Char2Glob - global Array1Glob - global Array2Glob - global PtrGlb - global PtrGlbNext - - starttime = clock() - for i in range(loops): - pass - nulltime = clock() - starttime - - PtrGlbNext = Record() - PtrGlb = Record() - PtrGlb.PtrComp = PtrGlbNext - PtrGlb.Discr = Ident1 - PtrGlb.EnumComp = Ident3 - PtrGlb.IntComp = 40 - PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING" - String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING" - Array2Glob[8][7] = 10 - - starttime = clock() - - for i in range(loops): - Proc5() - Proc4() - IntLoc1 = 2 - IntLoc2 = 3 - String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING" - EnumLoc = Ident2 - BoolGlob = not Func2(String1Loc, String2Loc) - while IntLoc1 < IntLoc2: - IntLoc3 = 5 * IntLoc1 - IntLoc2 - IntLoc3 = Proc7(IntLoc1, IntLoc2) - IntLoc1 = IntLoc1 + 1 - Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3) - PtrGlb = Proc1(PtrGlb) - CharIndex = 'A' - while CharIndex <= Char2Glob: - if EnumLoc == Func1(CharIndex, 'C'): - EnumLoc = Proc6(Ident1) - CharIndex = chr(ord(CharIndex)+1) - IntLoc3 = IntLoc2 * IntLoc1 - IntLoc2 = IntLoc3 / IntLoc1 - IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1 - IntLoc1 = Proc2(IntLoc1) - - benchtime = clock() - starttime - nulltime - return benchtime, (loops / benchtime) + global IntGlob + global BoolGlob + global Char1Glob + global Char2Glob + global Array1Glob + global Array2Glob + global PtrGlb + global PtrGlbNext + + starttime = clock() + for i in range(loops): + pass + nulltime = clock() - starttime + + PtrGlbNext = Record() + PtrGlb = Record() + PtrGlb.PtrComp = PtrGlbNext + PtrGlb.Discr = Ident1 + PtrGlb.EnumComp = Ident3 + PtrGlb.IntComp = 40 + PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING" + String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING" + Array2Glob[8][7] = 10 + + starttime = clock() + + for i in range(loops): + Proc5() + Proc4() + IntLoc1 = 2 + IntLoc2 = 3 + String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING" + EnumLoc = Ident2 + BoolGlob = not Func2(String1Loc, String2Loc) + while IntLoc1 < IntLoc2: + IntLoc3 = 5 * IntLoc1 - IntLoc2 + IntLoc3 = Proc7(IntLoc1, IntLoc2) + IntLoc1 = IntLoc1 + 1 + Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3) + PtrGlb = Proc1(PtrGlb) + CharIndex = 'A' + while CharIndex <= Char2Glob: + if EnumLoc == Func1(CharIndex, 'C'): + EnumLoc = Proc6(Ident1) + CharIndex = chr(ord(CharIndex)+1) + IntLoc3 = IntLoc2 * IntLoc1 + IntLoc2 = IntLoc3 / IntLoc1 + IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1 + IntLoc1 = Proc2(IntLoc1) + + benchtime = clock() - starttime - nulltime + return benchtime, (loops / benchtime) def Proc1(PtrParIn): - PtrParIn.PtrComp = NextRecord = PtrGlb.copy() - PtrParIn.IntComp = 5 - NextRecord.IntComp = PtrParIn.IntComp - NextRecord.PtrComp = PtrParIn.PtrComp - NextRecord.PtrComp = Proc3(NextRecord.PtrComp) - if NextRecord.Discr == Ident1: - NextRecord.IntComp = 6 - NextRecord.EnumComp = Proc6(PtrParIn.EnumComp) - NextRecord.PtrComp = PtrGlb.PtrComp - NextRecord.IntComp = Proc7(NextRecord.IntComp, 10) - else: - PtrParIn = NextRecord.copy() - NextRecord.PtrComp = None - return PtrParIn + PtrParIn.PtrComp = NextRecord = PtrGlb.copy() + PtrParIn.IntComp = 5 + NextRecord.IntComp = PtrParIn.IntComp + NextRecord.PtrComp = PtrParIn.PtrComp + NextRecord.PtrComp = Proc3(NextRecord.PtrComp) + if NextRecord.Discr == Ident1: + NextRecord.IntComp = 6 + NextRecord.EnumComp = Proc6(PtrParIn.EnumComp) + NextRecord.PtrComp = PtrGlb.PtrComp + NextRecord.IntComp = Proc7(NextRecord.IntComp, 10) + else: + PtrParIn = NextRecord.copy() + NextRecord.PtrComp = None + return PtrParIn def Proc2(IntParIO): - IntLoc = IntParIO + 10 - while 1: - if Char1Glob == 'A': - IntLoc = IntLoc - 1 - IntParIO = IntLoc - IntGlob - EnumLoc = Ident1 - if EnumLoc == Ident1: - break - return IntParIO + IntLoc = IntParIO + 10 + while 1: + if Char1Glob == 'A': + IntLoc = IntLoc - 1 + IntParIO = IntLoc - IntGlob + EnumLoc = Ident1 + if EnumLoc == Ident1: + break + return IntParIO def Proc3(PtrParOut): - global IntGlob - - if PtrGlb is not None: - PtrParOut = PtrGlb.PtrComp - else: - IntGlob = 100 - PtrGlb.IntComp = Proc7(10, IntGlob) - return PtrParOut + global IntGlob + + if PtrGlb is not None: + PtrParOut = PtrGlb.PtrComp + else: + IntGlob = 100 + PtrGlb.IntComp = Proc7(10, IntGlob) + return PtrParOut def Proc4(): - global Char2Glob - - BoolLoc = Char1Glob == 'A' - BoolLoc = BoolLoc or BoolGlob - Char2Glob = 'B' + global Char2Glob + + BoolLoc = Char1Glob == 'A' + BoolLoc = BoolLoc or BoolGlob + Char2Glob = 'B' def Proc5(): - global Char1Glob - global BoolGlob - - Char1Glob = 'A' - BoolGlob = FALSE + global Char1Glob + global BoolGlob + + Char1Glob = 'A' + BoolGlob = FALSE def Proc6(EnumParIn): - EnumParOut = EnumParIn - if not Func3(EnumParIn): - EnumParOut = Ident4 - if EnumParIn == Ident1: - EnumParOut = Ident1 - elif EnumParIn == Ident2: - if IntGlob > 100: - EnumParOut = Ident1 - else: - EnumParOut = Ident4 - elif EnumParIn == Ident3: - EnumParOut = Ident2 - elif EnumParIn == Ident4: - pass - elif EnumParIn == Ident5: - EnumParOut = Ident3 - return EnumParOut + EnumParOut = EnumParIn + if not Func3(EnumParIn): + EnumParOut = Ident4 + if EnumParIn == Ident1: + EnumParOut = Ident1 + elif EnumParIn == Ident2: + if IntGlob > 100: + EnumParOut = Ident1 + else: + EnumParOut = Ident4 + elif EnumParIn == Ident3: + EnumParOut = Ident2 + elif EnumParIn == Ident4: + pass + elif EnumParIn == Ident5: + EnumParOut = Ident3 + return EnumParOut def Proc7(IntParI1, IntParI2): - IntLoc = IntParI1 + 2 - IntParOut = IntParI2 + IntLoc - return IntParOut + IntLoc = IntParI1 + 2 + IntParOut = IntParI2 + IntLoc + return IntParOut def Proc8(Array1Par, Array2Par, IntParI1, IntParI2): - global IntGlob - - IntLoc = IntParI1 + 5 - Array1Par[IntLoc] = IntParI2 - Array1Par[IntLoc+1] = Array1Par[IntLoc] - Array1Par[IntLoc+30] = IntLoc - for IntIndex in range(IntLoc, IntLoc+2): - Array2Par[IntLoc][IntIndex] = IntLoc - Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1 - Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc] - IntGlob = 5 + global IntGlob + + IntLoc = IntParI1 + 5 + Array1Par[IntLoc] = IntParI2 + Array1Par[IntLoc+1] = Array1Par[IntLoc] + Array1Par[IntLoc+30] = IntLoc + for IntIndex in range(IntLoc, IntLoc+2): + Array2Par[IntLoc][IntIndex] = IntLoc + Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1 + Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc] + IntGlob = 5 def Func1(CharPar1, CharPar2): - CharLoc1 = CharPar1 - CharLoc2 = CharLoc1 - if CharLoc2 != CharPar2: - return Ident1 - else: - return Ident2 + CharLoc1 = CharPar1 + CharLoc2 = CharLoc1 + if CharLoc2 != CharPar2: + return Ident1 + else: + return Ident2 def Func2(StrParI1, StrParI2): - IntLoc = 1 - while IntLoc <= 1: - if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1: - CharLoc = 'A' - IntLoc = IntLoc + 1 - if CharLoc >= 'W' and CharLoc <= 'Z': - IntLoc = 7 - if CharLoc == 'X': - return TRUE - else: - if StrParI1 > StrParI2: - IntLoc = IntLoc + 7 - return TRUE - else: - return FALSE + IntLoc = 1 + while IntLoc <= 1: + if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1: + CharLoc = 'A' + IntLoc = IntLoc + 1 + if CharLoc >= 'W' and CharLoc <= 'Z': + IntLoc = 7 + if CharLoc == 'X': + return TRUE + else: + if StrParI1 > StrParI2: + IntLoc = IntLoc + 7 + return TRUE + else: + return FALSE def Func3(EnumParIn): - EnumLoc = EnumParIn - if EnumLoc == Ident3: return TRUE - return FALSE + EnumLoc = EnumParIn + if EnumLoc == Ident3: return TRUE + return FALSE if __name__ == '__main__': - main() + main() diff --git a/Lib/test/regex_tests.py b/Lib/test/regex_tests.py index dcb980a..e004ad0 100644 --- a/Lib/test/regex_tests.py +++ b/Lib/test/regex_tests.py @@ -1,6 +1,5 @@ - # Regex test suite and benchmark suite v1.5a2 -# Due to the use of r"aw" strings, this file will +# Due to the use of r"aw" strings, this file will # only work with Python 1.5 or higher. # The 3 possible outcomes for each pattern @@ -9,22 +8,22 @@ # Benchmark suite (needs expansion) # # The benchmark suite does not test correctness, just speed. The -# first element of each tuple is the regex pattern; the second is a +# first element of each tuple is the regex pattern; the second is a # string to match it against. The benchmarking code will embed the -# second string inside several sizes of padding, to test how regex +# second string inside several sizes of padding, to test how regex # matching performs on large strings. benchmarks = [ - ('Python', 'Python'), # Simple text literal - ('.*Python', 'Python'), # Bad text literal + ('Python', 'Python'), # Simple text literal + ('.*Python', 'Python'), # Bad text literal ('.*Python.*', 'Python'), # Worse text literal - ('.*\\(Python\\)', 'Python'), # Bad text literal with grouping + ('.*\\(Python\\)', 'Python'), # Bad text literal with grouping - ('(Python\\|Perl\\|Tcl', 'Perl'), # Alternation - ('\\(Python\\|Perl\\|Tcl\\)', 'Perl'), # Grouped alternation - ('\\(Python\\)\\1', 'PythonPython'), # Backreference -# ('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization - ('\\([a-z][a-z0-9]*,\\)+', 'a5,b7,c9,') # A few sets + ('(Python\\|Perl\\|Tcl', 'Perl'), # Alternation + ('\\(Python\\|Perl\\|Tcl\\)', 'Perl'), # Grouped alternation + ('\\(Python\\)\\1', 'PythonPython'), # Backreference +# ('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization + ('\\([a-z][a-z0-9]*,\\)+', 'a5,b7,c9,') # A few sets ] # Test suite (for verifying correctness) @@ -286,4 +285,3 @@ tests = [ ('a\>', 'a!', SUCCEED, 'found', 'a'), ('a\>', 'a', SUCCEED, 'found', 'a'), ] - diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index d392e6c..3d9c5af 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -46,14 +46,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, """Execute a test suite. This also parses command-line options and modifies its behavior - accordingly. + accordingly. tests -- a list of strings containing test names (optional) testdir -- the directory in which to look for tests (optional) Users other than the Python test suite will certainly want to specify testdir; if it's omitted, the directory containing the - Python test suite is searched for. + Python test suite is searched for. If the tests argument is omitted, the tests listed on the command-line will be used. If that's empty, too, then all *.py @@ -65,7 +65,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, command line. """ - + try: opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl', ['have-resources']) except getopt.error, msg: diff --git a/Lib/test/test_MimeWriter.py b/Lib/test/test_MimeWriter.py index 8b74421..5041105 100644 --- a/Lib/test/test_MimeWriter.py +++ b/Lib/test/test_MimeWriter.py @@ -81,7 +81,7 @@ def main(): import sys # Toplevel headers - + toplevel = MimeWriter(sys.stdout) toplevel.addheader("From", "bwarsaw@cnri.reston.va.us") toplevel.addheader("Date", "Mon Feb 12 17:21:48 EST 1996") @@ -89,7 +89,7 @@ def main(): toplevel.addheader("MIME-Version", "1.0") # Toplevel body parts - + f = toplevel.startmultipartbody("knowbot", "801spam999", [("version", "0.1")], prefix=0) f.write("This is a multi-part message in MIME format.\n") @@ -100,7 +100,7 @@ def main(): md.startmultipartbody("knowbot-metadata", "802spam999") # Metadata part 1 - + md1 = md.nextpart() md1.addheader("KP-Metadata-Type", "simple") md1.addheader("KP-Access", "read-only") diff --git a/Lib/test/test_al.py b/Lib/test/test_al.py index d7b5ec4..d11c7e5 100755 --- a/Lib/test/test_al.py +++ b/Lib/test/test_al.py @@ -21,4 +21,3 @@ def main(): getattr(al, attr) main() - diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index fb451a9..4a64bd6 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -16,173 +16,172 @@ def main(): def testoverflow(type, lowerLimit, upperLimit): - # should not overflow assigning lower limit - if verbose: - print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`) - try: - a = array.array(type, [lowerLimit]) - except: - raise TestFailed, "array(%s) overflowed assigning %s" %\ - (`type`, `lowerLimit`) - # should overflow assigning less than lower limit - if verbose: - print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`) - try: - a = array.array(type, [lowerLimit-1]) - raise TestFailed, "array(%s) did not overflow assigning %s" %\ - (`type`, `lowerLimit-1`) - except OverflowError: - pass - # should not overflow assigning upper limit - if verbose: - print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`) - try: - a = array.array(type, [upperLimit]) - except: - raise TestFailed, "array(%s) overflowed assigning %s" %\ - (`type`, `upperLimit`) - # should overflow assigning more than upper limit - if verbose: - print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`) - try: - a = array.array(type, [upperLimit+1]) - raise TestFailed, "array(%s) did not overflow assigning %s" %\ - (`type`, `upperLimit+1`) - except OverflowError: - pass + # should not overflow assigning lower limit + if verbose: + print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`) + try: + a = array.array(type, [lowerLimit]) + except: + raise TestFailed, "array(%s) overflowed assigning %s" %\ + (`type`, `lowerLimit`) + # should overflow assigning less than lower limit + if verbose: + print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`) + try: + a = array.array(type, [lowerLimit-1]) + raise TestFailed, "array(%s) did not overflow assigning %s" %\ + (`type`, `lowerLimit-1`) + except OverflowError: + pass + # should not overflow assigning upper limit + if verbose: + print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`) + try: + a = array.array(type, [upperLimit]) + except: + raise TestFailed, "array(%s) overflowed assigning %s" %\ + (`type`, `upperLimit`) + # should overflow assigning more than upper limit + if verbose: + print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`) + try: + a = array.array(type, [upperLimit+1]) + raise TestFailed, "array(%s) did not overflow assigning %s" %\ + (`type`, `upperLimit+1`) + except OverflowError: + pass def testtype(type, example): - a = array.array(type) - a.append(example) - if verbose: - print 40*'*' - print 'array after append: ', a - a.typecode - a.itemsize - if a.typecode in ('i', 'b', 'h', 'l'): - a.byteswap() - - if a.typecode == 'c': - f = open(TESTFN, "w") - f.write("The quick brown fox jumps over the lazy dog.\n") - f.close() - f = open(TESTFN, 'r') - a.fromfile(f, 10) - f.close() - if verbose: - print 'char array with 10 bytes of TESTFN appended: ', a - a.fromlist(['a', 'b', 'c']) - if verbose: - print 'char array with list appended: ', a - - a.insert(0, example) - if verbose: - print 'array of %s after inserting another:' % a.typecode, a - f = open(TESTFN, 'w') - a.tofile(f) + a = array.array(type) + a.append(example) + if verbose: + print 40*'*' + print 'array after append: ', a + a.typecode + a.itemsize + if a.typecode in ('i', 'b', 'h', 'l'): + a.byteswap() + + if a.typecode == 'c': + f = open(TESTFN, "w") + f.write("The quick brown fox jumps over the lazy dog.\n") + f.close() + f = open(TESTFN, 'r') + a.fromfile(f, 10) f.close() - a.tolist() - a.tostring() if verbose: - print 'array of %s converted to a list: ' % a.typecode, a.tolist() + print 'char array with 10 bytes of TESTFN appended: ', a + a.fromlist(['a', 'b', 'c']) if verbose: - print 'array of %s converted to a string: ' \ - % a.typecode, `a.tostring()` - - if type == 'c': - a = array.array(type, "abcde") - a[:-1] = a - if a != array.array(type, "abcdee"): - raise TestFailed, "array(%s) self-slice-assign (head)" % `type` - a = array.array(type, "abcde") - a[1:] = a - if a != array.array(type, "aabcde"): - raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` - a = array.array(type, "abcde") - a[1:-1] = a - if a != array.array(type, "aabcdee"): - raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` - if a.index("e") != 5: - raise TestFailed, "array(%s) index-test" % `type` - if a.count("a") != 2: - raise TestFailed, "array(%s) count-test" % `type` - a.remove("e") - if a != array.array(type, "aabcde"): - raise TestFailed, "array(%s) remove-test" % `type` - if a.pop(0) != "a": - raise TestFailed, "array(%s) pop-test" % `type` - if a.pop(1) != "b": - raise TestFailed, "array(%s) pop-test" % `type` - a.extend(array.array(type, "xyz")) - if a != array.array(type, "acdexyz"): - raise TestFailed, "array(%s) extend-test" % `type` - a.pop() - a.pop() - a.pop() - x = a.pop() - if x != 'e': - raise TestFailed, "array(%s) pop-test" % `type` - if a != array.array(type, "acd"): - raise TestFailed, "array(%s) pop-test" % `type` - a.reverse() - if a != array.array(type, "dca"): - raise TestFailed, "array(%s) reverse-test" % `type` - else: - a = array.array(type, [1, 2, 3, 4, 5]) - a[:-1] = a - if a != array.array(type, [1, 2, 3, 4, 5, 5]): - raise TestFailed, "array(%s) self-slice-assign (head)" % `type` - a = array.array(type, [1, 2, 3, 4, 5]) - a[1:] = a - if a != array.array(type, [1, 1, 2, 3, 4, 5]): - raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` - a = array.array(type, [1, 2, 3, 4, 5]) - a[1:-1] = a - if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]): - raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` - if a.index(5) != 5: - raise TestFailed, "array(%s) index-test" % `type` - if a.count(1) != 2: - raise TestFailed, "array(%s) count-test" % `type` - a.remove(5) - if a != array.array(type, [1, 1, 2, 3, 4, 5]): - raise TestFailed, "array(%s) remove-test" % `type` - if a.pop(0) != 1: - raise TestFailed, "array(%s) pop-test" % `type` - if a.pop(1) != 2: - raise TestFailed, "array(%s) pop-test" % `type` - a.extend(array.array(type, [7, 8, 9])) - if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]): - raise TestFailed, "array(%s) extend-test" % `type` - a.pop() - a.pop() - a.pop() - x = a.pop() - if x != 5: - raise TestFailed, "array(%s) pop-test" % `type` - if a != array.array(type, [1, 3, 4]): - raise TestFailed, "array(%s) pop-test" % `type` - a.reverse() - if a != array.array(type, [4, 3, 1]): - raise TestFailed, "array(%s) reverse-test" % `type` - - # test that overflow exceptions are raised as expected for assignment - # to array of specific integral types - from math import pow - if type in ('b', 'h', 'i', 'l'): - # check signed and unsigned versions - a = array.array(type) - signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1)) - signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L - unsignedLowerLimit = 0 - unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L - testoverflow(type, signedLowerLimit, signedUpperLimit) - testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit) - - - -main() + print 'char array with list appended: ', a + + a.insert(0, example) + if verbose: + print 'array of %s after inserting another:' % a.typecode, a + f = open(TESTFN, 'w') + a.tofile(f) + f.close() + a.tolist() + a.tostring() + if verbose: + print 'array of %s converted to a list: ' % a.typecode, a.tolist() + if verbose: + print 'array of %s converted to a string: ' \ + % a.typecode, `a.tostring()` + if type == 'c': + a = array.array(type, "abcde") + a[:-1] = a + if a != array.array(type, "abcdee"): + raise TestFailed, "array(%s) self-slice-assign (head)" % `type` + a = array.array(type, "abcde") + a[1:] = a + if a != array.array(type, "aabcde"): + raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` + a = array.array(type, "abcde") + a[1:-1] = a + if a != array.array(type, "aabcdee"): + raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` + if a.index("e") != 5: + raise TestFailed, "array(%s) index-test" % `type` + if a.count("a") != 2: + raise TestFailed, "array(%s) count-test" % `type` + a.remove("e") + if a != array.array(type, "aabcde"): + raise TestFailed, "array(%s) remove-test" % `type` + if a.pop(0) != "a": + raise TestFailed, "array(%s) pop-test" % `type` + if a.pop(1) != "b": + raise TestFailed, "array(%s) pop-test" % `type` + a.extend(array.array(type, "xyz")) + if a != array.array(type, "acdexyz"): + raise TestFailed, "array(%s) extend-test" % `type` + a.pop() + a.pop() + a.pop() + x = a.pop() + if x != 'e': + raise TestFailed, "array(%s) pop-test" % `type` + if a != array.array(type, "acd"): + raise TestFailed, "array(%s) pop-test" % `type` + a.reverse() + if a != array.array(type, "dca"): + raise TestFailed, "array(%s) reverse-test" % `type` + else: + a = array.array(type, [1, 2, 3, 4, 5]) + a[:-1] = a + if a != array.array(type, [1, 2, 3, 4, 5, 5]): + raise TestFailed, "array(%s) self-slice-assign (head)" % `type` + a = array.array(type, [1, 2, 3, 4, 5]) + a[1:] = a + if a != array.array(type, [1, 1, 2, 3, 4, 5]): + raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` + a = array.array(type, [1, 2, 3, 4, 5]) + a[1:-1] = a + if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]): + raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` + if a.index(5) != 5: + raise TestFailed, "array(%s) index-test" % `type` + if a.count(1) != 2: + raise TestFailed, "array(%s) count-test" % `type` + a.remove(5) + if a != array.array(type, [1, 1, 2, 3, 4, 5]): + raise TestFailed, "array(%s) remove-test" % `type` + if a.pop(0) != 1: + raise TestFailed, "array(%s) pop-test" % `type` + if a.pop(1) != 2: + raise TestFailed, "array(%s) pop-test" % `type` + a.extend(array.array(type, [7, 8, 9])) + if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]): + raise TestFailed, "array(%s) extend-test" % `type` + a.pop() + a.pop() + a.pop() + x = a.pop() + if x != 5: + raise TestFailed, "array(%s) pop-test" % `type` + if a != array.array(type, [1, 3, 4]): + raise TestFailed, "array(%s) pop-test" % `type` + a.reverse() + if a != array.array(type, [4, 3, 1]): + raise TestFailed, "array(%s) reverse-test" % `type` + + # test that overflow exceptions are raised as expected for assignment + # to array of specific integral types + from math import pow + if type in ('b', 'h', 'i', 'l'): + # check signed and unsigned versions + a = array.array(type) + signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1)) + signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L + unsignedLowerLimit = 0 + unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L + testoverflow(type, signedLowerLimit, signedUpperLimit) + testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit) + + + +main() diff --git a/Lib/test/test_augassign.py b/Lib/test/test_augassign.py index a01195e..a37b4e1 100644 --- a/Lib/test/test_augassign.py +++ b/Lib/test/test_augassign.py @@ -1,4 +1,3 @@ - # Augmented assignment test. x = 2 @@ -55,29 +54,29 @@ print x print x is y class aug_test: - def __init__(self, value): - self.val = value - def __radd__(self, val): - return self.val + val - def __add__(self, val): - return aug_test(self.val + val) + def __init__(self, value): + self.val = value + def __radd__(self, val): + return self.val + val + def __add__(self, val): + return aug_test(self.val + val) class aug_test2(aug_test): - def __iadd__(self, val): - self.val = self.val + val - return self + def __iadd__(self, val): + self.val = self.val + val + return self class aug_test3(aug_test): - def __iadd__(self, val): - return aug_test3(self.val + val) + def __iadd__(self, val): + return aug_test3(self.val + val) x = aug_test(1) y = x x += 10 print isinstance(x, aug_test) -print y is not x +print y is not x print x.val x = aug_test2(2) @@ -97,93 +96,93 @@ print x.val class testall: - def __add__(self, val): - print "__add__ called" - def __radd__(self, val): - print "__radd__ called" - def __iadd__(self, val): - print "__iadd__ called" - return self - - def __sub__(self, val): - print "__sub__ called" - def __rsub__(self, val): - print "__rsub__ called" - def __isub__(self, val): - print "__isub__ called" - return self - - def __mul__(self, val): - print "__mul__ called" - def __rmul__(self, val): - print "__rmul__ called" - def __imul__(self, val): - print "__imul__ called" - return self - - def __div__(self, val): - print "__div__ called" - def __rdiv__(self, val): - print "__rdiv__ called" - def __idiv__(self, val): - print "__idiv__ called" - return self - - def __mod__(self, val): - print "__mod__ called" - def __rmod__(self, val): - print "__rmod__ called" - def __imod__(self, val): - print "__imod__ called" - return self - - def __pow__(self, val): - print "__pow__ called" - def __rpow__(self, val): - print "__rpow__ called" - def __ipow__(self, val): - print "__ipow__ called" - return self - - def __or__(self, val): - print "__or__ called" - def __ror__(self, val): - print "__ror__ called" - def __ior__(self, val): - print "__ior__ called" - return self - - def __and__(self, val): - print "__and__ called" - def __rand__(self, val): - print "__rand__ called" - def __iand__(self, val): - print "__iand__ called" - return self - - def __xor__(self, val): - print "__xor__ called" - def __rxor__(self, val): - print "__rxor__ called" - def __ixor__(self, val): - print "__ixor__ called" - return self - - def __rshift__(self, val): - print "__rshift__ called" - def __rrshift__(self, val): - print "__rrshift__ called" - def __irshift__(self, val): - print "__irshift__ called" - return self - - def __lshift__(self, val): - print "__lshift__ called" - def __rlshift__(self, val): - print "__rlshift__ called" - def __ilshift__(self, val): - print "__ilshift__ called" - return self + def __add__(self, val): + print "__add__ called" + def __radd__(self, val): + print "__radd__ called" + def __iadd__(self, val): + print "__iadd__ called" + return self + + def __sub__(self, val): + print "__sub__ called" + def __rsub__(self, val): + print "__rsub__ called" + def __isub__(self, val): + print "__isub__ called" + return self + + def __mul__(self, val): + print "__mul__ called" + def __rmul__(self, val): + print "__rmul__ called" + def __imul__(self, val): + print "__imul__ called" + return self + + def __div__(self, val): + print "__div__ called" + def __rdiv__(self, val): + print "__rdiv__ called" + def __idiv__(self, val): + print "__idiv__ called" + return self + + def __mod__(self, val): + print "__mod__ called" + def __rmod__(self, val): + print "__rmod__ called" + def __imod__(self, val): + print "__imod__ called" + return self + + def __pow__(self, val): + print "__pow__ called" + def __rpow__(self, val): + print "__rpow__ called" + def __ipow__(self, val): + print "__ipow__ called" + return self + + def __or__(self, val): + print "__or__ called" + def __ror__(self, val): + print "__ror__ called" + def __ior__(self, val): + print "__ior__ called" + return self + + def __and__(self, val): + print "__and__ called" + def __rand__(self, val): + print "__rand__ called" + def __iand__(self, val): + print "__iand__ called" + return self + + def __xor__(self, val): + print "__xor__ called" + def __rxor__(self, val): + print "__rxor__ called" + def __ixor__(self, val): + print "__ixor__ called" + return self + + def __rshift__(self, val): + print "__rshift__ called" + def __rrshift__(self, val): + print "__rrshift__ called" + def __irshift__(self, val): + print "__irshift__ called" + return self + + def __lshift__(self, val): + print "__lshift__ called" + def __rlshift__(self, val): + print "__rlshift__ called" + def __ilshift__(self, val): + print "__ilshift__ called" + return self x = testall() x + 1 @@ -229,4 +228,3 @@ x >>= 1 x << 1 1 << x x <<= 1 - diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py index 8ee4a03..ec6ae50 100644 --- a/Lib/test/test_b2.py +++ b/Lib/test/test_b2.py @@ -6,35 +6,35 @@ print 'oct' if oct(100) != '0144': raise TestFailed, 'oct(100)' if oct(100L) != '0144L': raise TestFailed, 'oct(100L)' if oct(-100) not in ('037777777634', '01777777777777777777634'): - raise TestFailed, 'oct(-100)' + raise TestFailed, 'oct(-100)' if oct(-100L) != '-0144L': raise TestFailed, 'oct(-100L)' print 'open' # NB the first 4 lines are also used to test input and raw_input, below fp = open(TESTFN, 'w') try: - fp.write('1+1\n') - fp.write('1+1\n') - fp.write('The quick brown fox jumps over the lazy dog') - fp.write('.\n') - fp.write('Dear John\n') - fp.write('XXX'*100) - fp.write('YYY'*100) + fp.write('1+1\n') + fp.write('1+1\n') + fp.write('The quick brown fox jumps over the lazy dog') + fp.write('.\n') + fp.write('Dear John\n') + fp.write('XXX'*100) + fp.write('YYY'*100) finally: - fp.close() + fp.close() # fp = open(TESTFN, 'r') try: - if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' - if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' - if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n': - raise TestFailed, 'readline() # default' - if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short' - if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)' - if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)' - if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate' + if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' + if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' + if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n': + raise TestFailed, 'readline() # default' + if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short' + if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)' + if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)' + if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate' finally: - fp.close() + fp.close() print 'ord' if ord(' ') <> 32: raise TestFailed, 'ord(\' \')' @@ -89,10 +89,10 @@ if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)' #if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)' # for x in 2, 2L, 2.0: - for y in 10, 10L, 10.0: - for z in 1000, 1000L, 1000.0: - if fcmp(pow(x, y, z), 24.0): - raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z) + for y in 10, 10L, 10.0: + for z in 1000, 1000L, 1000.0: + if fcmp(pow(x, y, z), 24.0): + raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z) print 'range' if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)' @@ -107,45 +107,45 @@ import sys fp = open(TESTFN, 'r') savestdin = sys.stdin try: - sys.stdin = fp - if input() <> 2: raise TestFailed, 'input()' - if input('testing\n') <> 2: raise TestFailed, 'input()' - if raw_input() <> 'The quick brown fox jumps over the lazy dog.': - raise TestFailed, 'raw_input()' - if raw_input('testing\n') <> 'Dear John': - raise TestFailed, 'raw_input(\'testing\\n\')' + sys.stdin = fp + if input() <> 2: raise TestFailed, 'input()' + if input('testing\n') <> 2: raise TestFailed, 'input()' + if raw_input() <> 'The quick brown fox jumps over the lazy dog.': + raise TestFailed, 'raw_input()' + if raw_input('testing\n') <> 'Dear John': + raise TestFailed, 'raw_input(\'testing\\n\')' finally: - sys.stdin = savestdin - fp.close() + sys.stdin = savestdin + fp.close() print 'reduce' if reduce(lambda x, y: x+y, ['a', 'b', 'c'], '') <> 'abc': - raise TestFailed, 'reduce(): implode a string' + raise TestFailed, 'reduce(): implode a string' if reduce(lambda x, y: x+y, - [['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']: - raise TestFailed, 'reduce(): append' + [['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']: + raise TestFailed, 'reduce(): append' if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040: - raise TestFailed, 'reduce(): compute 7!' + raise TestFailed, 'reduce(): compute 7!' if reduce(lambda x, y: x*y, range(2,21), 1L) <> 2432902008176640000L: - raise TestFailed, 'reduce(): compute 20!, use long' + raise TestFailed, 'reduce(): compute 20!, use long' class Squares: - def __init__(self, max): - self.max = max - self.sofar = [] - def __len__(self): return len(self.sofar) - def __getitem__(self, i): - if not 0 <= i < self.max: raise IndexError - n = len(self.sofar) - while n <= i: - self.sofar.append(n*n) - n = n+1 - return self.sofar[i] + def __init__(self, max): + self.max = max + self.sofar = [] + def __len__(self): return len(self.sofar) + def __getitem__(self, i): + if not 0 <= i < self.max: raise IndexError + n = len(self.sofar) + while n <= i: + self.sofar.append(n*n) + n = n+1 + return self.sofar[i] if reduce(lambda x, y: x+y, Squares(10)) != 285: - raise TestFailed, 'reduce(<+>, Squares(10))' + raise TestFailed, 'reduce(<+>, Squares(10))' if reduce(lambda x, y: x+y, Squares(10), 0) != 285: - raise TestFailed, 'reduce(<+>, Squares(10), 0)' + raise TestFailed, 'reduce(<+>, Squares(10), 0)' if reduce(lambda x, y: x+y, Squares(0), 0) != 0: - raise TestFailed, 'reduce(<+>, Squares(0), 0)' + raise TestFailed, 'reduce(<+>, Squares(0), 0)' print 'reload' @@ -171,35 +171,35 @@ if round(0.0) <> 0.0: raise TestFailed, 'round(0.0)' if round(1.0) <> 1.0: raise TestFailed, 'round(1.0)' if round(10.0) <> 10.0: raise TestFailed, 'round(10.0)' if round(1000000000.0) <> 1000000000.0: - raise TestFailed, 'round(1000000000.0)' + raise TestFailed, 'round(1000000000.0)' if round(1e20) <> 1e20: raise TestFailed, 'round(1e20)' if round(-1.0) <> -1.0: raise TestFailed, 'round(-1.0)' if round(-10.0) <> -10.0: raise TestFailed, 'round(-10.0)' if round(-1000000000.0) <> -1000000000.0: - raise TestFailed, 'round(-1000000000.0)' + raise TestFailed, 'round(-1000000000.0)' if round(-1e20) <> -1e20: raise TestFailed, 'round(-1e20)' if round(0.1) <> 0.0: raise TestFailed, 'round(0.0)' if round(1.1) <> 1.0: raise TestFailed, 'round(1.0)' if round(10.1) <> 10.0: raise TestFailed, 'round(10.0)' if round(1000000000.1) <> 1000000000.0: - raise TestFailed, 'round(1000000000.0)' + raise TestFailed, 'round(1000000000.0)' if round(-1.1) <> -1.0: raise TestFailed, 'round(-1.0)' if round(-10.1) <> -10.0: raise TestFailed, 'round(-10.0)' if round(-1000000000.1) <> -1000000000.0: - raise TestFailed, 'round(-1000000000.0)' + raise TestFailed, 'round(-1000000000.0)' if round(0.9) <> 1.0: raise TestFailed, 'round(0.9)' if round(9.9) <> 10.0: raise TestFailed, 'round(9.9)' if round(999999999.9) <> 1000000000.0: - raise TestFailed, 'round(999999999.9)' + raise TestFailed, 'round(999999999.9)' if round(-0.9) <> -1.0: raise TestFailed, 'round(-0.9)' if round(-9.9) <> -10.0: raise TestFailed, 'round(-9.9)' if round(-999999999.9) <> -1000000000.0: - raise TestFailed, 'round(-999999999.9)' + raise TestFailed, 'round(-999999999.9)' print 'setattr' import sys @@ -224,7 +224,7 @@ if tuple('spam') <> ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')" print 'type' if type('') <> type('123') or type('') == type(()): - raise TestFailed, 'type()' + raise TestFailed, 'type()' print 'vars' a = b = None @@ -240,20 +240,20 @@ a.sort() b.sort() if a <> b: raise TestFailed, 'vars(sys)' def f0(): - if vars() != {}: raise TestFailed, 'vars() in f0()' + if vars() != {}: raise TestFailed, 'vars() in f0()' f0() def f2(): - f0() - a = 1 - b = 2 - if vars() != {'a': a, 'b': b}: raise TestFailed, 'vars() in f2()' + f0() + a = 1 + b = 2 + if vars() != {'a': a, 'b': b}: raise TestFailed, 'vars() in f2()' f2() print 'xrange' if tuple(xrange(10)) <> tuple(range(10)): raise TestFailed, 'xrange(10)' if tuple(xrange(5,10)) <> tuple(range(5,10)): raise TestFailed, 'xrange(5,10)' if tuple(xrange(0,10,2)) <> tuple(range(0,10,2)): - raise TestFailed, 'xrange(0,10,2)' + raise TestFailed, 'xrange(0,10,2)' print 'zip' a = (1, 2, 3) @@ -265,43 +265,43 @@ if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, tuple/list' b = (4, 5, 6, 7) if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - b is longer' class I: - def __getitem__(self, i): - if i < 0 or i > 2: raise IndexError - return i + 4 + def __getitem__(self, i): + if i < 0 or i > 2: raise IndexError + return i + 4 if zip(a, I()) <> t: raise TestFailed, 'zip(a, b) - b is instance' exc = 0 try: - zip() + zip() except TypeError: - exc = 1 + exc = 1 except: - e = sys.exc_info()[0] - raise TestFailed, 'zip() - no args, expected TypeError, got %s' % e + e = sys.exc_info()[0] + raise TestFailed, 'zip() - no args, expected TypeError, got %s' % e if not exc: - raise TestFailed, 'zip() - no args, missing expected TypeError' + raise TestFailed, 'zip() - no args, missing expected TypeError' exc = 0 try: - zip(None) + zip(None) except TypeError: - exc = 1 + exc = 1 except: - e = sys.exc_info()[0] - raise TestFailed, 'zip(None) - expected TypeError, got %s' % e + e = sys.exc_info()[0] + raise TestFailed, 'zip(None) - expected TypeError, got %s' % e if not exc: - raise TestFailed, 'zip(None) - missing expected TypeError' + raise TestFailed, 'zip(None) - missing expected TypeError' class G: - pass + pass exc = 0 try: - zip(a, G()) + zip(a, G()) except AttributeError: - exc = 1 + exc = 1 except: - e = sys.exc_info()[0] - raise TestFailed, 'zip(a, b) - b instance w/o __getitem__' + e = sys.exc_info()[0] + raise TestFailed, 'zip(a, b) - b instance w/o __getitem__' if not exc: - raise TestFailed, 'zip(a, b) - missing expected AttributeError' + raise TestFailed, 'zip(a, b) - missing expected AttributeError' # Epilogue -- unlink the temp file diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py index d7f6016..68012f8 100755 --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -20,7 +20,7 @@ def test(): start = 'Jack is my hero' f.write(start) f.close() - + binhex.binhex(fname1, fname2) if verbose: print 'binhex' diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py index e5780ea..aa65295 100755 --- a/Lib/test/test_bsddb.py +++ b/Lib/test/test_bsddb.py @@ -12,7 +12,7 @@ def test(openmethod, what): if verbose: print '\nTesting: ', what - + fname = tempfile.mktemp() f = openmethod(fname, 'c') if verbose: diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py index 4bdbc69..00b8465 100644 --- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -110,7 +110,7 @@ basic(r""" [Foo Bar] foo=bar [Spacey Bar] -foo = bar +foo = bar [Commented Bar] foo: bar ; comment """) diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index de60115..890d1b2 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -4,7 +4,7 @@ import sys class HackedSysModule: # The regression test will have real values in sys.argv, which - # will completely confuse the test of the cgi module + # will completely confuse the test of the cgi module argv = [] stdin = sys.stdin @@ -53,7 +53,7 @@ def do_test(buf, method): # A list of test cases. Each test case is a a two-tuple that contains # a string with the query and a dictionary with the expected result. - + parse_test_cases = [ ("", ValueError("bad query field: ''")), ("&", ValueError("bad query field: ''")), @@ -90,7 +90,7 @@ parse_test_cases = [ 'ss': ['env'], 'view': ['bustomer'], }), - + ("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse", {'SUBMIT': ['Browse'], '_assigned_to': ['31392'], diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 43c1d3b..3bcbf18 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -67,7 +67,7 @@ testmeths = [ class AllTests: def __coerce__(self, *args): print "__coerce__:", args - return (self,) + args + return (self,) + args def __hash__(self, *args): print "__hash__:", args @@ -202,18 +202,17 @@ del testme # Interfering tests class ExtraTests: - def __getattr__(self, *args): - print "__getattr__:", args - return "SomeVal" + def __getattr__(self, *args): + print "__getattr__:", args + return "SomeVal" - def __setattr__(self, *args): - print "__setattr__:", args + def __setattr__(self, *args): + print "__setattr__:", args - def __delattr__(self, *args): - print "__delattr__:", args + def __delattr__(self, *args): + print "__delattr__:", args testme = ExtraTests() testme.spam testme.eggs = "spam, spam, spam and ham" del testme.cardinal - diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py index 355135f..499d587 100644 --- a/Lib/test/test_contains.py +++ b/Lib/test/test_contains.py @@ -2,18 +2,18 @@ from test_support import TestFailed class base_set: - def __init__(self, el): - self.el = el + def __init__(self, el): + self.el = el class set(base_set): - def __contains__(self, el): - return self.el == el + def __contains__(self, el): + return self.el == el class seq(base_set): - def __getitem__(self, n): - return [self.el][n] + def __getitem__(self, n): + return [self.el][n] def check(ok, *args): if not ok: @@ -29,16 +29,16 @@ check(1 in c, "1 not in seq(1)") check(0 not in c, "0 in seq(1)") try: - 1 in a - check(0, "in base_set did not raise error") + 1 in a + check(0, "in base_set did not raise error") except AttributeError: - pass + pass try: - 1 not in a - check(0, "not in base_set did not raise error") + 1 not in a + check(0, "not in base_set did not raise error") except AttributeError: - pass + pass # Test char in string @@ -46,22 +46,22 @@ check('c' in 'abc', "'c' not in 'abc'") check('d' not in 'abc', "'d' in 'abc'") try: - '' in 'abc' - check(0, "'' in 'abc' did not raise error") + '' in 'abc' + check(0, "'' in 'abc' did not raise error") except TypeError: - pass + pass try: - 'ab' in 'abc' - check(0, "'ab' in 'abc' did not raise error") + 'ab' in 'abc' + check(0, "'ab' in 'abc' did not raise error") except TypeError: - pass + pass try: - None in 'abc' - check(0, "None in 'abc' did not raise error") + None in 'abc' + check(0, "None in 'abc' did not raise error") except TypeError: - pass + pass # Test char in Unicode @@ -69,22 +69,22 @@ check('c' in u'abc', "'c' not in u'abc'") check('d' not in u'abc', "'d' in u'abc'") try: - '' in u'abc' - check(0, "'' in u'abc' did not raise error") + '' in u'abc' + check(0, "'' in u'abc' did not raise error") except TypeError: - pass + pass try: - 'ab' in u'abc' - check(0, "'ab' in u'abc' did not raise error") + 'ab' in u'abc' + check(0, "'ab' in u'abc' did not raise error") except TypeError: - pass + pass try: - None in u'abc' - check(0, "None in u'abc' did not raise error") + None in u'abc' + check(0, "None in u'abc' did not raise error") except TypeError: - pass + pass # Test Unicode char in Unicode @@ -92,16 +92,16 @@ check(u'c' in u'abc', "u'c' not in u'abc'") check(u'd' not in u'abc', "u'd' in u'abc'") try: - u'' in u'abc' - check(0, "u'' in u'abc' did not raise error") + u'' in u'abc' + check(0, "u'' in u'abc' did not raise error") except TypeError: - pass + pass try: - u'ab' in u'abc' - check(0, "u'ab' in u'abc' did not raise error") + u'ab' in u'abc' + check(0, "u'ab' in u'abc' did not raise error") except TypeError: - pass + pass # Test Unicode char in string @@ -109,60 +109,60 @@ check(u'c' in 'abc', "u'c' not in 'abc'") check(u'd' not in 'abc', "u'd' in 'abc'") try: - u'' in 'abc' - check(0, "u'' in 'abc' did not raise error") + u'' in 'abc' + check(0, "u'' in 'abc' did not raise error") except TypeError: - pass + pass try: - u'ab' in 'abc' - check(0, "u'ab' in 'abc' did not raise error") + u'ab' in 'abc' + check(0, "u'ab' in 'abc' did not raise error") except TypeError: - pass + pass # A collection of tests on builtin sequence types a = range(10) for i in a: - check(i in a, "%s not in %s" % (`i`, `a`)) + check(i in a, "%s not in %s" % (`i`, `a`)) check(16 not in a, "16 not in %s" % `a`) check(a not in a, "%s not in %s" % (`a`, `a`)) a = tuple(a) for i in a: - check(i in a, "%s not in %s" % (`i`, `a`)) + check(i in a, "%s not in %s" % (`i`, `a`)) check(16 not in a, "16 not in %s" % `a`) check(a not in a, "%s not in %s" % (`a`, `a`)) class Deviant1: - """Behaves strangely when compared + """Behaves strangely when compared - This class is designed to make sure that the contains code - works when the list is modified during the check. - """ + This class is designed to make sure that the contains code + works when the list is modified during the check. + """ - aList = range(15) - - def __cmp__(self, other): - if other == 12: - self.aList.remove(12) - self.aList.remove(13) - self.aList.remove(14) - return 1 + aList = range(15) + + def __cmp__(self, other): + if other == 12: + self.aList.remove(12) + self.aList.remove(13) + self.aList.remove(14) + return 1 check(Deviant1() not in Deviant1.aList, "Deviant1 failed") class Deviant2: - """Behaves strangely when compared + """Behaves strangely when compared - This class raises an exception during comparison. That in - turn causes the comparison to fail with a TypeError. - """ + This class raises an exception during comparison. That in + turn causes the comparison to fail with a TypeError. + """ - def __cmp__(self, other): - if other == 4: - raise RuntimeError, "gotcha" + def __cmp__(self, other): + if other == 4: + raise RuntimeError, "gotcha" try: - check(Deviant2() not in a, "oops") + check(Deviant2() not in a, "oops") except TypeError: - pass + pass diff --git a/Lib/test/test_cookie.py b/Lib/test/test_cookie.py index a275cf2..bf3e9af 100644 --- a/Lib/test/test_cookie.py +++ b/Lib/test/test_cookie.py @@ -1,4 +1,3 @@ - # Simple test suite for Cookie.py import Cookie @@ -8,8 +7,8 @@ import Cookie cases = [ ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}), ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";', - {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}), - ] + {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}), + ] for data, dict in cases: C = Cookie.SimpleCookie() ; C.load(data) @@ -37,4 +36,3 @@ C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"') assert C['Customer'].value == 'WILE_E_COYOTE' assert C['Customer']['version'] == '1' assert C['Customer']['path'] == '/acme' - diff --git a/Lib/test/test_crypt.py b/Lib/test/test_crypt.py index 0685c95..9fb93dd 100755 --- a/Lib/test/test_crypt.py +++ b/Lib/test/test_crypt.py @@ -3,7 +3,7 @@ Roger E. Masse """ -from test_support import verbose +from test_support import verbose import crypt c = crypt.crypt('mypassword', 'ab') diff --git a/Lib/test/test_dospath.py b/Lib/test/test_dospath.py index ffa3ef7..08d32da 100644 --- a/Lib/test/test_dospath.py +++ b/Lib/test/test_dospath.py @@ -5,16 +5,16 @@ import os errors = 0 def tester(fn, wantResult): - fn = string.replace(fn, "\\", "\\\\") - gotResult = eval(fn) - if wantResult != gotResult: - print "error!" - print "evaluated: " + str(fn) - print "should be: " + str(wantResult) - print " returned: " + str(gotResult) - print "" - global errors - errors = errors + 1 + fn = string.replace(fn, "\\", "\\\\") + gotResult = eval(fn) + if wantResult != gotResult: + print "error!" + print "evaluated: " + str(fn) + print "should be: " + str(wantResult) + print " returned: " + str(gotResult) + print "" + global errors + errors = errors + 1 tester('dospath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar')) tester('dospath.splitdrive("c:/foo/bar")', ('c:', '/foo/bar')) @@ -43,7 +43,6 @@ tester('dospath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', "/home/swen/spam") if errors: - print str(errors) + " errors." + print str(errors) + " errors." else: - print "No errors. Thank your lucky stars." - + print "No errors. Thank your lucky stars." diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index de2312b..10e4d6c 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -27,21 +27,21 @@ except TypeError, err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" - + try: g(*()) except TypeError, err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" - + try: g(*(), **{}) except TypeError, err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" - + g(1) g(1, 2) g(1, 2, 3) @@ -63,7 +63,7 @@ except AttributeError, attr: pass else: print "should raise AttributeError: __getitem__" - + class Nothing: def __len__(self): return 5 @@ -92,14 +92,14 @@ kw = saboteur(a=1, **d) assert d == {} # break the cycle del kw['x'] - + try: g(1, 2, 3, **{'x':4, 'y':5}) except TypeError, err: print err else: print "should raise TypeError: keyword parameter redefined" - + try: g(1, 2, 3, a=4, b=5, *(6, 7), **{'a':8, 'b':9}) except TypeError, err: diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 18b7237..b6d4dfa 100755 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -15,7 +15,7 @@ f = open(filename, 'w') rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK) if verbose: print 'Status from fnctl with O_NONBLOCK: ', rv - + if sys.platform in ('netbsd1', 'Darwin1.2', 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'bsdos2', 'bsdos3', 'bsdos4', @@ -27,7 +27,7 @@ else: lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0) if verbose: print 'struct.pack: ', `lockdata` - + rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata) if verbose: print 'String from fcntl with F_SETLKW: ', `rv` diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index da0b141..f4714d5 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -134,15 +134,15 @@ def test_del(): gc.enable() gc.set_threshold(1) - class A: - def __del__(self): - dir(self) + class A: + def __del__(self): + dir(self) a = A() del a gc.disable() apply(gc.set_threshold, thresholds) - + def test_all(): run_test("lists", test_list) @@ -161,7 +161,7 @@ def test(): print "disabling automatic collection" enabled = gc.isenabled() gc.disable() - assert not gc.isenabled() + assert not gc.isenabled() debug = gc.get_debug() gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak diff --git a/Lib/test/test_gdbm.py b/Lib/test/test_gdbm.py index 030218e..900d737 100755 --- a/Lib/test/test_gdbm.py +++ b/Lib/test/test_gdbm.py @@ -2,7 +2,7 @@ """Test script for the gdbm module Roger E. Masse """ - + import gdbm from gdbm import error from test_support import verbose, TestFailed @@ -15,7 +15,7 @@ g['12345678910'] = '019237410982340912840198242' a = g.keys() if verbose: print 'Test gdbm file keys: ', a - + g.has_key('a') g.close() try: diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index d31cac2..56a8524 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -2,7 +2,7 @@ import os import base64 import gettext - + def test_api_1(localedir, mofile): print 'test api 1' @@ -56,7 +56,7 @@ gettext message catalog library.''') print _('mullusk') - + def test_api_2(localedir, mofile): print 'test api 2' @@ -104,7 +104,7 @@ gettext message catalog library.''') return gettext.dgettext('gettext') - + GNU_MO_DATA = '''\ 3hIElQAAAAAFAAAAHAAAAEQAAAAHAAAAbAAAAAAAAACIAAAAFQAAAIkAAAChAAAAnwAAAAcAAABB AQAACwAAAEkBAAAbAQAAVQEAABYAAABxAgAAoQAAAIgCAAAFAAAAKgMAAAkAAAAwAwAAAQAAAAQA @@ -123,7 +123,7 @@ bCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1ciBUQUgKdHJnZ3JrZyB6cmZmbnRyIHBuZ255 YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA== ''' - + LOCALEDIR = os.path.join('xx', 'LC_MESSAGES') MOFILE = os.path.join(LOCALEDIR, 'gettext.mo') @@ -147,7 +147,7 @@ finally: pass - + # For reference, here's the .po file used to created the .mo data above. ''' diff --git a/Lib/test/test_gl.py b/Lib/test/test_gl.py index 1282fc4..61eaa83 100755 --- a/Lib/test/test_gl.py +++ b/Lib/test/test_gl.py @@ -146,5 +146,5 @@ def main(): if verbose: print 'winclose' gl.winclose(w) - + main() diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 0ca5a46..7dcad07 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -25,37 +25,37 @@ if 0xff <> 255: raise TestFailed, 'hex int' if 0377 <> 255: raise TestFailed, 'octal int' if 2147483647 != 017777777777: raise TestFailed, 'large positive int' try: - from sys import maxint + from sys import maxint except ImportError: - maxint = 2147483647 + maxint = 2147483647 if maxint == 2147483647: - if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int' - # XXX -2147483648 - if 037777777777 != -1: raise TestFailed, 'oct -1' - if 0xffffffff != -1: raise TestFailed, 'hex -1' - for s in '2147483648', '040000000000', '0x100000000': - try: - x = eval(s) - except OverflowError: - continue -## raise TestFailed, \ - print \ - 'No OverflowError on huge integer literal ' + `s` + if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int' + # XXX -2147483648 + if 037777777777 != -1: raise TestFailed, 'oct -1' + if 0xffffffff != -1: raise TestFailed, 'hex -1' + for s in '2147483648', '040000000000', '0x100000000': + try: + x = eval(s) + except OverflowError: + continue +## raise TestFailed, \ + print \ + 'No OverflowError on huge integer literal ' + `s` elif eval('maxint == 9223372036854775807'): - if eval('-9223372036854775807-1 != 01000000000000000000000'): - raise TestFailed, 'max negative int' - if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1' - if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1' - for s in '9223372036854775808', '02000000000000000000000', \ - '0x10000000000000000': - try: - x = eval(s) - except OverflowError: - continue - raise TestFailed, \ - 'No OverflowError on huge integer literal ' + `s` + if eval('-9223372036854775807-1 != 01000000000000000000000'): + raise TestFailed, 'max negative int' + if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1' + if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1' + for s in '9223372036854775808', '02000000000000000000000', \ + '0x10000000000000000': + try: + x = eval(s) + except OverflowError: + continue + raise TestFailed, \ + 'No OverflowError on huge integer literal ' + `s` else: - print 'Weird maxint value', maxint + print 'Weird maxint value', maxint print '1.1.2.2 Long integers' x = 0L @@ -84,7 +84,7 @@ x = 3.1e4 print '1.1.3 String literals' ##def assert(s): -## if not s: raise TestFailed, 'see traceback' +## if not s: raise TestFailed, 'see traceback' x = ''; y = ""; assert(len(x) == 0 and x == y) x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39) @@ -142,11 +142,11 @@ print 'funcdef' ### parameters: '(' [varargslist] ')' ### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME] ### | ('**'|'*' '*') NAME) -### | fpdef ['=' test] (',' fpdef ['=' test])* [','] +### | fpdef ['=' test] (',' fpdef ['=' test])* [','] ### fpdef: NAME | '(' fplist ')' ### fplist: fpdef (',' fpdef)* [','] ### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test) -### argument: [test '='] test # Really [keyword '='] test +### argument: [test '='] test # Really [keyword '='] test def f1(): pass f1() f1(*()) @@ -270,7 +270,7 @@ print >> sys.stdout, 0 or 1 # test printing to an instance class Gulp: - def write(self, msg): pass + def write(self, msg): pass gulp = Gulp() print >> gulp, 1, 2, 3 @@ -281,34 +281,34 @@ print >> gulp, 0 or 1 # test print >> None def driver(): - oldstdout = sys.stdout - sys.stdout = Gulp() - try: - tellme(Gulp()) - tellme() - finally: - sys.stdout = oldstdout + oldstdout = sys.stdout + sys.stdout = Gulp() + try: + tellme(Gulp()) + tellme() + finally: + sys.stdout = oldstdout # we should see this once def tellme(file=sys.stdout): - print >> file, 'hello world' + print >> file, 'hello world' driver() # we should not see this at all def tellme(file=None): - print >> file, 'goodbye universe' + print >> file, 'goodbye universe' driver() # syntax errors def check_syntax(statement): - try: - compile(statement, '', 'exec') - except SyntaxError: - pass - else: - print 'Missing SyntaxError: "%s"' % statement + try: + compile(statement, '', 'exec') + except SyntaxError: + pass + else: + print 'Missing SyntaxError: "%s"' % statement check_syntax('print ,') check_syntax('print >> x,') @@ -350,26 +350,26 @@ from sys import path, argv print 'global_stmt' # 'global' NAME (',' NAME)* def f(): - global a - global a, b - global one, two, three, four, five, six, seven, eight, nine, ten + global a + global a, b + global one, two, three, four, five, six, seven, eight, nine, ten print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]] def f(): - z = None - del z - exec 'z=1+1\n' - if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n' - del z - exec 'z=1+1' - if z <> 2: raise TestFailed, 'exec \'z=1+1\'' - z = None - del z - exec u'z=1+1\n' - if z <> 2: raise TestFailed, 'exec u\'z=1+1\'\\n' - del z - exec u'z=1+1' - if z <> 2: raise TestFailed, 'exec u\'z=1+1\'' + z = None + del z + exec 'z=1+1\n' + if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n' + del z + exec 'z=1+1' + if z <> 2: raise TestFailed, 'exec \'z=1+1\'' + z = None + del z + exec u'z=1+1\n' + if z <> 2: raise TestFailed, 'exec u\'z=1+1\'\\n' + del z + exec u'z=1+1' + if z <> 2: raise TestFailed, 'exec u\'z=1+1\'' f() g = {} exec 'z = 1' in g @@ -408,17 +408,17 @@ for i in 1, 2, 3: pass for i, j, k in (): pass else: pass class Squares: - def __init__(self, max): - self.max = max - self.sofar = [] - def __len__(self): return len(self.sofar) - def __getitem__(self, i): - if not 0 <= i < self.max: raise IndexError - n = len(self.sofar) - while n <= i: - self.sofar.append(n*n) - n = n+1 - return self.sofar[i] + def __init__(self, max): + self.max = max + self.sofar = [] + def __len__(self): return len(self.sofar) + def __getitem__(self, i): + if not 0 <= i < self.max: raise IndexError + n = len(self.sofar) + while n <= i: + self.sofar.append(n*n) + n = n+1 + return self.sofar[i] n = 0 for x in Squares(10): n = n+x if n != 285: raise TestFailed, 'for over growing sequence' @@ -428,11 +428,11 @@ print 'try_stmt' ### | 'try' ':' suite 'finally' ':' suite ### except_clause: 'except' [expr [',' expr]] try: - 1/0 + 1/0 except ZeroDivisionError: - pass + pass else: - pass + pass try: 1/0 except EOFError: pass except TypeError, msg: pass @@ -449,16 +449,16 @@ finally: pass print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT if 1: pass if 1: - pass + pass if 1: - # - # - # - pass - pass - # - pass - # + # + # + # + pass + pass + # + pass + # print 'test' ### and_test ('or' and_test)* @@ -598,9 +598,9 @@ class C1(B): pass class C2(B): pass class D(C1, C2, B): pass class C: - def meth1(self): pass - def meth2(self, arg): pass - def meth3(self, a1, a2): pass + def meth1(self): pass + def meth2(self, arg): pass + def meth3(self, a1, a2): pass # list comprehension tests nums = [1, 2, 3, 4, 5] @@ -622,7 +622,7 @@ try: eval("[x if y]") print "FAIL: should have raised a SyntaxError!" except SyntaxError: - print "good: got a SyntaxError as expected" + print "good: got a SyntaxError as expected" suppliers = [ (1, "Boeing"), diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py index bfe3a76..b737da9 100755 --- a/Lib/test/test_grp.py +++ b/Lib/test/test_grp.py @@ -2,7 +2,7 @@ """Test script for the grp module Roger E. Masse """ - + import grp from test_support import verbose diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 2366d02..7edc617 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -1,4 +1,3 @@ - import sys, os import gzip, tempfile @@ -38,7 +37,7 @@ while 1: line_length = (line_length + 1) % 50 f.close() -# Try .readlines() +# Try .readlines() f = gzip.GzipFile(filename, 'rb') L = f.readlines() @@ -47,7 +46,7 @@ f.close() f = gzip.GzipFile(filename, 'rb') while 1: L = f.readlines(150) - if L == []: break + if L == []: break f.close() diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index 51b4c33..d5ac026 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -6,12 +6,12 @@ import test_support def same_hash(*objlist): - # hash each object given an raise TestFailed if - # the hash values are not all the same - hashed = map(hash, objlist) - for h in hashed[1:]: - if h != hashed[0]: - raise TestFailed, "hashed values differ: %s" % `objlist` + # hash each object given an raise TestFailed if + # the hash values are not all the same + hashed = map(hash, objlist) + for h in hashed[1:]: + if h != hashed[0]: + raise TestFailed, "hashed values differ: %s" % `objlist` @@ -21,6 +21,3 @@ same_hash(int(1), long(1), float(1), complex(1)) same_hash(long(1.23e300), float(1.23e300)) same_hash(float(0.5), complex(0.5, 0.0)) - - - diff --git a/Lib/test/test_imageop.py b/Lib/test/test_imageop.py index 6b144c6..7a6981e 100755 --- a/Lib/test/test_imageop.py +++ b/Lib/test/test_imageop.py @@ -18,7 +18,7 @@ def main(use_rgbimg=1): image, width, height = getrgbimage('test.rgb') else: image, width, height = getimage('test.rgb') - + # Return the selected part of image, which should by width by height # in size and consist of pixels of psize bytes. if verbose: @@ -28,7 +28,7 @@ def main(use_rgbimg=1): # Return image scaled to size newwidth by newheight. No interpolation # is done, scaling is done by simple-minded pixel duplication or removal. # Therefore, computer-generated images or dithered images will - # not look nice after scaling. + # not look nice after scaling. if verbose: print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) @@ -36,7 +36,7 @@ def main(use_rgbimg=1): # Run a vertical low-pass filter over an image. It does so by computing # each destination pixel as the average of two vertically-aligned source # pixels. The main use of this routine is to forestall excessive flicker - # if the image two vertically-aligned source pixels, hence the name. + # if the image two vertically-aligned source pixels, hence the name. if verbose: print 'tovideo' videoimage = imageop.tovideo (image, 4, width, height) @@ -50,7 +50,7 @@ def main(use_rgbimg=1): if verbose: print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) - + # Convert an rgb image to an 8 bit greyscale image if verbose: print 'rgb2grey' @@ -60,13 +60,13 @@ def main(use_rgbimg=1): if verbose: print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) - + # Convert a 8-bit deep greyscale image to a 1-bit deep image by # thresholding all the pixels. The resulting image is tightly packed - # and is probably only useful as an argument to mono2grey. + # and is probably only useful as an argument to mono2grey. if verbose: print 'grey2mono' - monoimage = imageop.grey2mono (greyimage, width, height, 0) + monoimage = imageop.grey2mono (greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. @@ -85,30 +85,30 @@ def main(use_rgbimg=1): monoimage = imageop.dither2mono (greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without - # dithering. + # dithering. if verbose: print 'grey2grey4' - grey4image = imageop.grey2grey4 (greyimage, width, height) + grey4image = imageop.grey2grey4 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without - # dithering. + # dithering. if verbose: print 'grey2grey2' - grey2image = imageop.grey2grey2 (greyimage, width, height) + grey2image = imageop.grey2grey2 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image with # dithering. As for dither2mono, the dithering algorithm is currently - # very simple. + # very simple. if verbose: print 'dither2grey2' - grey2image = imageop.dither2grey2 (greyimage, width, height) + grey2image = imageop.dither2grey2 (greyimage, width, height) - # Convert a 4-bit greyscale image to an 8-bit greyscale image. + # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey42grey' - greyimage = imageop.grey42grey (grey4image, width, height) + greyimage = imageop.grey42grey (grey4image, width, height) - # Convert a 2-bit greyscale image to an 8-bit greyscale image. + # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' image = imageop.grey22grey (grey2image, width, height) @@ -132,14 +132,14 @@ def getrgbimage(name): image = rgbimg.longimagedata(name) return (image, sizes[0], sizes[1]) - + def getimage(name): """return a tuple consisting of image (in 'imgfile' format) width and height """ import imgfile - + try: sizes = imgfile.getsizes(name) except imgfile.error: diff --git a/Lib/test/test_imgfile.py b/Lib/test/test_imgfile.py index b074320..8eb330d 100755 --- a/Lib/test/test_imgfile.py +++ b/Lib/test/test_imgfile.py @@ -8,7 +8,7 @@ from test_support import verbose, unlink, findfile import imgfile, uu, os - + def main(): uu.decode(findfile('testrgb.uue'), 'test.rgb') @@ -16,7 +16,7 @@ def main(): # Test a 3 byte color image testimage('test.rgb') - + # Test a 1 byte greyscale image testimage('greytest.rgb') @@ -57,18 +57,18 @@ def testimage(name): # and returns it as a python string. The string has either 1 byte # greyscale pixels or 4 byte RGBA pixels. The bottom left pixel # is the first in the string. This format is suitable to pass - # to gl.lrectwrite, for instance. + # to gl.lrectwrite, for instance. image = imgfile.read(name) - + # This function writes the RGB or greyscale data in data to # image file file. x and y give the size of the image, z is # 1 for 1 byte greyscale images or 3 for RGB images (which # are stored as 4 byte values of which only the lower three - # bytes are used). These are the formats returned by gl.lrectread. + # bytes are used). These are the formats returned by gl.lrectread. if verbose: print 'Writing output file' - imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2]) - + imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2]) + if verbose: print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes)) @@ -91,18 +91,18 @@ def testimage(name): # This function sets a global flag which defines whether the # scan lines of the image are read or written from bottom to # top (flag is zero, compatible with SGI GL) or from top to - # bottom(flag is one, compatible with X). The default is zero. + # bottom(flag is one, compatible with X). The default is zero. if verbose: print 'Switching to X compatibility' - imgfile.ttob (1) + imgfile.ttob (1) if verbose: print 'Filtering with "triangle"' simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'triangle', 3.0) if verbose: print 'Switching back to SGI compatibility' - imgfile.ttob (0) - + imgfile.ttob (0) + if verbose: print 'Filtering with "quadratic"' simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic') if verbose: print 'Filtering with "gaussian"' @@ -110,7 +110,7 @@ def testimage(name): if verbose: print 'Writing output file' - imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2]) + imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2]) os.unlink(outputfile) diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 3f0785c..58de293 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -56,7 +56,7 @@ def expect(got_this, expect_this): # we have to check >4GB) files if test_support.verbose: - print 'create large file via seek (may be sparse file) ...' + print 'create large file via seek (may be sparse file) ...' f = open(name, 'w') f.seek(size) f.write('a') @@ -117,16 +117,16 @@ f.close() # XXX has truncate ever worked on Windows? specifically on WinNT I get: # "IOError: [Errno 13] Permission denied" ##try: -## newsize = size - 10 -## f.seek(newsize) -## f.truncate() -## expect(f.tell(), newsize) -## newsize = newsize - 1 -## f.seek(0) -## f.truncate(newsize) -## expect(f.tell(), newsize) +## newsize = size - 10 +## f.seek(newsize) +## f.truncate() +## expect(f.tell(), newsize) +## newsize = newsize - 1 +## f.seek(0) +## f.truncate(newsize) +## expect(f.tell(), newsize) ##except AttributeError: -## pass +## pass os.unlink(name) print >>sys.stderr, name, "exists:", os.path.exists(name) diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 6a1f117..5e0e001 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -257,4 +257,3 @@ test_division() test_bitop_identities() test_format() test_misc() - diff --git a/Lib/test/test_longexp.py b/Lib/test/test_longexp.py index 2d57285..243b28a 100644 --- a/Lib/test/test_longexp.py +++ b/Lib/test/test_longexp.py @@ -1,4 +1,4 @@ REPS = 65580 -l = eval("[" + "2," * REPS + "]") -print len(l) +l = eval("[" + "2," * REPS + "]") +print len(l) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index b7fde0a..888d277 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -9,9 +9,9 @@ print 'math module, testing with eps', seps import math def testit(name, value, expected): - if abs(value-expected) > eps: - raise TestFailed, '%s returned %f, expected %f'%\ - (name, value, expected) + if abs(value-expected) > eps: + raise TestFailed, '%s returned %f, expected %f'%\ + (name, value, expected) print 'constants' testit('pi', math.pi, 3.1415926) @@ -85,9 +85,9 @@ testit('fmod(-10,1.5)', math.fmod(-10,1.5), -1) print 'frexp' def testfrexp(name, (mant, exp), (emant, eexp)): - if abs(mant-emant) > eps or exp <> eexp: - raise TestFailed, '%s returned %s, expected %s'%\ - (name, `mant, exp`, `emant,eexp`) + if abs(mant-emant) > eps or exp <> eexp: + raise TestFailed, '%s returned %s, expected %s'%\ + (name, `mant, exp`, `emant,eexp`) testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1)) testfrexp('frexp(0)', math.frexp(0), (0, 0)) @@ -116,9 +116,9 @@ testit('log10(10)', math.log10(10), 1) print 'modf' def testmodf(name, (v1, v2), (e1, e2)): - if abs(v1-e1) > eps or abs(v2-e2): - raise TestFailed, '%s returned %s, expected %s'%\ - (name, `v1,v2`, `e1,e2`) + if abs(v1-e1) > eps or abs(v2-e2): + raise TestFailed, '%s returned %s, expected %s'%\ + (name, `v1,v2`, `e1,e2`) testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0)) testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0)) diff --git a/Lib/test/test_md5.py b/Lib/test/test_md5.py index 5e453fa..e2d3f22 100644 --- a/Lib/test/test_md5.py +++ b/Lib/test/test_md5.py @@ -4,15 +4,15 @@ import string from md5 import md5 def hexstr(s): - h = string.hexdigits - r = '' - for c in s: - i = ord(c) - r = r + h[(i >> 4) & 0xF] + h[i & 0xF] - return r + h = string.hexdigits + r = '' + for c in s: + i = ord(c) + r = r + h[(i >> 4) & 0xF] + h[i & 0xF] + return r def md5test(s): - return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest()) + return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest()) print 'MD5 test suite:' print md5test('') @@ -27,4 +27,4 @@ print md5test('12345678901234567890123456789012345678901234567890123456789012345 m = md5('testing the hexdigest method') h = m.hexdigest() if hexstr(m.digest()) <> h: - print 'hexdigest() failed' + print 'hexdigest() failed' diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 7afdf5d..ce7170d 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -16,9 +16,9 @@ tstfile = os.path.join(os.path.dirname(base), "test.xml") del base def confirm(test, testname = "Test"): - if test: + if test: print "Passed " + testname - else: + else: print "Failed " + testname raise Exception @@ -41,7 +41,7 @@ def testInsertBefore(): docel = dom.documentElement #docel.insertBefore( dom.createProcessingInstruction("a", "b"), # docel.childNodes[1]) - + #docel.insertBefore( dom.createProcessingInstruction("a", "b"), # docel.childNodes[0]) @@ -133,7 +133,7 @@ def testRemoveAttrNS(): dom = Document() child = dom.appendChild( dom.createElementNS("http://www.python.org", "python:abc")) - child.setAttributeNS("http://www.w3.org", "xmlns:python", + child.setAttributeNS("http://www.w3.org", "xmlns:python", "http://www.python.org") child.setAttributeNS("http://www.python.org", "python:abcattr", "foo") confirm(len(child.attributes) == 2) @@ -141,7 +141,7 @@ def testRemoveAttrNS(): confirm(len(child.attributes) == 1) dom.unlink() - + def testRemoveAttributeNode(): dom = Document() child = dom.appendChild(dom.createElement("foo")) @@ -313,11 +313,11 @@ def testSiblings(): root = doc.documentElement (pi, text, elm) = root.childNodes - confirm(pi.nextSibling is text and - pi.previousSibling is None and - text.nextSibling is elm and - text.previousSibling is pi and - elm.nextSibling is None and + confirm(pi.nextSibling is text and + pi.previousSibling is None and + text.nextSibling is elm and + text.previousSibling is pi and + elm.nextSibling is None and elm.previousSibling is text, "testSiblings") doc.unlink() @@ -347,7 +347,7 @@ def testSAX2DOM(): sax2dom.startElement("subelm", {}) sax2dom.characters("text") sax2dom.endElement("subelm") - sax2dom.characters("text") + sax2dom.characters("text") sax2dom.endElement("doc") sax2dom.endDocument() @@ -370,11 +370,11 @@ def testSAX2DOM(): elm1.parentNode is root and text2.parentNode is root and text3.parentNode is elm1, "testSAX2DOM - parents") - + doc.unlink() # --- MAIN PROGRAM - + names = globals().keys() names.sort() diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 449c674..3e2d89f 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,4 +1,3 @@ - import mmap import string, os, re, sys @@ -6,10 +5,10 @@ PAGESIZE = mmap.PAGESIZE def test_both(): "Test mmap module on Unix systems and Windows" - + # Create an mmap'ed file f = open('foo', 'w+') - + # Write 2 pages worth of data to the file f.write('\0'* PAGESIZE) f.write('foo') @@ -17,11 +16,11 @@ def test_both(): m = mmap.mmap(f.fileno(), 2 * PAGESIZE) f.close() - + # Simple sanity checks print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages' assert string.find(m, 'foo') == PAGESIZE - + print ' Length of file:', len(m) / float(PAGESIZE), 'pages' assert len(m) == 2*PAGESIZE @@ -29,12 +28,12 @@ def test_both(): assert m[0] == '\0' print ' Contents of first 3 bytes:', repr(m[0:3]) assert m[0:3] == '\0\0\0' - + # Modify the file's content print "\n Modifying file's content..." m[0] = '3' m[PAGESIZE +3: PAGESIZE +3+3]='bar' - + # Check that the modification worked print ' Contents of byte 0:', repr(m[0]) assert m[0] == '3' @@ -42,7 +41,7 @@ def test_both(): assert m[0:3] == '3\0\0' print ' Contents of second page:', repr(m[PAGESIZE-1 : PAGESIZE + 7]) assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0' - + m.flush() # Test doing a regular expression match in an mmap'ed file @@ -51,11 +50,11 @@ def test_both(): print ' ERROR: regex match on mmap failed!' else: start, end = match.span(0) - length = end - start + length = end - start print ' Regex match on mmap (page start, length of match):', print start / float(PAGESIZE), length - + assert start == PAGESIZE assert end == PAGESIZE + 6 @@ -113,7 +112,7 @@ def test_both(): pass else: assert 0, 'Could seek beyond the new size' - + m.close() os.unlink("foo") print ' Test passed' diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 11f2f44..1b49c03 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -5,16 +5,16 @@ import os errors = 0 def tester(fn, wantResult): - fn = string.replace(fn, "\\", "\\\\") - gotResult = eval(fn) - if wantResult != gotResult: - print "error!" - print "evaluated: " + str(fn) - print "should be: " + str(wantResult) - print " returned: " + str(gotResult) - print "" - global errors - errors = errors + 1 + fn = string.replace(fn, "\\", "\\\\") + gotResult = eval(fn) + if wantResult != gotResult: + print "error!" + print "evaluated: " + str(fn) + print "should be: " + str(wantResult) + print " returned: " + str(gotResult) + print "" + global errors + errors = errors + 1 tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar')) tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\foo\\bar')) @@ -45,7 +45,6 @@ tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', "/home/swen/spam") if errors: - print str(errors) + " errors." + print str(errors) + " errors." else: - print "No errors. Thank your lucky stars." - + print "No errors. Thank your lucky stars." diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index bdace26..94a0a92 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -9,18 +9,18 @@ print 'XXX Not yet fully implemented' print '2.1 try inside for loop' n = 0 for i in range(10): - n = n+i - try: 1/0 - except NameError: pass - except ZeroDivisionError: pass - except TypeError: pass - try: pass - except: pass - try: pass - finally: pass - n = n+i + n = n+i + try: 1/0 + except NameError: pass + except ZeroDivisionError: pass + except TypeError: pass + try: pass + except: pass + try: pass + finally: pass + n = n+i if n <> 90: - raise TestFailed, 'try inside for' + raise TestFailed, 'try inside for' print '2.2 raise class exceptions' @@ -50,12 +50,12 @@ b = BClass() try: raise AClass, b except BClass, v: - if v != b: raise TestFailed + if v != b: raise TestFailed else: raise TestFailed try: raise b except AClass, v: - if v != b: raise TestFailed + if v != b: raise TestFailed # not enough arguments try: raise BClass, a diff --git a/Lib/test/test_openpty.py b/Lib/test/test_openpty.py index 723e57c..fb81719 100644 --- a/Lib/test/test_openpty.py +++ b/Lib/test/test_openpty.py @@ -19,4 +19,3 @@ if not os.isatty(slave): os.write(slave, 'Ping!') print os.read(master, 1024) - diff --git a/Lib/test/test_operations.py b/Lib/test/test_operations.py index c14f480..4c76a8f 100644 --- a/Lib/test/test_operations.py +++ b/Lib/test/test_operations.py @@ -10,15 +10,15 @@ print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception' # SourceForge bug #112558: # http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470 -class BadDictKey: - def __hash__(self): - return hash(self.__class__) - - def __cmp__(self, other): - if isinstance(other, self.__class__): - print "raising error" - raise RuntimeError, "gotcha" - return other +class BadDictKey: + def __hash__(self): + return hash(self.__class__) + + def __cmp__(self, other): + if isinstance(other, self.__class__): + print "raising error" + raise RuntimeError, "gotcha" + return other d = {} x1 = BadDictKey() diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 3c81fdd..85a6daa 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -137,7 +137,7 @@ def dotest(pickle): pass else: print "accepted insecure string: %s" % repr(buf) - + import pickle dotest(pickle) diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index a0988e0..5456100 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -78,7 +78,7 @@ def runtest(hier, code): tests = [ ("t1", [("t1", None), ("t1 __init__.py", "")], "import t1"), - + ("t2", [ ("t2", None), ("t2 __init__.py", "'doc for t2'; print __name__, 'loading'"), @@ -108,7 +108,7 @@ print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__ from t2 import * print dir() """), - + ("t3", [ ("t3", None), ("t3 __init__.py", "print __name__, 'loading'"), @@ -124,7 +124,7 @@ reload(t3) reload(t3.sub) reload(t3.sub.subsub) """), - + ("t4", [ ("t4.py", "print 'THIS SHOULD NOT BE PRINTED (t4.py)'"), ("t4", None), @@ -172,7 +172,7 @@ from t6 import * print fixdir(dir(t6)) print dir() """), - + ("t7", [ ("t7.py", "print 'Importing t7.py'"), ("t7", None), diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py index 82d8372..576e4cc 100644 --- a/Lib/test/test_poll.py +++ b/Lib/test/test_poll.py @@ -1,5 +1,5 @@ # Test case for the os.poll() function - + import sys, os, select, random from test_support import verbose, TestSkipped, TESTFN diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 27bee61..45bcdc1 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -4,15 +4,15 @@ import string errors = 0 def tester(fn, wantResult): - gotResult = eval(fn) - if wantResult != gotResult: - print "error!" - print "evaluated: " + str(fn) - print "should be: " + str(wantResult) - print " returned: " + str(gotResult) - print "" - global errors - errors = errors + 1 + gotResult = eval(fn) + if wantResult != gotResult: + print "error!" + print "evaluated: " + str(fn) + print "should be: " + str(wantResult) + print " returned: " + str(gotResult) + print "" + global errors + errors = errors + 1 tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar')) @@ -36,7 +36,6 @@ tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])', "/home/swen/spam") if errors: - print str(errors) + " errors." + print str(errors) + " errors." else: - print "No errors. Thank your lucky stars." - + print "No errors. Thank your lucky stars." diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py index 22c1972..0ef6cbf 100644 --- a/Lib/test/test_pow.py +++ b/Lib/test/test_pow.py @@ -2,10 +2,10 @@ import sys import test_support def powtest(type): - if type != float: + if type != float: print " Testing 2-argument pow() function..." for i in range(-1000, 1000): - if pow(type(i), 0) != 1: + if pow(type(i), 0) != 1: raise ValueError, 'pow('+str(i)+',0) != 1' if pow(type(i), 1) != type(i): raise ValueError, 'pow('+str(i)+',1) != '+str(i) @@ -17,7 +17,7 @@ def powtest(type): for i in range(-100, 100): if pow(type(i), 3) != i*i*i: raise ValueError, 'pow('+str(i)+',3) != '+str(i*i*i) - + pow2 = 1 for i in range(0,31): if pow(2, i) != pow2: @@ -62,13 +62,13 @@ def powtest(type): elif type == long: jl, jh = 0, 15 for i in range(il, ih+1): - for j in range(jl, jh+1): - for k in range(kl, kh+1): - if k != 0: - if compare(pow(type(i),j,k), pow(type(i),j)% type(k)): - raise ValueError, "pow(" +str(i)+ "," +str(j)+ \ - "," +str(k)+ ") != pow(" +str(i)+ "," + \ - str(j)+ ") % " +str(k) + for j in range(jl, jh+1): + for k in range(kl, kh+1): + if k != 0: + if compare(pow(type(i),j,k), pow(type(i),j)% type(k)): + raise ValueError, "pow(" +str(i)+ "," +str(j)+ \ + "," +str(k)+ ") != pow(" +str(i)+ "," + \ + str(j)+ ") % " +str(k) print 'Testing integer mode...' @@ -104,17 +104,17 @@ print pow(5.0,2) % -8, pow(5.0,2,-8) print for i in range(-10, 11): - for j in range(0, 6): - for k in range(-7, 11): - if j >= 0 and k != 0: - o = pow(i,j) % k - n = pow(i,j,k) - if o != n: print 'Integer mismatch:', i,j,k - if j >= 0 and k <> 0: - o = pow(long(i),j) % k - n = pow(long(i),j,k) - if o != n: print 'Long mismatch:', i,j,k - if i >= 0 and k <> 0: - o = pow(float(i),j) % k - n = pow(float(i),j,k) - if o != n: print 'Float mismatch:', i,j,k + for j in range(0, 6): + for k in range(-7, 11): + if j >= 0 and k != 0: + o = pow(i,j) % k + n = pow(i,j,k) + if o != n: print 'Integer mismatch:', i,j,k + if j >= 0 and k <> 0: + o = pow(long(i),j) % k + n = pow(long(i),j,k) + if o != n: print 'Long mismatch:', i,j,k + if i >= 0 and k <> 0: + o = pow(float(i),j) % k + n = pow(float(i),j,k) + if o != n: print 'Float mismatch:', i,j,k diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 69379b1..53769c0 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -88,4 +88,3 @@ else: os.close(master_fd) # pty.fork() passed. - diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index edd40f4..7e9db21 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -51,7 +51,7 @@ while bynames.has_key(fakename): # should never happen... if so, just forget it break fakename = string.join(map(None, chars), '') - + try: pwd.getpwnam(fakename) except KeyError: diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index a119987..fae1849 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -2,13 +2,13 @@ # XXX TypeErrors on calling handlers, or on bad return values from a # handler, are obscure and unhelpful. - + from xml.parsers import expat - + class Outputter: def StartElementHandler(self, name, attrs): print 'Start element:\n\t', repr(name), attrs - + def EndElementHandler(self, name): print 'End element:\n\t', repr(name) @@ -43,11 +43,11 @@ class Outputter: def UnparsedEntityDeclHandler(self, *args): entityName, base, systemId, publicId, notationName = args print 'Unparsed entity decl:\n\t', args - + def NotStandaloneHandler(self, userData): print 'Not standalone' return 1 - + def ExternalEntityRefHandler(self, *args): context, base, sysId, pubId = args print 'External entity ref:', args diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 47cfbe0..2dfa2bb 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -351,7 +351,7 @@ for t in tests: # string), so we'll ignore patterns that feature it. if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \ - and result != None: + and result != None: obj = re.compile(pattern) result = obj.search(s, result.start(0), result.end(0) + 1) if result == None: diff --git a/Lib/test/test_regex.py b/Lib/test/test_regex.py index 6a7f01b..3bb78ef 100644 --- a/Lib/test/test_regex.py +++ b/Lib/test/test_regex.py @@ -69,7 +69,7 @@ for t in tests: if len(t)==5: pattern, s, outcome, repl, expected = t elif len(t)==3: - pattern, s, outcome = t + pattern, s, outcome = t else: raise ValueError, ('Test tuples should have 3 or 5 fields',t) @@ -77,8 +77,8 @@ for t in tests: obj=regex.compile(pattern) except regex.error: if outcome==SYNTAX_ERROR: pass # Expected a syntax error - else: - # Regex syntax errors aren't yet reported, so for + else: + # Regex syntax errors aren't yet reported, so for # the official test suite they'll be quietly ignored. pass #print '=== Syntax error:', t diff --git a/Lib/test/test_rgbimg.py b/Lib/test/test_rgbimg.py index 1fa201d..f2622e4 100644 --- a/Lib/test/test_rgbimg.py +++ b/Lib/test/test_rgbimg.py @@ -5,24 +5,24 @@ import rgbimg, os, uu from test_support import verbose, unlink, findfile class error(Exception): - pass + pass print 'RGBimg test suite:' def testimg(rgb_file, raw_file): - rgb_file = findfile(rgb_file) - raw_file = findfile(raw_file) - width, height = rgbimg.sizeofimage(rgb_file) - rgb = rgbimg.longimagedata(rgb_file) - if len(rgb) != width * height * 4: - raise error, 'bad image length' - raw = open(raw_file, 'rb').read() - if rgb != raw: - raise error, \ - 'images don\'t match for '+rgb_file+' and '+raw_file - for depth in [1, 3, 4]: - rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') - os.unlink('@.rgb') + rgb_file = findfile(rgb_file) + raw_file = findfile(raw_file) + width, height = rgbimg.sizeofimage(rgb_file) + rgb = rgbimg.longimagedata(rgb_file) + if len(rgb) != width * height * 4: + raise error, 'bad image length' + raw = open(raw_file, 'rb').read() + if rgb != raw: + raise error, \ + 'images don\'t match for '+rgb_file+' and '+raw_file + for depth in [1, 3, 4]: + rgbimg.longstoimage(rgb, width, height, depth, '@.rgb') + os.unlink('@.rgb') table = [ ('testrgb.uue', 'test.rgb'), @@ -41,23 +41,23 @@ if verbose: ttob = rgbimg.ttob(0) if ttob != 0: - raise error, 'ttob should start out as zero' + raise error, 'ttob should start out as zero' testimg('test.rgb', 'test.rawimg') ttob = rgbimg.ttob(1) if ttob != 0: - raise error, 'ttob should be zero' + raise error, 'ttob should be zero' testimg('test.rgb', 'test.rawimg.rev') ttob = rgbimg.ttob(0) if ttob != 1: - raise error, 'ttob should be one' + raise error, 'ttob should be one' ttob = rgbimg.ttob(0) if ttob != 0: - raise error, 'ttob should be zero' + raise error, 'ttob should be zero' for source, target in table: unlink(findfile(target)) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index e080217..26fd873 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -1,4 +1,3 @@ - # regression test for SAX 2.0 # $Id$ @@ -75,7 +74,7 @@ def test_xmlgen_basic(): def test_xmlgen_content(): result = StringIO() gen = XMLGenerator(result) - + gen.startDocument() gen.startElement("doc", {}) gen.characters("huhei") @@ -87,7 +86,7 @@ def test_xmlgen_content(): def test_xmlgen_pi(): result = StringIO() gen = XMLGenerator(result) - + gen.startDocument() gen.processingInstruction("test", "data") gen.startElement("doc", {}) @@ -99,7 +98,7 @@ def test_xmlgen_pi(): def test_xmlgen_content_escape(): result = StringIO() gen = XMLGenerator(result) - + gen.startDocument() gen.startElement("doc", {}) gen.characters("" - + # ===== Attributes support class AttrGatherer(ContentHandler): @@ -224,7 +223,7 @@ class AttrGatherer(ContentHandler): def startElementNS(self, name, qname, attrs): self._attrs = attrs - + def test_expat_attrs_empty(): parser = create_parser() gather = AttrGatherer() @@ -264,7 +263,7 @@ def test_expat_nsattrs_wattr(): parser.close() attrs = gather._attrs - + return attrs.getLength() == 1 and \ attrs.getNames() == [(ns_uri, "attr")] and \ attrs.getQNames() == [] and \ @@ -376,13 +375,13 @@ def verify_empty_attrs(attrs): gqnk = 0 except KeyError: gqnk = 1 - + try: attrs["attr"] gik = 0 except KeyError: gik = 1 - + return attrs.getLength() == 0 and \ attrs.getNames() == [] and \ attrs.getQNames() == [] and \ @@ -444,13 +443,13 @@ def verify_empty_nsattrs(attrs): gqnk = 0 except KeyError: gqnk = 1 - + try: attrs[(ns_uri, "attr")] gik = 0 except KeyError: gik = 1 - + return attrs.getLength() == 0 and \ attrs.getNames() == [] and \ attrs.getQNames() == [] and \ @@ -469,7 +468,7 @@ def test_nsattrs_empty(): def test_nsattrs_wattr(): attrs = AttributesNSImpl({(ns_uri, "attr") : "val"}, {(ns_uri, "attr") : "ns:attr"}) - + return attrs.getLength() == 1 and \ attrs.getNames() == [(ns_uri, "attr")] and \ attrs.getQNames() == ["ns:attr"] and \ @@ -485,7 +484,7 @@ def test_nsattrs_wattr(): attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \ attrs[(ns_uri, "attr")] == "val" and \ attrs.getQNameByName((ns_uri, "attr")) == "ns:attr" - + # ===== Main program diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py index b198cf1..d5bcfd5 100644 --- a/Lib/test/test_select.py +++ b/Lib/test/test_select.py @@ -17,7 +17,7 @@ class Nope: class Almost: def fileno(self): return 'fileno' - + try: rfd, wfd, xfd = select.select([Nope()], [], []) except TypeError: @@ -34,30 +34,29 @@ else: def test(): - import sys - if sys.platform[:3] in ('win', 'mac', 'os2'): - if verbose: - print "Can't test select easily on", sys.platform - return - cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' - p = os.popen(cmd, 'r') - for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: + import sys + if sys.platform[:3] in ('win', 'mac', 'os2'): + if verbose: + print "Can't test select easily on", sys.platform + return + cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done' + p = os.popen(cmd, 'r') + for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: + if verbose: + print 'timeout =', tout + rfd, wfd, xfd = select.select([p], [], [], tout) + if (rfd, wfd, xfd) == ([], [], []): + continue + if (rfd, wfd, xfd) == ([p], [], []): + line = p.readline() + if verbose: + print `line` + if not line: if verbose: - print 'timeout =', tout - rfd, wfd, xfd = select.select([p], [], [], tout) - if (rfd, wfd, xfd) == ([], [], []): - continue - if (rfd, wfd, xfd) == ([p], [], []): - line = p.readline() - if verbose: - print `line` - if not line: - if verbose: - print 'EOF' - break - continue - print 'Unexpected return values from select():', rfd, wfd, xfd - p.close() + print 'EOF' + break + continue + print 'Unexpected return values from select():', rfd, wfd, xfd + p.close() test() - diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 02b5dc3..a6c32b4 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -8,36 +8,36 @@ if sys.platform[:3] in ('win', 'os2'): raise TestSkipped, "Can't test signal on %s" % sys.platform[:3] if verbose: - x = '-x' + x = '-x' else: - x = '+x' + x = '+x' pid = os.getpid() # Shell script that will send us asynchronous signals script = """ ( - set %(x)s - sleep 2 - kill -5 %(pid)d - sleep 2 - kill -2 %(pid)d - sleep 2 - kill -3 %(pid)d + set %(x)s + sleep 2 + kill -5 %(pid)d + sleep 2 + kill -2 %(pid)d + sleep 2 + kill -3 %(pid)d ) & """ % vars() def handlerA(*args): - if verbose: - print "handlerA", args + if verbose: + print "handlerA", args -HandlerBCalled = "HandlerBCalled" # Exception +HandlerBCalled = "HandlerBCalled" # Exception def handlerB(*args): - if verbose: - print "handlerB", args - raise HandlerBCalled, args + if verbose: + print "handlerB", args + raise HandlerBCalled, args -signal.alarm(20) # Entire test lasts at most 20 sec. +signal.alarm(20) # Entire test lasts at most 20 sec. signal.signal(5, handlerA) signal.signal(2, handlerB) signal.signal(3, signal.SIG_IGN) @@ -48,19 +48,19 @@ os.system(script) print "starting pause() loop..." try: - while 1: - if verbose: - print "call pause()..." - try: - signal.pause() - if verbose: - print "pause() returned" - except HandlerBCalled: - if verbose: - print "HandlerBCalled exception caught" - else: - pass - + while 1: + if verbose: + print "call pause()..." + try: + signal.pause() + if verbose: + print "pause() returned" + except HandlerBCalled: + if verbose: + print "HandlerBCalled exception caught" + else: + pass + except KeyboardInterrupt: - if verbose: - print "KeyboardInterrupt (assume the alarm() went off)" + if verbose: + print "KeyboardInterrupt (assume the alarm() went off)" diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 59f8285..3574719 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -20,7 +20,7 @@ def test(name, input, output, *args): f = getattr(string, name) value = apply(f, (input,) + args) except: - value = sys.exc_type + value = sys.exc_type if value != output: if verbose: print 'no' @@ -35,4 +35,3 @@ string_tests.run_method_tests(test) string.whitespace string.lowercase string.uppercase - diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py index bd31058..5770046 100644 --- a/Lib/test/test_strop.py +++ b/Lib/test/test_strop.py @@ -8,7 +8,7 @@ def test(name, input, output, *args): try: value = apply(f, (input,) + args) except: - value = sys.exc_type + value = sys.exc_type if value != output: if verbose: print 'no' diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 2c599d7..5892966 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -94,7 +94,7 @@ tests = [ ] def badpack(fmt, arg, got, exp): - return + return def badunpack(fmt, arg, got, exp): return "unpack(%s, %s) -> (%s,) # expected (%s,)" % ( diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 99bacda..4f78b4c 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -2,72 +2,72 @@ class Error(Exception): - """Base class for regression test exceptions.""" + """Base class for regression test exceptions.""" class TestFailed(Error): - """Test failed.""" + """Test failed.""" class TestSkipped(Error): - """Test skipped. + """Test skipped. - This can be raised to indicate that a test was deliberatly - skipped, but not because a feature wasn't available. For - example, if some resource can't be used, such as the network - appears to be unavailable, this should be raised instead of - TestFailed. + This can be raised to indicate that a test was deliberatly + skipped, but not because a feature wasn't available. For + example, if some resource can't be used, such as the network + appears to be unavailable, this should be raised instead of + TestFailed. - """ + """ -verbose = 1 # Flag set to 0 by regrtest.py +verbose = 1 # Flag set to 0 by regrtest.py use_large_resources = 1 # Flag set to 0 by regrtest.py def unload(name): - import sys - try: - del sys.modules[name] - except KeyError: - pass + import sys + try: + del sys.modules[name] + except KeyError: + pass def forget(modname): - unload(modname) - import sys, os - for dirname in sys.path: - try: - os.unlink(os.path.join(dirname, modname + '.pyc')) - except os.error: - pass + unload(modname) + import sys, os + for dirname in sys.path: + try: + os.unlink(os.path.join(dirname, modname + '.pyc')) + except os.error: + pass FUZZ = 1e-6 def fcmp(x, y): # fuzzy comparison function - if type(x) == type(0.0) or type(y) == type(0.0): - try: - x, y = coerce(x, y) - fuzz = (abs(x) + abs(y)) * FUZZ - if abs(x-y) <= fuzz: - return 0 - except: - pass - elif type(x) == type(y) and type(x) in (type(()), type([])): - for i in range(min(len(x), len(y))): - outcome = fcmp(x[i], y[i]) - if outcome <> 0: - return outcome - return cmp(len(x), len(y)) - return cmp(x, y) + if type(x) == type(0.0) or type(y) == type(0.0): + try: + x, y = coerce(x, y) + fuzz = (abs(x) + abs(y)) * FUZZ + if abs(x-y) <= fuzz: + return 0 + except: + pass + elif type(x) == type(y) and type(x) in (type(()), type([])): + for i in range(min(len(x), len(y))): + outcome = fcmp(x[i], y[i]) + if outcome <> 0: + return outcome + return cmp(len(x), len(y)) + return cmp(x, y) TESTFN = '@test' # Filename used for testing from os import unlink def findfile(file, here=__file__): - import os - if os.path.isabs(file): - return file - import sys - path = sys.path - path = [os.path.dirname(here)] + path - for dn in path: - fn = os.path.join(dn, file) - if os.path.exists(fn): return fn - return file + import os + if os.path.isabs(file): + return file + import sys + path = sys.path + path = [os.path.dirname(here)] + path + for dn in path: + fn = os.path.join(dn, file) + if os.path.exists(fn): return fn + return file diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index 710fb89..02da94e 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -16,98 +16,98 @@ done.acquire() numtasks = 10 def task(ident): - global running - rmutex.acquire() - delay = random.random() * numtasks - rmutex.release() - if verbose: - print 'task', ident, 'will run for', round(delay, 1), 'sec' - time.sleep(delay) - if verbose: - print 'task', ident, 'done' - mutex.acquire() - running = running - 1 - if running == 0: - done.release() - mutex.release() + global running + rmutex.acquire() + delay = random.random() * numtasks + rmutex.release() + if verbose: + print 'task', ident, 'will run for', round(delay, 1), 'sec' + time.sleep(delay) + if verbose: + print 'task', ident, 'done' + mutex.acquire() + running = running - 1 + if running == 0: + done.release() + mutex.release() next_ident = 0 def newtask(): - global next_ident, running - mutex.acquire() - next_ident = next_ident + 1 - if verbose: - print 'creating task', next_ident - thread.start_new_thread(task, (next_ident,)) - running = running + 1 - mutex.release() + global next_ident, running + mutex.acquire() + next_ident = next_ident + 1 + if verbose: + print 'creating task', next_ident + thread.start_new_thread(task, (next_ident,)) + running = running + 1 + mutex.release() for i in range(numtasks): - newtask() + newtask() print 'waiting for all tasks to complete' done.acquire() print 'all tasks done' class barrier: - def __init__(self, n): - self.n = n - self.waiting = 0 - self.checkin = thread.allocate_lock() - self.checkout = thread.allocate_lock() - self.checkout.acquire() + def __init__(self, n): + self.n = n + self.waiting = 0 + self.checkin = thread.allocate_lock() + self.checkout = thread.allocate_lock() + self.checkout.acquire() - def enter(self): - checkin, checkout = self.checkin, self.checkout + def enter(self): + checkin, checkout = self.checkin, self.checkout - checkin.acquire() - self.waiting = self.waiting + 1 - if self.waiting == self.n: - self.waiting = self.n - 1 - checkout.release() - return - checkin.release() + checkin.acquire() + self.waiting = self.waiting + 1 + if self.waiting == self.n: + self.waiting = self.n - 1 + checkout.release() + return + checkin.release() - checkout.acquire() - self.waiting = self.waiting - 1 - if self.waiting == 0: - checkin.release() - return - checkout.release() + checkout.acquire() + self.waiting = self.waiting - 1 + if self.waiting == 0: + checkin.release() + return + checkout.release() numtrips = 3 def task2(ident): - global running - for i in range(numtrips): - if ident == 0: - # give it a good chance to enter the next - # barrier before the others are all out - # of the current one - delay = 0.001 - else: - rmutex.acquire() - delay = random.random() * numtasks - rmutex.release() - if verbose: - print 'task', ident, 'will run for', round(delay, 1), 'sec' - time.sleep(delay) - if verbose: - print 'task', ident, 'entering barrier', i - bar.enter() - if verbose: - print 'task', ident, 'leaving barrier', i - mutex.acquire() - running = running - 1 - if running == 0: - done.release() - mutex.release() + global running + for i in range(numtrips): + if ident == 0: + # give it a good chance to enter the next + # barrier before the others are all out + # of the current one + delay = 0.001 + else: + rmutex.acquire() + delay = random.random() * numtasks + rmutex.release() + if verbose: + print 'task', ident, 'will run for', round(delay, 1), 'sec' + time.sleep(delay) + if verbose: + print 'task', ident, 'entering barrier', i + bar.enter() + if verbose: + print 'task', ident, 'leaving barrier', i + mutex.acquire() + running = running - 1 + if running == 0: + done.release() + mutex.release() print '\n*** Barrier Test ***' if done.acquire(0): - raise ValueError, "'done' should have remained acquired" + raise ValueError, "'done' should have remained acquired" bar = barrier(numtasks) running = numtasks for i in range(numtasks): - thread.start_new_thread(task2, (i,)) + thread.start_new_thread(task2, (i,)) done.acquire() print 'all tasks done' diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index cd97e9a..a0713d1 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -7,4 +7,3 @@ file = open(findfile('tokenize_tests.py')) tokenize.tokenize(file.readline) if verbose: print 'finished' - diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index e3a51f0..eec9e2d 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -53,7 +53,7 @@ print '6.4 Numeric types (mostly conversions)' if 0 <> 0L or 0 <> 0.0 or 0L <> 0.0: raise TestFailed, 'mixed comparisons' if 1 <> 1L or 1 <> 1.0 or 1L <> 1.0: raise TestFailed, 'mixed comparisons' if -1 <> -1L or -1 <> -1.0 or -1L <> -1.0: - raise TestFailed, 'int/long/float value not equal' + raise TestFailed, 'int/long/float value not equal' if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass else: raise TestFailed, 'int() does not round properly' if long(1.9) == 1L == long(1.1) and long(-1.1) == -1L == long(-1.9): pass @@ -70,7 +70,7 @@ if not -24 < -12: raise TestFailed, 'int op' # Test for a particular bug in integer multiply xsize, ysize, zsize = 238, 356, 4 if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912): - raise TestFailed, 'int mul commutativity' + raise TestFailed, 'int mul commutativity' print '6.4.2 Long integers' if 12L + 24L <> 36L: raise TestFailed, 'long op' if 12L + (-24L) <> -12L: raise TestFailed, 'long op' @@ -139,15 +139,15 @@ else: raise TestFailed, 'in/not in list' a = [1, 2, 3, 4, 5] a[:-1] = a if a != [1, 2, 3, 4, 5, 5]: - raise TestFailed, "list self-slice-assign (head)" + raise TestFailed, "list self-slice-assign (head)" a = [1, 2, 3, 4, 5] a[1:] = a if a != [1, 1, 2, 3, 4, 5]: - raise TestFailed, "list self-slice-assign (tail)" + raise TestFailed, "list self-slice-assign (tail)" a = [1, 2, 3, 4, 5] a[1:-1] = a if a != [1, 1, 2, 3, 4, 5, 5]: - raise TestFailed, "list self-slice-assign (center)" + raise TestFailed, "list self-slice-assign (center)" print '6.5.3a Additional list operations' @@ -212,10 +212,10 @@ z.sort(myComparison) # Test extreme cases with long ints a = [0,1,2,3,4] -if a[ -pow(2,128L): 3 ] != [0,1,2]: - raise TestFailed, "list slicing with too-small long integer" -if a[ 3: pow(2,145L) ] != [3,4]: - raise TestFailed, "list slicing with too-large long integer" +if a[ -pow(2,128L): 3 ] != [0,1,2]: + raise TestFailed, "list slicing with too-small long integer" +if a[ 3: pow(2,145L) ] != [3,4]: + raise TestFailed, "list slicing with too-large long integer" print '6.6 Mappings == Dictionaries' d = {} @@ -256,12 +256,12 @@ if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg' # dict.setdefault() d = {} if d.setdefault('key0') <> None: - raise TestFailed, 'missing {} setdefault, no 2nd arg' + raise TestFailed, 'missing {} setdefault, no 2nd arg' if d.setdefault('key0') <> None: - raise TestFailed, 'present {} setdefault, no 2nd arg' + raise TestFailed, 'present {} setdefault, no 2nd arg' d.setdefault('key', []).append(3) if d['key'][0] <> 3: - raise TestFailed, 'missing {} setdefault, w/ 2nd arg' + raise TestFailed, 'missing {} setdefault, w/ 2nd arg' d.setdefault('key', []).append(4) if len(d['key']) <> 2: - raise TestFailed, 'present {} setdefault, w/ 2nd arg' + raise TestFailed, 'present {} setdefault, w/ 2nd arg' diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py index d631406..f1a6229 100644 --- a/Lib/test/test_ucn.py +++ b/Lib/test/test_ucn.py @@ -52,31 +52,30 @@ k_cchMaxUnicodeName = 83 s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}" try: - unicode(s, 'unicode-escape', 'strict') + unicode(s, 'unicode-escape', 'strict') except UnicodeError: - pass + pass else: - raise AssertionError, "failed to raise an exception when presented " \ - "with a UCN > k_cchMaxUnicodeName" + raise AssertionError, "failed to raise an exception when presented " \ + "with a UCN > k_cchMaxUnicodeName" try: - unicode("\N{blah}", 'unicode-escape', 'strict') + unicode("\N{blah}", 'unicode-escape', 'strict') except UnicodeError: - pass + pass else: - raise AssertionError, "failed to raise an exception when given a bogus character name" + raise AssertionError, "failed to raise an exception when given a bogus character name" try: - unicode("\N{SPACE", 'unicode-escape', 'strict') + unicode("\N{SPACE", 'unicode-escape', 'strict') except UnicodeError: - pass + pass else: - raise AssertionError, "failed to raise an exception for a missing closing brace." + raise AssertionError, "failed to raise an exception for a missing closing brace." try: - unicode("\NSPACE", 'unicode-escape', 'strict') + unicode("\NSPACE", 'unicode-escape', 'strict') except UnicodeError: - pass + pass else: - raise AssertionError, "failed to raise an exception for a missing opening brace." + raise AssertionError, "failed to raise an exception for a missing opening brace." print "done." - diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 0c44fbf..74e0cf3 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -179,41 +179,41 @@ if 0: # Non surrogate above surrogate value, fixup required def test_lecmp(s, s2): - assert s < s2 , "comparison failed on %s < %s" % (s, s2) + assert s < s2 , "comparison failed on %s < %s" % (s, s2) def test_fixup(s): - s2 = u'\ud800\udc01' - test_lecmp(s, s2) - s2 = u'\ud900\udc01' - test_lecmp(s, s2) - s2 = u'\uda00\udc01' - test_lecmp(s, s2) - s2 = u'\udb00\udc01' - test_lecmp(s, s2) - s2 = u'\ud800\udd01' - test_lecmp(s, s2) - s2 = u'\ud900\udd01' - test_lecmp(s, s2) - s2 = u'\uda00\udd01' - test_lecmp(s, s2) - s2 = u'\udb00\udd01' - test_lecmp(s, s2) - s2 = u'\ud800\ude01' - test_lecmp(s, s2) - s2 = u'\ud900\ude01' - test_lecmp(s, s2) - s2 = u'\uda00\ude01' - test_lecmp(s, s2) - s2 = u'\udb00\ude01' - test_lecmp(s, s2) - s2 = u'\ud800\udfff' - test_lecmp(s, s2) - s2 = u'\ud900\udfff' - test_lecmp(s, s2) - s2 = u'\uda00\udfff' - test_lecmp(s, s2) - s2 = u'\udb00\udfff' - test_lecmp(s, s2) + s2 = u'\ud800\udc01' + test_lecmp(s, s2) + s2 = u'\ud900\udc01' + test_lecmp(s, s2) + s2 = u'\uda00\udc01' + test_lecmp(s, s2) + s2 = u'\udb00\udc01' + test_lecmp(s, s2) + s2 = u'\ud800\udd01' + test_lecmp(s, s2) + s2 = u'\ud900\udd01' + test_lecmp(s, s2) + s2 = u'\uda00\udd01' + test_lecmp(s, s2) + s2 = u'\udb00\udd01' + test_lecmp(s, s2) + s2 = u'\ud800\ude01' + test_lecmp(s, s2) + s2 = u'\ud900\ude01' + test_lecmp(s, s2) + s2 = u'\uda00\ude01' + test_lecmp(s, s2) + s2 = u'\udb00\ude01' + test_lecmp(s, s2) + s2 = u'\ud800\udfff' + test_lecmp(s, s2) + s2 = u'\ud900\udfff' + test_lecmp(s, s2) + s2 = u'\uda00\udfff' + test_lecmp(s, s2) + s2 = u'\udb00\udfff' + test_lecmp(s, s2) test_fixup(u'\ue000') test_fixup(u'\uff61') @@ -321,13 +321,13 @@ assert u"%c" % (u"a",) == u'a' assert u"%c" % ("a",) == u'a' assert u"%c" % (34,) == u'"' assert u"%c" % (36,) == u'$' -value = u"%r, %r" % (u"abc", "abc") +value = u"%r, %r" % (u"abc", "abc") if value != u"u'abc', 'abc'": print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")' assert u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def' try: - value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"} + value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"} except KeyError: print '*** formatting failed for "%s"' % "u'abc, def'" else: @@ -453,7 +453,7 @@ for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', - 'cp863', 'cp865', 'cp866', + 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1', @@ -465,10 +465,10 @@ for encoding in ( 'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', 'cp1006', 'cp875', 'iso8859_8', - + ### These have undefined mappings: #'cp424', - + ): try: assert unicode(s,encoding).encode(encoding) == s @@ -483,21 +483,21 @@ for encoding in ( 'cp037', 'cp1026', 'cp437', 'cp500', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp860', 'cp861', 'cp862', - 'cp863', 'cp865', 'cp866', + 'cp863', 'cp865', 'cp866', 'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1', 'mac_cyrillic', 'mac_latin2', - + ### These have undefined mappings: #'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', #'cp1256', 'cp1257', 'cp1258', #'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874', #'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish', - + ### These fail the round-trip: #'cp1006', 'cp875', 'iso8859_8', - + ): try: assert unicode(s,encoding).encode(encoding) == s @@ -515,4 +515,3 @@ assert (u"abc" "def") == u"abcdef" assert (u"abc" u"def" "ghi") == u"abcdefghi" assert ("abc" "def" u"ghi") == u"abcdefghi" print 'done.' - diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py index 0dc5756..7e3cf22 100644 --- a/Lib/test/test_unicodedata.py +++ b/Lib/test/test_unicodedata.py @@ -15,7 +15,7 @@ def test_methods(): for i in range(65536): char = unichr(i) data = [ - + # Predicates (single char) char.isalnum() and u'1' or u'0', char.isalpha() and u'1' or u'0', @@ -26,7 +26,7 @@ def test_methods(): char.isspace() and u'1' or u'0', char.istitle() and u'1' or u'0', char.isupper() and u'1' or u'0', - + # Predicates (multiple chars) (char + u'abc').isalnum() and u'1' or u'0', (char + u'abc').isalpha() and u'1' or u'0', @@ -42,13 +42,13 @@ def test_methods(): char.lower(), char.upper(), char.title(), - + # Mappings (multiple chars) (char + u'abc').lower(), (char + u'ABC').upper(), (char + u'abc').title(), (char + u'ABC').title(), - + ] h.update(u''.join(data).encode(encoding)) return h.hexdigest() @@ -68,7 +68,7 @@ def test_unicodedata(): unicodedata.decomposition(char), str(unicodedata.mirrored(char)), str(unicodedata.combining(char)), - ] + ] h.update(''.join(data)) return h.hexdigest() diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 484acea..81533e1 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -28,5 +28,3 @@ out2_2 = "abc?def" assert urllib.quote(in2) == out2_1, "urllib.quote problem" assert urllib.quote(in2, '?') == out2_2, "urllib.quote problem" - - diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index 18ce7a7..f3d5cdf 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -144,4 +144,3 @@ if remote_name is not None: else: print "Remote registry calls can be tested using", print "'test_winreg.py --remote \\\\machine_name'" - diff --git a/Lib/test/test_winsound.py b/Lib/test/test_winsound.py index 7b4fa15..3635281 100644 --- a/Lib/test/test_winsound.py +++ b/Lib/test/test_winsound.py @@ -4,4 +4,3 @@ import winsound for i in range(100, 2000, 100): winsound.Beep(i, 75) print "Hopefully you heard some sounds increasing in frequency!" - diff --git a/Lib/test/test_xmllib.py b/Lib/test/test_xmllib.py index eb868a3..62803b5 100644 --- a/Lib/test/test_xmllib.py +++ b/Lib/test/test_xmllib.py @@ -16,10 +16,10 @@ testdoc = """\ import xmllib if verbose: - parser = xmllib.TestXMLParser() + parser = xmllib.TestXMLParser() else: - parser = xmllib.XMLParser() + parser = xmllib.XMLParser() for c in testdoc: - parser.feed(c) + parser.feed(c) parser.close() diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 3ffdd19..a7b46cb 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -4,23 +4,22 @@ srcname = "junk9630.tmp" zipname = "junk9708.tmp" try: - fp = open(srcname, "w") # Make a source file with some lines - for i in range(0, 1000): - fp.write("Test of zipfile line %d.\n" % i) - fp.close() + fp = open(srcname, "w") # Make a source file with some lines + for i in range(0, 1000): + fp.write("Test of zipfile line %d.\n" % i) + fp.close() - zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive - zip.write(srcname, srcname) - zip.write(srcname, "another.name") - zip.close() + zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive + zip.write(srcname, srcname) + zip.write(srcname, "another.name") + zip.close() - zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive - zip.read("another.name") - zip.read(srcname) - zip.close() + zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive + zip.read("another.name") + zip.read(srcname) + zip.close() finally: - if os.path.isfile(srcname): # Remove temporary files - os.unlink(srcname) - if os.path.isfile(zipname): - os.unlink(zipname) - + if os.path.isfile(srcname): # Remove temporary files + os.unlink(srcname) + if os.path.isfile(zipname): + os.unlink(zipname) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index d22a2cc..7f01114 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -96,7 +96,7 @@ def ignore(): """ """ -LAERTES +LAERTES O, fear me not. I stay too long: but here my father comes. @@ -106,7 +106,7 @@ LAERTES A double blessing is a double grace, Occasion smiles upon a second leave. -LORD POLONIUS +LORD POLONIUS Yet here, Laertes! aboard, aboard, for shame! The wind sits in the shoulder of your sail, @@ -136,26 +136,25 @@ LORD POLONIUS Thou canst not then be false to any man. Farewell: my blessing season this in thee! -LAERTES +LAERTES Most humbly do I take my leave, my lord. -LORD POLONIUS +LORD POLONIUS The time invites you; go; your servants tend. -LAERTES +LAERTES Farewell, Ophelia; and remember well What I have said to you. -OPHELIA +OPHELIA 'Tis in my memory lock'd, And you yourself shall keep the key of it. -LAERTES +LAERTES Farewell. """ - -- cgit v0.12