diff options
Diffstat (limited to 'Lib/test')
36 files changed, 930 insertions, 930 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index abd40a6..41e750f 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -30,58 +30,58 @@ import test_support def main(): try: - opts, args = getopt.getopt(sys.argv[1:], 'vgqx') + opts, args = getopt.getopt(sys.argv[1:], 'vgqx') except getopt.error, msg: - print msg - print __doc__ - return 2 + print msg + print __doc__ + return 2 verbose = 0 quiet = 0 generate = 0 exclude = 0 for o, a in opts: - if o == '-v': verbose = verbose+1 - if o == '-q': quiet = 1; verbose = 0 - if o == '-g': generate = 1 - if o == '-x': exclude = 1 + if o == '-v': verbose = verbose+1 + if o == '-q': quiet = 1; verbose = 0 + if o == '-g': generate = 1 + if o == '-x': exclude = 1 if generate and verbose: - print "-g and -v don't go together!" - return 2 + print "-g and -v don't go together!" + return 2 good = [] bad = [] skipped = [] for i in range(len(args)): - # Strip trailing ".py" from arguments - if args[i][-3:] == '.py': - args[i] = args[i][:-3] + # Strip trailing ".py" from arguments + if args[i][-3:] == '.py': + args[i] = args[i][:-3] if exclude: - nottests[:0] = args - args = [] + nottests[:0] = args + args = [] tests = args or findtests() - test_support.verbose = verbose # Tell tests to be moderately quiet + test_support.verbose = verbose # Tell tests to be moderately quiet for test in tests: - if not quiet: - print test - ok = runtest(test, generate, verbose) - if ok > 0: - good.append(test) - elif ok == 0: - bad.append(test) - else: - if not quiet: - print "test", test, - print "skipped -- an optional feature could not be imported" - skipped.append(test) + if not quiet: + print test + ok = runtest(test, generate, verbose) + if ok > 0: + good.append(test) + elif ok == 0: + bad.append(test) + else: + if not quiet: + print "test", test, + print "skipped -- an optional feature could not be imported" + skipped.append(test) if good and not quiet: - if not bad and not skipped and len(good) > 1: - print "All", - print count(len(good), "test"), "OK." + if not bad and not skipped and len(good) > 1: + print "All", + print count(len(good), "test"), "OK." if bad: - print count(len(bad), "test"), "failed:", - print string.join(bad) + print count(len(bad), "test"), "failed:", + print string.join(bad) if skipped and not quiet: - print count(len(skipped), "test"), "skipped:", - print string.join(skipped) + print count(len(skipped), "test"), "skipped:", + print string.join(skipped) return len(bad) > 0 stdtests = [ @@ -105,10 +105,10 @@ def findtests(): names = os.listdir(testdir) tests = [] for name in names: - if name[:5] == "test_" and name[-3:] == ".py": - modname = name[:-3] - if modname not in stdtests and modname not in nottests: - tests.append(modname) + if name[:5] == "test_" and name[-3:] == ".py": + modname = name[:-3] + if modname not in stdtests and modname not in nottests: + tests.append(modname) tests.sort() return stdtests + tests @@ -118,76 +118,76 @@ def runtest(test, generate, verbose): outputdir = os.path.join(testdir, "output") outputfile = os.path.join(outputdir, test) try: - if generate: - cfp = open(outputfile, "w") - elif verbose: - cfp = sys.stdout - else: - cfp = Compare(outputfile) + if generate: + cfp = open(outputfile, "w") + elif verbose: + cfp = sys.stdout + else: + cfp = Compare(outputfile) except IOError: - cfp = None - print "Warning: can't open", outputfile + cfp = None + print "Warning: can't open", outputfile try: - save_stdout = sys.stdout - try: - if cfp: - sys.stdout = cfp - print test # Output file starts with test name - __import__(test, globals(), locals(), []) - finally: - sys.stdout = save_stdout + save_stdout = sys.stdout + try: + if cfp: + sys.stdout = cfp + print test # Output file starts with test name + __import__(test, globals(), locals(), []) + finally: + sys.stdout = save_stdout except ImportError, msg: - return -1 + return -1 except KeyboardInterrupt, v: - raise KeyboardInterrupt, v, sys.exc_info()[2] + raise KeyboardInterrupt, v, sys.exc_info()[2] except test_support.TestFailed, msg: - print "test", test, "failed --", msg - return 0 + print "test", test, "failed --", msg + return 0 except: - type, value = sys.exc_info()[:2] - print "test", test, "crashed --", type, ":", value - if verbose: - traceback.print_exc(file=sys.stdout) - return 0 + type, value = sys.exc_info()[:2] + print "test", test, "crashed --", type, ":", value + if verbose: + traceback.print_exc(file=sys.stdout) + return 0 else: - return 1 + return 1 def findtestdir(): if __name__ == '__main__': - file = sys.argv[0] + file = sys.argv[0] else: - file = __file__ + file = __file__ testdir = os.path.dirname(file) or os.curdir return testdir def count(n, word): if n == 1: - return "%d %s" % (n, word) + return "%d %s" % (n, word) else: - return "%d %ss" % (n, word) + return "%d %ss" % (n, word) class Compare: def __init__(self, filename): - self.fp = open(filename, 'r') + self.fp = open(filename, 'r') def write(self, data): - expected = self.fp.read(len(data)) - if data <> expected: - raise test_support.TestFailed, \ - 'Writing: '+`data`+', expected: '+`expected` + expected = self.fp.read(len(data)) + if data <> expected: + raise test_support.TestFailed, \ + 'Writing: '+`data`+', expected: '+`expected` def flush(self): - pass + pass def close(self): - leftover = self.fp.read() - if leftover: - raise test_support.TestFailed, 'Unread: '+`leftover` - self.fp.close() + leftover = self.fp.read() + if leftover: + raise test_support.TestFailed, 'Unread: '+`leftover` + self.fp.close() def isatty(self): - return 0 + return 0 if __name__ == '__main__': sys.exit(main()) diff --git a/Lib/test/test_al.py b/Lib/test/test_al.py index b8ea868..587bf1f 100755 --- a/Lib/test/test_al.py +++ b/Lib/test/test_al.py @@ -6,7 +6,7 @@ import al from test_support import verbose alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getparams', - 'newconfig', 'openport', 'queryparams', 'setparams'] + 'newconfig', 'openport', 'queryparams', 'setparams'] # This is a very inobstrusive test for the existance of the al module and all it's # attributes. More comprehensive examples can be found in Demo/al @@ -14,11 +14,11 @@ alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getpara def main(): # touch all the attributes of al without doing anything if verbose: - print 'Touching al module attributes...' + print 'Touching al module attributes...' for attr in alattrs: - if verbose: - print 'touching: ', attr - getattr(al, attr) + if verbose: + print 'touching: ', attr + getattr(al, attr) main() diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index e95fac4..6a0d17c 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -10,50 +10,50 @@ def main(): testtype('c', 'c') for type in (['b', 'h', 'i', 'l', 'f', 'd']): - testtype(type, 1) + testtype(type, 1) unlink(TESTFN) 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) - 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()` + 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) + 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()` main() - + diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py index a03fe60..900ec58 100644 --- a/Lib/test/test_audioop.py +++ b/Lib/test/test_audioop.py @@ -7,166 +7,166 @@ def gendata1(): def gendata2(): if verbose: - print 'getsample' + print 'getsample' if audioop.getsample('\0\1', 2, 0) == 1: - return '\0\0\0\1\0\2' + return '\0\0\0\1\0\2' else: - return '\0\0\1\0\2\0' + return '\0\0\1\0\2\0' def gendata4(): if verbose: - print 'getsample' + print 'getsample' if audioop.getsample('\0\0\0\1', 4, 0) == 1: - return '\0\0\0\0\0\0\0\1\0\0\0\2' + return '\0\0\0\0\0\0\0\1\0\0\0\2' else: - return '\0\0\0\0\1\0\0\0\2\0\0\0' + return '\0\0\0\0\1\0\0\0\2\0\0\0' def testmax(data): if verbose: - print 'max' + print 'max' if audioop.max(data[0], 1) <> 2 or \ - audioop.max(data[1], 2) <> 2 or \ - audioop.max(data[2], 4) <> 2: - return 0 + audioop.max(data[1], 2) <> 2 or \ + audioop.max(data[2], 4) <> 2: + return 0 return 1 def testminmax(data): if verbose: - print 'minmax' + print 'minmax' if audioop.minmax(data[0], 1) <> (0, 2) or \ - audioop.minmax(data[1], 2) <> (0, 2) or \ - audioop.minmax(data[2], 4) <> (0, 2): - return 0 + audioop.minmax(data[1], 2) <> (0, 2) or \ + audioop.minmax(data[2], 4) <> (0, 2): + return 0 return 1 def testmaxpp(data): if verbose: - print 'maxpp' + print 'maxpp' if audioop.maxpp(data[0], 1) <> 0 or \ - audioop.maxpp(data[1], 2) <> 0 or \ - audioop.maxpp(data[2], 4) <> 0: - return 0 + audioop.maxpp(data[1], 2) <> 0 or \ + audioop.maxpp(data[2], 4) <> 0: + return 0 return 1 def testavg(data): if verbose: - print 'avg' + print 'avg' if audioop.avg(data[0], 1) <> 1 or \ - audioop.avg(data[1], 2) <> 1 or \ - audioop.avg(data[2], 4) <> 1: - return 0 + audioop.avg(data[1], 2) <> 1 or \ + audioop.avg(data[2], 4) <> 1: + return 0 return 1 def testavgpp(data): if verbose: - print 'avgpp' + print 'avgpp' if audioop.avgpp(data[0], 1) <> 0 or \ - audioop.avgpp(data[1], 2) <> 0 or \ - audioop.avgpp(data[2], 4) <> 0: - return 0 + audioop.avgpp(data[1], 2) <> 0 or \ + audioop.avgpp(data[2], 4) <> 0: + return 0 return 1 def testrms(data): if audioop.rms(data[0], 1) <> 1 or \ - audioop.rms(data[1], 2) <> 1 or \ - audioop.rms(data[2], 4) <> 1: - return 0 + audioop.rms(data[1], 2) <> 1 or \ + audioop.rms(data[2], 4) <> 1: + return 0 return 1 def testcross(data): if verbose: - print 'cross' + print 'cross' if audioop.cross(data[0], 1) <> 0 or \ - audioop.cross(data[1], 2) <> 0 or \ - audioop.cross(data[2], 4) <> 0: - return 0 + audioop.cross(data[1], 2) <> 0 or \ + audioop.cross(data[2], 4) <> 0: + return 0 return 1 def testadd(data): if verbose: - print 'add' + print 'add' data2 = [] for d in data: - str = '' - for s in d: - str = str + chr(ord(s)*2) - data2.append(str) + str = '' + for s in d: + str = str + chr(ord(s)*2) + data2.append(str) if audioop.add(data[0], data[0], 1) <> data2[0] or \ - audioop.add(data[1], data[1], 2) <> data2[1] or \ - audioop.add(data[2], data[2], 4) <> data2[2]: - return 0 + audioop.add(data[1], data[1], 2) <> data2[1] or \ + audioop.add(data[2], data[2], 4) <> data2[2]: + return 0 return 1 def testbias(data): if verbose: - print 'bias' + print 'bias' # Note: this test assumes that avg() works d1 = audioop.bias(data[0], 1, 100) d2 = audioop.bias(data[1], 2, 100) d4 = audioop.bias(data[2], 4, 100) if audioop.avg(d1, 1) <> 101 or \ - audioop.avg(d2, 2) <> 101 or \ - audioop.avg(d4, 4) <> 101: - return 0 + audioop.avg(d2, 2) <> 101 or \ + audioop.avg(d4, 4) <> 101: + return 0 return 1 def testlin2lin(data): if verbose: - print 'lin2lin' + print 'lin2lin' # too simple: we test only the size for d1 in data: - for d2 in data: - got = len(d1)/3 - wtd = len(d2)/3 - if len(audioop.lin2lin(d1, got, wtd)) <> len(d2): - return 0 + for d2 in data: + got = len(d1)/3 + wtd = len(d2)/3 + if len(audioop.lin2lin(d1, got, wtd)) <> len(d2): + return 0 return 1 def testadpcm2lin(data): # Very cursory test if audioop.adpcm2lin('\0\0', 1, None) <> ('\0\0\0\0', (0,0)): - return 0 + return 0 return 1 def testlin2adpcm(data): if verbose: - print 'lin2adpcm' + print 'lin2adpcm' # Very cursory test if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)): - return 0 + return 0 return 1 def testlin2ulaw(data): if verbose: - print 'lin2ulaw' + print 'lin2ulaw' if audioop.lin2ulaw(data[0], 1) <> '\377\347\333' or \ - audioop.lin2ulaw(data[1], 2) <> '\377\377\377' or \ - audioop.lin2ulaw(data[2], 4) <> '\377\377\377': - return 0 + audioop.lin2ulaw(data[1], 2) <> '\377\377\377' or \ + audioop.lin2ulaw(data[2], 4) <> '\377\377\377': + return 0 return 1 def testulaw2lin(data): if verbose: - print 'ulaw2lin' + print 'ulaw2lin' # Cursory d = audioop.lin2ulaw(data[0], 1) if audioop.ulaw2lin(d, 1) <> data[0]: - return 0 + return 0 return 1 def testmul(data): if verbose: - print 'mul' + print 'mul' data2 = [] for d in data: - str = '' - for s in d: - str = str + chr(ord(s)*2) - data2.append(str) + str = '' + for s in d: + str = str + chr(ord(s)*2) + data2.append(str) if audioop.mul(data[0], 1, 2) <> data2[0] or \ - audioop.mul(data[1],2, 2) <> data2[1] or \ - audioop.mul(data[2], 4, 2) <> data2[2]: - return 0 + audioop.mul(data[1],2, 2) <> data2[1] or \ + audioop.mul(data[2], 4, 2) <> data2[2]: + return 0 return 1 def testratecv(data): @@ -181,75 +181,75 @@ def testratecv(data): def testreverse(data): if verbose: - print 'reverse' + print 'reverse' if audioop.reverse(data[0], 1) <> '\2\1\0': - return 0 + return 0 return 1 def testtomono(data): if verbose: - print 'tomono' + print 'tomono' data2 = '' for d in data[0]: - data2 = data2 + d + d + data2 = data2 + d + d if audioop.tomono(data2, 1, 0.5, 0.5) <> data[0]: - return 0 + return 0 return 1 def testtostereo(data): if verbose: - print 'tostereo' + print 'tostereo' data2 = '' for d in data[0]: - data2 = data2 + d + d + data2 = data2 + d + d if audioop.tostereo(data[0], 1, 1, 1) <> data2: - return 0 + return 0 return 1 def testfindfactor(data): if verbose: - print 'findfactor' + print 'findfactor' if audioop.findfactor(data[1], data[1]) <> 1.0: - return 0 + return 0 return 1 def testfindfit(data): if verbose: - print 'findfit' + print 'findfit' if audioop.findfit(data[1], data[1]) <> (0, 1.0): - return 0 + return 0 return 1 def testfindmax(data): if verbose: - print 'findmax' + print 'findmax' if audioop.findmax(data[1], 1) <> 2: - return 0 + return 0 return 1 def testgetsample(data): if verbose: - print 'getsample' + print 'getsample' for i in range(3): - if audioop.getsample(data[0], 1, i) <> i or \ - audioop.getsample(data[1], 2, i) <> i or \ - audioop.getsample(data[2], 4, i) <> i: - return 0 + if audioop.getsample(data[0], 1, i) <> i or \ + audioop.getsample(data[1], 2, i) <> i or \ + audioop.getsample(data[2], 4, i) <> i: + return 0 return 1 def testone(name, data): try: - func = eval('test'+name) + func = eval('test'+name) except NameError: - print 'No test found for audioop.'+name+'()' - return + print 'No test found for audioop.'+name+'()' + return try: - rv = func(data) + rv = func(data) except 'xx': - print 'Test FAILED for audioop.'+name+'() (with an exception)' - return + print 'Test FAILED for audioop.'+name+'() (with an exception)' + return if not rv: - print 'Test FAILED for audioop.'+name+'()' + print 'Test FAILED for audioop.'+name+'()' def testall(): data = [gendata1(), gendata2(), gendata4()] @@ -257,8 +257,8 @@ def testall(): # We know there is a routine 'add' routines = [] for n in names: - if type(eval('audioop.'+n)) == type(audioop.add): - routines.append(n) + if type(eval('audioop.'+n)) == type(audioop.add): + routines.append(n) for n in routines: - testone(n, data) + testone(n, data) testall() diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index aa156d9..fe3843d 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -11,11 +11,11 @@ from test_support import verbose def test(): try: - fname1 = tempfile.mktemp() - fname2 = tempfile.mktemp() - f = open(fname1, 'w') + fname1 = tempfile.mktemp() + fname2 = tempfile.mktemp() + f = open(fname1, 'w') except: - raise ImportError, "Cannot test binascii without a temp file" + raise ImportError, "Cannot test binascii without a temp file" start = 'Jack is my hero' f.write(start) @@ -23,24 +23,24 @@ def test(): binhex.binhex(fname1, fname2) if verbose: - print 'binhex' + print 'binhex' binhex.hexbin(fname2, fname1) if verbose: - print 'hexbin' + print 'hexbin' f = open(fname1, 'r') finish = f.readline() if start <> finish: - print 'Error: binhex <> hexbin' + print 'Error: binhex <> hexbin' elif verbose: - print 'binhex == hexbin' + print 'binhex == hexbin' try: - import os - os.unlink(fname1) - os.unlink(fname2) + import os + os.unlink(fname1) + os.unlink(fname2) except: - pass + pass test() diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py index aa156d9..fe3843d 100755 --- a/Lib/test/test_binhex.py +++ b/Lib/test/test_binhex.py @@ -11,11 +11,11 @@ from test_support import verbose def test(): try: - fname1 = tempfile.mktemp() - fname2 = tempfile.mktemp() - f = open(fname1, 'w') + fname1 = tempfile.mktemp() + fname2 = tempfile.mktemp() + f = open(fname1, 'w') except: - raise ImportError, "Cannot test binascii without a temp file" + raise ImportError, "Cannot test binascii without a temp file" start = 'Jack is my hero' f.write(start) @@ -23,24 +23,24 @@ def test(): binhex.binhex(fname1, fname2) if verbose: - print 'binhex' + print 'binhex' binhex.hexbin(fname2, fname1) if verbose: - print 'hexbin' + print 'hexbin' f = open(fname1, 'r') finish = f.readline() if start <> finish: - print 'Error: binhex <> hexbin' + print 'Error: binhex <> hexbin' elif verbose: - print 'binhex == hexbin' + print 'binhex == hexbin' try: - import os - os.unlink(fname1) - os.unlink(fname2) + import os + os.unlink(fname1) + os.unlink(fname2) except: - pass + pass test() diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py index 7a95eb9..1188e06 100755 --- a/Lib/test/test_bsddb.py +++ b/Lib/test/test_bsddb.py @@ -9,12 +9,12 @@ from test_support import verbose def test(openmethod, what): if verbose: - print '\nTesting: ', what - + print '\nTesting: ', what + fname = tempfile.mktemp() f = openmethod(fname, 'c') if verbose: - print 'creation...' + print 'creation...' f['0'] = '' f['a'] = 'Guido' f['b'] = 'van' @@ -22,47 +22,47 @@ def test(openmethod, what): f['d'] = 'invented' f['f'] = 'Python' if verbose: - print '%s %s %s' % (f['a'], f['b'], f['c']) + print '%s %s %s' % (f['a'], f['b'], f['c']) if what == 'BTree' : - if verbose: - print 'key ordering...' - f.set_location(f.first()[0]) - while 1: - try: - rec = f.next() - except KeyError: - if rec <> f.last(): - print 'Error, last <> last!' - f.previous() - break - if verbose: - print rec - if not f.has_key('a'): - print 'Error, missing key!' + if verbose: + print 'key ordering...' + f.set_location(f.first()[0]) + while 1: + try: + rec = f.next() + except KeyError: + if rec <> f.last(): + print 'Error, last <> last!' + f.previous() + break + if verbose: + print rec + if not f.has_key('a'): + print 'Error, missing key!' f.sync() f.close() if verbose: - print 'modification...' + print 'modification...' f = openmethod(fname, 'w') f['d'] = 'discovered' if verbose: - print 'access...' + print 'access...' for key in f.keys(): - word = f[key] - if verbose: - print word + word = f[key] + if verbose: + print word f.close() types = [(bsddb.btopen, 'BTree'), - (bsddb.hashopen, 'Hash Table'), - # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 + (bsddb.hashopen, 'Hash Table'), + # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 # appears broken... at least on - # Solaris Intel - rmasse 1/97 - ] + # Solaris Intel - rmasse 1/97 + ] for type in types: test(type[0], type[1]) diff --git a/Lib/test/test_cd.py b/Lib/test/test_cd.py index aa51d57..4d56158 100755 --- a/Lib/test/test_cd.py +++ b/Lib/test/test_cd.py @@ -6,8 +6,8 @@ import cd from test_support import verbose cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY', - 'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error', - 'ident', 'index', 'msftoframe', 'open', 'pnum', 'ptime'] + 'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error', + 'ident', 'index', 'msftoframe', 'open', 'pnum', 'ptime'] # This is a very inobstrusive test for the existance of the cd module and all it's @@ -17,10 +17,10 @@ cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYI def main(): # touch all the attributes of cd without doing anything if verbose: - print 'Touching cd module attributes...' + print 'Touching cd module attributes...' for attr in cdattrs: - if verbose: - print 'touching: ', attr - getattr(cd, attr) + if verbose: + print 'touching: ', attr + getattr(cd, attr) main() diff --git a/Lib/test/test_cl.py b/Lib/test/test_cl.py index f32efa6..60fbc43 100755 --- a/Lib/test/test_cl.py +++ b/Lib/test/test_cl.py @@ -69,10 +69,10 @@ clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID', def main(): # touch all the attributes of al without doing anything if verbose: - print 'Touching cl module attributes...' + print 'Touching cl module attributes...' for attr in clattrs: - if verbose: - print 'touching: ', attr - getattr(cl, attr) + if verbose: + print 'touching: ', attr + getattr(cl, attr) main() diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 71e7729..509c739 100755 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -6,27 +6,27 @@ import cmath from test_support import verbose testdict = {'acos' : 1.0, - 'acosh' : 1.0, - 'asin' : 1.0, - 'asinh' : 1.0, - 'atan' : 0.2, - 'atanh' : 0.2, - 'cos' : 1.0, - 'cosh' : 1.0, - 'exp' : 1.0, - 'log' : 1.0, - 'log10' : 1.0, - 'sin' : 1.0, - 'sinh' : 1.0, - 'sqrt' : 1.0, - 'tan' : 1.0, - 'tanh' : 1.0} + 'acosh' : 1.0, + 'asin' : 1.0, + 'asinh' : 1.0, + 'atan' : 0.2, + 'atanh' : 0.2, + 'cos' : 1.0, + 'cosh' : 1.0, + 'exp' : 1.0, + 'log' : 1.0, + 'log10' : 1.0, + 'sin' : 1.0, + 'sinh' : 1.0, + 'sqrt' : 1.0, + 'tan' : 1.0, + 'tanh' : 1.0} for func in testdict.keys(): f = getattr(cmath, func) r = f(testdict[func]) if verbose: - print 'Calling %s(%f) = %f' % (func, testdict[func], abs(r)) + print 'Calling %s(%f) = %f' % (func, testdict[func], abs(r)) p = cmath.pi e = cmath.e diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index 45f5f37..b4f7f89 100755 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -14,8 +14,8 @@ d['12345678910'] = '019237410982340912840198242' d.keys() if d.has_key('a'): if verbose: - print 'Test dbm keys: ', d.keys() - + print 'Test dbm keys: ', d.keys() + d.close() d = dbm.open(filename, 'r') d.close() diff --git a/Lib/test/test_dl.py b/Lib/test/test_dl.py index 029196d..e7902cc 100755 --- a/Lib/test/test_dl.py +++ b/Lib/test/test_dl.py @@ -12,20 +12,20 @@ sharedlibs = [ for s, func in sharedlibs: try: - if verbose: - print 'trying to open:', s, - l = dl.open(s) + if verbose: + print 'trying to open:', s, + l = dl.open(s) except dl.error: - if verbose: - print 'failed' - pass + if verbose: + print 'failed' + pass else: - if verbose: - print 'succeeded...', - l.call(func) - l.close() - if verbose: - print 'worked!' - break + if verbose: + print 'succeeded...', + l.call(func) + l.close() + if verbose: + print 'worked!' + break else: print 'Could not open any shared libraries' diff --git a/Lib/test/test_errno.py b/Lib/test/test_errno.py index 7228fdf..cb1e729 100755 --- a/Lib/test/test_errno.py +++ b/Lib/test/test_errno.py @@ -7,31 +7,31 @@ import errno from test_support import verbose errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', - 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF', - 'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT', - 'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM', - 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', - 'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOM', - 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN', - 'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS', - 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', - 'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC', - 'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG', - 'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', - 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', - 'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA', - 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', - 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT', - 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK', - 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK', - 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP', - 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE', - 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', - 'ERANGE', 'EREMCHG', 'EREMOTE', 'ERESTART', - 'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE', - 'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME', - 'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUNATCH', - 'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL'] + 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF', + 'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT', + 'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM', + 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', + 'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOM', + 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN', + 'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS', + 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', + 'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC', + 'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG', + 'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', + 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', + 'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA', + 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', + 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT', + 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK', + 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK', + 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP', + 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE', + 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', + 'ERANGE', 'EREMCHG', 'EREMOTE', 'ERESTART', + 'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE', + 'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME', + 'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUNATCH', + 'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL'] # # This is is a wee bit bogus since the module only conditionally adds @@ -40,10 +40,10 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', # for error in errors: try: - a = getattr(errno, error) + a = getattr(errno, error) except AttributeError: - if verbose: - print '%s: not found' % error + if verbose: + print '%s: not found' % error else: - if verbose: - print '%s: %d' % (error, a) + if verbose: + print '%s: %d' % (error, a) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index dbcdbe8..9796ef4 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -8,9 +8,9 @@ print '5. Built-in exceptions' def r(thing): if type(thing) == ClassType: - print thing.__name__ + print thing.__name__ else: - print thing + print thing r(AttributeError) import sys @@ -24,14 +24,14 @@ fp.close() fp = open(TESTFN, 'r') savestdin = sys.stdin try: - try: - sys.stdin = fp - x = raw_input() - except EOFError: - pass + try: + sys.stdin = fp + x = raw_input() + except EOFError: + pass finally: - sys.stdin = savestdin - fp.close() + sys.stdin = savestdin + fp.close() r(IOError) try: open('this file does not exist', 'r') @@ -64,7 +64,7 @@ except NameError: pass r(OverflowError) x = 1 try: - while 1: x = x+x + while 1: x = x+x except OverflowError: pass r(RuntimeError) diff --git a/Lib/test/test_gl.py b/Lib/test/test_gl.py index d4e4d28..1010b6f 100755 --- a/Lib/test/test_gl.py +++ b/Lib/test/test_gl.py @@ -85,67 +85,67 @@ def main(): # insure that we at least have an X display before continuing. import os try: - display = os.environ['DISPLAY'] + display = os.environ['DISPLAY'] except: - # Raise ImportError because regrtest.py handles it specially. - raise ImportError, "No $DISPLAY -- skipping gl test" + # Raise ImportError because regrtest.py handles it specially. + raise ImportError, "No $DISPLAY -- skipping gl test" # touch all the attributes of gl without doing anything if verbose: - print 'Touching gl module attributes...' + print 'Touching gl module attributes...' for attr in glattrs: - if verbose: - print 'touching: ', attr - getattr(gl, attr) + if verbose: + print 'touching: ', attr + getattr(gl, attr) # create a small 'Crisscross' window if verbose: - print 'Creating a small "CrissCross" window...' - print 'foreground' + print 'Creating a small "CrissCross" window...' + print 'foreground' gl.foreground() if verbose: - print 'prefposition' + print 'prefposition' gl.prefposition(500, 900, 500, 900) if verbose: - print 'winopen "CrissCross"' + print 'winopen "CrissCross"' w = gl.winopen('CrissCross') if verbose: - print 'clear' + print 'clear' gl.clear() if verbose: - print 'ortho2' + print 'ortho2' gl.ortho2(0.0, 400.0, 0.0, 400.0) if verbose: - print 'color WHITE' + print 'color WHITE' gl.color(GL.WHITE) if verbose: - print 'color RED' + print 'color RED' gl.color(GL.RED) if verbose: - print 'bgnline' + print 'bgnline' gl.bgnline() if verbose: - print 'v2f' + print 'v2f' gl.v2f(0.0, 0.0) gl.v2f(400.0, 400.0) if verbose: - print 'endline' + print 'endline' gl.endline() if verbose: - print 'bgnline' + print 'bgnline' gl.bgnline() if verbose: - print 'v2i' + print 'v2i' gl.v2i(400, 0) gl.v2i(0, 400) if verbose: - print 'endline' + print 'endline' gl.endline() if verbose: - print 'Displaying window for 2 seconds...' + print 'Displaying window for 2 seconds...' time.sleep(2) if verbose: - print 'winclose' + print 'winclose' gl.winclose(w) main() diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py index f39049f..bfe3a76 100755 --- a/Lib/test/test_grp.py +++ b/Lib/test/test_grp.py @@ -10,16 +10,16 @@ groups = grp.getgrall() if verbose: print 'Groups:' for group in groups: - print group + print group if not groups: if verbose: - print "Empty Group Database -- no further tests of grp module possible" + print "Empty Group Database -- no further tests of grp module possible" else: group = grp.getgrgid(groups[0][2]) if verbose: - print 'Group Entry for GID %d: %s' % (groups[0][2], group) + print 'Group Entry for GID %d: %s' % (groups[0][2], group) group = grp.getgrnam(groups[0][0]) if verbose: - print 'Group Entry for group %s: %s' % (groups[0][0], group) + print 'Group Entry for group %s: %s' % (groups[0][0], group) diff --git a/Lib/test/test_imageop.py b/Lib/test/test_imageop.py index 89b111c..63ab138 100755 --- a/Lib/test/test_imageop.py +++ b/Lib/test/test_imageop.py @@ -15,14 +15,14 @@ def main(use_rgbimg=1): uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb') if use_rgbimg: - image, width, height = getrgbimage('test.rgb') + image, width, height = getrgbimage('test.rgb') else: - image, width, height = getimage('test.rgb') - + 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: - print 'crop' + print 'crop' newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 1) # Return image scaled to size newwidth by newheight. No interpolation @@ -30,7 +30,7 @@ def main(use_rgbimg=1): # Therefore, computer-generated images or dithered images will # not look nice after scaling. if verbose: - print 'scale' + print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) # Run a vertical low-pass filter over an image. It does so by computing @@ -38,34 +38,34 @@ def main(use_rgbimg=1): # pixels. The main use of this routine is to forestall excessive flicker # if the image two vertically-aligned source pixels, hence the name. if verbose: - print 'tovideo' + print 'tovideo' videoimage = imageop.tovideo (image, 4, width, height) # Convert an rgb image to an 8 bit rgb if verbose: - print 'rgb2rgb8' + print 'rgb2rgb8' greyimage = imageop.rgb2rgb8(image, width, height) # Convert an 8 bit rgb image to a 24 bit rgb image if verbose: - print 'rgb82rgb' + print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) # Convert an rgb image to an 8 bit greyscale image if verbose: - print 'rgb2grey' + print 'rgb2grey' greyimage = imageop.rgb2grey(image, width, height) # Convert an 8 bit greyscale image to a 24 bit rgb image if verbose: - print 'grey2rgb' + print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) # Convert a 8-bit deep greyscale image to a 1-bit deep image by # tresholding all the pixels. The resulting image is tightly packed # and is probably only useful as an argument to mono2grey. if verbose: - print 'grey2mono' + print 'grey2mono' monoimage = imageop.grey2mono (greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') @@ -75,42 +75,42 @@ def main(use_rgbimg=1): # monochrome black-and-white image to greyscale pass the values 0 and # 255 respectively. if verbose: - print 'mono2grey' + print 'mono2grey' greyimage = imageop.mono2grey (monoimage, width, height, 0, 255) # Convert an 8-bit greyscale image to a 1-bit monochrome image using a # (simple-minded) dithering algorithm. if verbose: - print 'dither2mono' + print 'dither2mono' monoimage = imageop.dither2mono (greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without # dithering. if verbose: - print 'grey2grey4' + print 'grey2grey4' grey4image = imageop.grey2grey4 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without # dithering. if verbose: - print 'grey2grey2' + print 'grey2grey2' 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. if verbose: - print 'dither2grey2' + print 'dither2grey2' grey2image = imageop.dither2grey2 (greyimage, width, height) # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: - print 'grey42grey' + print 'grey42grey' greyimage = imageop.grey42grey (grey4image, width, height) # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: - print 'grey22grey' + print 'grey22grey' image = imageop.grey22grey (grey2image, width, height) # Cleanup @@ -123,12 +123,12 @@ def getrgbimage(name): import rgbimg try: - sizes = rgbimg.sizeofimage(name) + sizes = rgbimg.sizeofimage(name) except rgbimg.error: - name = get_qualified_path(name) - sizes = rgbimg.sizeofimage(name) + name = get_qualified_path(name) + sizes = rgbimg.sizeofimage(name) if verbose: - print 'rgbimg opening test image: %s, sizes: %s' % (name, str(sizes)) + print 'rgbimg opening test image: %s, sizes: %s' % (name, str(sizes)) image = rgbimg.longimagedata(name) return (image, sizes[0], sizes[1]) @@ -141,12 +141,12 @@ def getimage(name): import imgfile try: - sizes = imgfile.getsizes(name) + sizes = imgfile.getsizes(name) except imgfile.error: - name = get_qualified_path(name) - sizes = imgfile.getsizes(name) + name = get_qualified_path(name) + sizes = imgfile.getsizes(name) if verbose: - print 'imgfile opening test image: %s, sizes: %s' % (name, str(sizes)) + print 'imgfile opening test image: %s, sizes: %s' % (name, str(sizes)) image = imgfile.read(name) return (image, sizes[0], sizes[1]) @@ -157,13 +157,13 @@ def get_qualified_path(name): import os path = sys.path try: - path = [os.path.dirname(__file__)] + path + path = [os.path.dirname(__file__)] + path except NameError: - pass + pass for dir in path: - fullname = os.path.join(dir, name) - if os.path.exists(fullname): - return fullname + fullname = os.path.join(dir, name) + if os.path.exists(fullname): + return fullname return name # rgbimg (unlike imgfile) is portable to platforms other than SGI. diff --git a/Lib/test/test_imgfile.py b/Lib/test/test_imgfile.py index 576a51c..aa9c414 100755 --- a/Lib/test/test_imgfile.py +++ b/Lib/test/test_imgfile.py @@ -24,12 +24,12 @@ def main(): unlink('greytest.rgb') def findfile(file): - if os.path.isabs(file): return file - import sys - for dn in sys.path: - fn = os.path.join(dn, file) - if os.path.exists(fn): return fn - return file + if os.path.isabs(file): return file + import sys + for dn in sys.path: + fn = os.path.join(dn, file) + if os.path.exists(fn): return fn + return file def testimage(name): """Run through the imgfile's battery of possible methods @@ -44,23 +44,23 @@ def testimage(name): # try opening the name directly try: - # This function returns a tuple (x, y, z) where x and y are the size - # of the image in pixels and z is the number of bytes per pixel. Only - # 3 byte RGB pixels and 1 byte greyscale pixels are supported. - sizes = imgfile.getsizes(name) + # This function returns a tuple (x, y, z) where x and y are the size + # of the image in pixels and z is the number of bytes per pixel. Only + # 3 byte RGB pixels and 1 byte greyscale pixels are supported. + sizes = imgfile.getsizes(name) except imgfile.error: - # get a more qualified path component of the script... - if __name__ == '__main__': - ourname = sys.argv[0] - else: # ...or the full path of the module - ourname = sys.modules[__name__].__file__ - - parts = string.splitfields(ourname, os.sep) - parts[-1] = name - name = string.joinfields(parts, os.sep) - sizes = imgfile.getsizes(name) + # get a more qualified path component of the script... + if __name__ == '__main__': + ourname = sys.argv[0] + else: # ...or the full path of the module + ourname = sys.modules[__name__].__file__ + + parts = string.splitfields(ourname, os.sep) + parts[-1] = name + name = string.joinfields(parts, os.sep) + sizes = imgfile.getsizes(name) if verbose: - print 'Opening test image: %s, sizes: %s' % (name, str(sizes)) + print 'Opening test image: %s, sizes: %s' % (name, str(sizes)) # This function reads and decodes the image on the specified file, # and returns it as a python string. The string has either 1 byte # greyscale pixels or 4 byte RGBA pixels. The bottom left pixel @@ -74,12 +74,12 @@ def testimage(name): # are stored as 4 byte values of which only the lower three # bytes are used). These are the formats returned by gl.lrectread. if verbose: - print 'Writing output file' + print 'Writing output file' imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2]) if verbose: - print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes)) + print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes)) # This function is identical to read but it returns an image that # is scaled to the given x and y sizes. If the filter and blur # parameters are omitted scaling is done by simply dropping @@ -93,7 +93,7 @@ def testimage(name): # makes no attempt to keep the aspect ratio correct, so that # is the users' responsibility. if verbose: - print 'Filtering with "impulse"' + print 'Filtering with "impulse"' simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'impulse', 2.0) # This function sets a global flag which defines whether the @@ -101,14 +101,14 @@ def testimage(name): # top (flag is zero, compatible with SGI GL) or from top to # bottom(flag is one, compatible with X). The default is zero. if verbose: - print 'Switching to X compatibility' + print 'Switching to X compatibility' imgfile.ttob (1) if verbose: - print 'Filtering with "triangle"' + 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' + print 'Switching back to SGI compatibility' imgfile.ttob (0) if verbose: print 'Filtering with "quadratic"' @@ -117,7 +117,7 @@ def testimage(name): simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'gaussian', 1.0) if verbose: - print 'Writing output file' + print 'Writing output file' imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2]) os.unlink(outputfile) diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py index b1e2ae7..a693d8b 100644 --- a/Lib/test/test_new.py +++ b/Lib/test/test_new.py @@ -4,7 +4,7 @@ import new class Eggs: def get_yolks(self): - return self.yolks + return self.yolks print 'new.module()' m = new.module('Spam') diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py index 0d345fe..b28a672 100644 --- a/Lib/test/test_nis.py +++ b/Lib/test/test_nis.py @@ -11,19 +11,19 @@ except nis.error, msg: done = 0 for nismap in maps: if verbose: - print nismap + print nismap mapping = nis.cat(nismap) for k, v in mapping.items(): - if verbose: - print ' ', k, v - if not k: - continue - if nis.match(k, nismap) <> v: - print "NIS match failed for key `%s' in map `%s'" % (k, nismap) - else: - # just test the one key, otherwise this test could take a - # very long time - done = 1 - break + if verbose: + print ' ', k, v + if not k: + continue + if nis.match(k, nismap) <> v: + print "NIS match failed for key `%s' in map `%s'" % (k, nismap) + else: + # just test the one key, otherwise this test could take a + # very long time + done = 1 + break if done: - break + break diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index 15c9dda..bdace26 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' @@ -30,7 +30,7 @@ class BClass(AClass): pass class CClass: pass class DClass(AClass): def __init__(self, ignore): - pass + pass try: raise AClass() except: pass @@ -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 @@ -64,7 +64,7 @@ except TypeError: pass try: raise DClass, a except DClass, v: if not isinstance(v, DClass): - raise TestFailed + raise TestFailed print '2.3 comparing function objects' diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index ff4cba0..8d3864c 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -6,11 +6,11 @@ def test(name, input, output, *args): f = getattr(operator, name) params = (input,) + args try: - val = apply(f, params) + val = apply(f, params) except: - val = sys.exc_type + val = sys.exc_type if val <> output: - print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`) + print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`) test('abs', -1, 1) test('add', 3, 7, 4) diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index dc5b567..aa0d3f0 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -1,7 +1,7 @@ # Test packages (dotted-name import) import sys, os, string, tempfile, traceback -from os import mkdir, rmdir # Can't test if these fail +from os import mkdir, rmdir # Can't test if these fail del mkdir, rmdir from test_support import verbose @@ -10,19 +10,19 @@ from test_support import verbose def mkhier(root, descr): mkdir(root) for name, contents in descr: - comps = string.split(name) - fullname = root - for c in comps: - fullname = os.path.join(fullname, c) - if contents is None: - mkdir(fullname) - else: - if verbose: print "write", fullname - f = open(fullname, "w") - f.write(contents) - if contents and contents[-1] != '\n': - f.write('\n') - f.close() + comps = string.split(name) + fullname = root + for c in comps: + fullname = os.path.join(fullname, c) + if contents is None: + mkdir(fullname) + else: + if verbose: print "write", fullname + f = open(fullname, "w") + f.write(contents) + if contents and contents[-1] != '\n': + f.write('\n') + f.close() def mkdir(x): if verbose: print "mkdir", x @@ -31,11 +31,11 @@ def mkdir(x): def cleanout(root): names = os.listdir(root) for name in names: - fullname = os.path.join(root, name) - if os.path.isdir(fullname) and not os.path.islink(fullname): - cleanout(fullname) - else: - os.remove(fullname) + fullname = os.path.join(root, name) + if os.path.isdir(fullname) and not os.path.islink(fullname): + cleanout(fullname) + else: + os.remove(fullname) rmdir(root) def rmdir(x): @@ -53,19 +53,19 @@ def runtest(hier, code): f.write(code) f.close() try: - sys.path.insert(0, root) - if verbose: print "sys.path =", sys.path - try: - execfile(codefile, globals(), {}) - except: - traceback.print_exc(file=sys.stdout) + sys.path.insert(0, root) + if verbose: print "sys.path =", sys.path + try: + execfile(codefile, globals(), {}) + except: + traceback.print_exc(file=sys.stdout) finally: - sys.path[:] = savepath - try: - cleanout(root) - except (os.error, IOError): - pass - os.remove(codefile) + sys.path[:] = savepath + try: + cleanout(root) + except (os.error, IOError): + pass + os.remove(codefile) # Test descriptions @@ -203,12 +203,12 @@ args = [] if __name__ == '__main__': args = sys.argv[1:] if args and args[0] == '-q': - verbose = 0 - del args[0] + verbose = 0 + del args[0] for name, hier, code in tests: if args and name not in args: - print "skipping test", name - continue + print "skipping test", name + continue print "running test", name runtest(hier, code) diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py index fc67253..ec17d53 100644 --- a/Lib/test/test_pow.py +++ b/Lib/test/test_pow.py @@ -13,16 +13,16 @@ def powtest(type): raise ValueError, 'pow(0,'+str(i)+') != 0' if (pow(type(1),1)!=type(1)): raise ValueError, 'pow(1,'+str(i)+') != 1' - + 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): + if (pow(2,i)!=pow2): raise ValueError, 'pow(2,'+str(i)+') != '+str(pow2) - if (i!=30): pow2=pow2*2 + if (i!=30): pow2=pow2*2 print " Testing 3-argument pow() function..." il, ih = -20, 20 @@ -31,7 +31,7 @@ def powtest(type): compare = cmp if (type==float): il=1 - compare = test_support.fcmp + compare = test_support.fcmp elif (type==int): jl=0 elif (type==long): @@ -39,11 +39,11 @@ def powtest(type): 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)): + 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) + "," +str(k)+ ") != pow(" +str(i)+ "," + \ + str(j)+ ") % " +str(k) print 'Testing integer mode...' diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index d900686..79bf866 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -9,17 +9,17 @@ for e in entries: name = e[0] uid = e[2] if verbose: - print name, uid + print name, uid print 'pwd.getpwuid()' dbuid = pwd.getpwuid(uid) if dbuid[0] <> name: - print 'Mismatch in pwd.getpwuid()' + print 'Mismatch in pwd.getpwuid()' print 'pwd.getpwnam()' dbname = pwd.getpwnam(name) if dbname[2] <> uid: - print 'Mismatch in pwd.getpwnam()' + print 'Mismatch in pwd.getpwnam()' else: - print 'name matches uid' + print 'name matches uid' break # try to get some errors @@ -35,21 +35,21 @@ fakename = allnames[namei] while bynames.has_key(fakename): chars = map(None, fakename) for i in range(len(chars)): - if chars[i] == 'z': - chars[i] = 'A' - break - elif chars[i] == 'Z': - continue - else: - chars[i] = chr(ord(chars[i]) + 1) - break + if chars[i] == 'z': + chars[i] = 'A' + break + elif chars[i] == 'Z': + continue + else: + chars[i] = chr(ord(chars[i]) + 1) + break else: - namei = namei + 1 - try: - fakename = allnames[namei] - except IndexError: - # should never happen... if so, just forget it - break + namei = namei + 1 + try: + fakename = allnames[namei] + except IndexError: + # should never happen... if so, just forget it + break fakename = string.join(map(None, chars), '') try: diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index b47c105..ffb5c66 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -15,8 +15,8 @@ try: assert re.sub("(?i)b+", "x", "bbbb BBBB") == 'x x' def bump_num(matchobj): - int_value = int(matchobj.group(0)) - return str(int_value + 1) + int_value = int(matchobj.group(0)) + return str(int_value + 1) assert re.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y' @@ -151,9 +151,9 @@ except AssertionError: for flags in [re.I, re.M, re.X, re.S, re.L]: try: - r = re.compile('^pattern$', flags) + r = re.compile('^pattern$', flags) except: - print 'Exception raised on flag', flags + print 'Exception raised on flag', flags from re_tests import * if verbose: @@ -166,86 +166,86 @@ for t in tests: sys.stdout.flush() pattern=s=outcome=repl=expected=None if len(t)==5: - pattern, s, outcome, repl, expected = t + 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) + raise ValueError, ('Test tuples should have 3 or 5 fields',t) try: - obj=re.compile(pattern) + obj=re.compile(pattern) except re.error: - if outcome==SYNTAX_ERROR: pass # Expected a syntax error - else: - print '=== Syntax error:', t + if outcome==SYNTAX_ERROR: pass # Expected a syntax error + else: + print '=== Syntax error:', t except KeyboardInterrupt: raise KeyboardInterrupt except: - print '*** Unexpected error ***' - if verbose: - traceback.print_exc(file=sys.stdout) + print '*** Unexpected error ***' + if verbose: + traceback.print_exc(file=sys.stdout) else: - try: - result=obj.search(s) - except (re.error), msg: - print '=== Unexpected exception', t, repr(msg) - if outcome==SYNTAX_ERROR: - # This should have been a syntax error; forget it. - pass - elif outcome==FAIL: - if result is None: pass # No match, as expected - else: print '=== Succeeded incorrectly', t - elif outcome==SUCCEED: - if result is not None: - # Matched, as expected, so now we compute the - # result string and compare it to our expected result. - start, end = result.span(0) - vardict={'found': result.group(0), - 'groups': result.group(), - 'flags': result.re.flags} - for i in range(1, 100): - try: - gi = result.group(i) - # Special hack because else the string concat fails: - if gi is None: - gi = "None" - except IndexError: - gi = "Error" - vardict['g%d' % i] = gi - for i in result.re.groupindex.keys(): - try: - gi = result.group(i) - if gi is None: - gi = "None" - except IndexError: - gi = "Error" - vardict[i] = gi - repl=eval(repl, vardict) - if repl!=expected: - print '=== grouping error', t, - print repr(repl)+' should be '+repr(expected) - else: - print '=== Failed incorrectly', t - - # Try the match with the search area limited to the extent - # of the match and see if it still succeeds. \B will - # break (because it won't match at the end or start of a - # string), so we'll ignore patterns that feature it. - - if pattern[:2]!='\\B' and pattern[-2:]!='\\B': - obj=re.compile(pattern) - result=obj.search(s, pos=result.start(0), endpos=result.end(0)+1) - if result==None: - print '=== Failed on range-limited match', t + try: + result=obj.search(s) + except (re.error), msg: + print '=== Unexpected exception', t, repr(msg) + if outcome==SYNTAX_ERROR: + # This should have been a syntax error; forget it. + pass + elif outcome==FAIL: + if result is None: pass # No match, as expected + else: print '=== Succeeded incorrectly', t + elif outcome==SUCCEED: + if result is not None: + # Matched, as expected, so now we compute the + # result string and compare it to our expected result. + start, end = result.span(0) + vardict={'found': result.group(0), + 'groups': result.group(), + 'flags': result.re.flags} + for i in range(1, 100): + try: + gi = result.group(i) + # Special hack because else the string concat fails: + if gi is None: + gi = "None" + except IndexError: + gi = "Error" + vardict['g%d' % i] = gi + for i in result.re.groupindex.keys(): + try: + gi = result.group(i) + if gi is None: + gi = "None" + except IndexError: + gi = "Error" + vardict[i] = gi + repl=eval(repl, vardict) + if repl!=expected: + print '=== grouping error', t, + print repr(repl)+' should be '+repr(expected) + else: + print '=== Failed incorrectly', t + + # Try the match with the search area limited to the extent + # of the match and see if it still succeeds. \B will + # break (because it won't match at the end or start of a + # string), so we'll ignore patterns that feature it. + + if pattern[:2]!='\\B' and pattern[-2:]!='\\B': + obj=re.compile(pattern) + result=obj.search(s, pos=result.start(0), endpos=result.end(0)+1) + if result==None: + print '=== Failed on range-limited match', t # Try the match with IGNORECASE enabled, and check that it - # still succeeds. + # still succeeds. obj=re.compile(pattern, re.IGNORECASE) result=obj.search(s) if result==None: print '=== Fails on case-insensitive match', t # Try the match with LOCALE enabled, and check that it - # still succeeds. + # still succeeds. obj=re.compile(pattern, re.LOCALE) result=obj.search(s) if result==None: diff --git a/Lib/test/test_regex.py b/Lib/test/test_regex.py index 4be6026..6a7f01b 100644 --- a/Lib/test/test_regex.py +++ b/Lib/test/test_regex.py @@ -67,44 +67,44 @@ if verbose: print 'Running regex_tests test suite' for t in tests: pattern=s=outcome=repl=expected=None if len(t)==5: - pattern, s, outcome, repl, expected = t + 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) + raise ValueError, ('Test tuples should have 3 or 5 fields',t) try: - obj=regex.compile(pattern) + 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 - # the official test suite they'll be quietly ignored. - pass - #print '=== Syntax error:', t + if outcome==SYNTAX_ERROR: pass # Expected a syntax error + else: + # Regex syntax errors aren't yet reported, so for + # the official test suite they'll be quietly ignored. + pass + #print '=== Syntax error:', t else: - try: - result=obj.search(s) - except regex.error, msg: - print '=== Unexpected exception', t, repr(msg) - if outcome==SYNTAX_ERROR: - # This should have been a syntax error; forget it. - pass - elif outcome==FAIL: - if result==-1: pass # No match, as expected - else: print '=== Succeeded incorrectly', t - elif outcome==SUCCEED: - if result!=-1: - # Matched, as expected, so now we compute the - # result string and compare it to our expected result. - start, end = obj.regs[0] - found=s[start:end] - groups=obj.group(1,2,3,4,5,6,7,8,9,10) - vardict=vars() - for i in range(len(groups)): - vardict['g'+str(i+1)]=str(groups[i]) - repl=eval(repl) - if repl!=expected: - print '=== grouping error', t, repr(repl)+' should be '+repr(expected) - else: - print '=== Failed incorrectly', t + try: + result=obj.search(s) + except regex.error, msg: + print '=== Unexpected exception', t, repr(msg) + if outcome==SYNTAX_ERROR: + # This should have been a syntax error; forget it. + pass + elif outcome==FAIL: + if result==-1: pass # No match, as expected + else: print '=== Succeeded incorrectly', t + elif outcome==SUCCEED: + if result!=-1: + # Matched, as expected, so now we compute the + # result string and compare it to our expected result. + start, end = obj.regs[0] + found=s[start:end] + groups=obj.group(1,2,3,4,5,6,7,8,9,10) + vardict=vars() + for i in range(len(groups)): + vardict['g'+str(i+1)]=str(groups[i]) + repl=eval(repl) + if repl!=expected: + print '=== grouping error', t, repr(repl)+' should be '+repr(expected) + else: + print '=== Failed incorrectly', t diff --git a/Lib/test/test_rgbimg.py b/Lib/test/test_rgbimg.py index c5b7c83..0c449da 100644 --- a/Lib/test/test_rgbimg.py +++ b/Lib/test/test_rgbimg.py @@ -9,32 +9,32 @@ error = 'test_rgbimg.error' print 'RGBimg test suite:' def findfile(file): - if os.path.isabs(file): return file - import sys - path = sys.path - try: - path = [os.path.dirname(__file__)] + path - except NameError: - pass - for dn in path: - fn = os.path.join(dn, file) - if os.path.exists(fn): return fn - return file + if os.path.isabs(file): return file + import sys + path = sys.path + try: + path = [os.path.dirname(__file__)] + path + except NameError: + pass + for dn in path: + fn = os.path.join(dn, file) + if os.path.exists(fn): return fn + return file 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'), @@ -45,7 +45,7 @@ for source, target in table: source = findfile(source) target = findfile(target) if verbose: - print "uudecoding", source, "->", target, "..." + print "uudecoding", source, "->", target, "..." uu.decode(source, target) if verbose: @@ -53,23 +53,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_select.py b/Lib/test/test_select.py index 53185b1..60de360 100644 --- a/Lib/test/test_select.py +++ b/Lib/test/test_select.py @@ -16,7 +16,7 @@ class Nope: class Almost: def fileno(self): - return 'fileno' + return 'fileno' try: rfd, wfd, xfd = select.select([Nope()], [], []) @@ -34,31 +34,31 @@ 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: - if verbose: - print 'timeout =', tout - rfd, wfd, xfd = select.select([p], [], [], tout) -## print rfd, wfd, xfd - 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 'Heh?' - p.close() + 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) +## print rfd, wfd, xfd + 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 'Heh?' + p.close() test() diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index b602c91..772b86b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1,11 +1,11 @@ # Not tested: -# socket.fromfd() -# sktobj.getsockopt() -# sktobj.recvfrom() -# sktobj.sendto() -# sktobj.setblocking() -# sktobj.setsockopt() -# sktobj.shutdown() +# socket.fromfd() +# sktobj.getsockopt() +# sktobj.recvfrom() +# sktobj.sendto() +# sktobj.setblocking() +# sktobj.setsockopt() +# sktobj.shutdown() from test_support import verbose, TestFailed @@ -16,9 +16,9 @@ import string def missing_ok(str): try: - getattr(socket, str) + getattr(socket, str) except AttributeError: - pass + pass try: raise socket.error except socket.error: print "socket.error" @@ -33,37 +33,37 @@ socket.SOCK_SEQPACKET for optional in ("AF_UNIX", - "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE", - "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER", - "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF", - "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO", - "SO_ERROR", "SO_TYPE", "SOMAXCONN", - - "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR", - "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG", - "MSG_ETAG", - - "SOL_SOCKET", - - "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP", - "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP", - "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP", - "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP", - "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP", - "IPPROTO_RAW", "IPPROTO_MAX", - - "IPPORT_RESERVED", "IPPORT_USERRESERVED", - - "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK", - "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP", - "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE", - - "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL", - "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR", - "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL", - "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP", - "IP_DROP_MEMBERSHIP", - ): + "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE", + "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER", + "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF", + "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO", + "SO_ERROR", "SO_TYPE", "SOMAXCONN", + + "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR", + "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG", + "MSG_ETAG", + + "SOL_SOCKET", + + "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP", + "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP", + "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP", + "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP", + "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP", + "IPPROTO_RAW", "IPPROTO_MAX", + + "IPPORT_RESERVED", "IPPORT_USERRESERVED", + + "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK", + "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP", + "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE", + + "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL", + "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR", + "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL", + "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP", + "IP_DROP_MEMBERSHIP", + ): missing_ok(optional) socktype = socket.SocketType @@ -80,7 +80,7 @@ if verbose: for name in all_host_names: if string.find(name, '.'): - break + break else: print 'FQDN not found' @@ -95,52 +95,52 @@ canfork = hasattr(os, 'fork') try: PORT = 50007 if not canfork or os.fork(): - # parent is server - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind(hostname, PORT) - s.listen(1) - if verbose: - print 'parent accepting' - if canfork: - conn, addr = s.accept() - if verbose: - print 'connected by', addr - # couple of interesting tests while we've got a live socket - f = conn.fileno() - if verbose: - print 'fileno:', f - p = conn.getpeername() - if verbose: - print 'peer:', p - n = conn.getsockname() - if verbose: - print 'sockname:', n - f = conn.makefile() - if verbose: - print 'file obj:', f - while 1: - data = conn.recv(1024) - if not data: - break - if verbose: - print 'received:', data - conn.send(data) - conn.close() + # parent is server + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(hostname, PORT) + s.listen(1) + if verbose: + print 'parent accepting' + if canfork: + conn, addr = s.accept() + if verbose: + print 'connected by', addr + # couple of interesting tests while we've got a live socket + f = conn.fileno() + if verbose: + print 'fileno:', f + p = conn.getpeername() + if verbose: + print 'peer:', p + n = conn.getsockname() + if verbose: + print 'sockname:', n + f = conn.makefile() + if verbose: + print 'file obj:', f + while 1: + data = conn.recv(1024) + if not data: + break + if verbose: + print 'received:', data + conn.send(data) + conn.close() else: - try: - # child is client - time.sleep(5) - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if verbose: - print 'child connecting' - s.connect(hostname, PORT) - msg = 'socket test' - s.send(msg) - data = s.recv(1024) - if msg <> data: - print 'parent/client mismatch' - s.close() - finally: - os._exit(1) + try: + # child is client + time.sleep(5) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if verbose: + print 'child connecting' + s.connect(hostname, PORT) + msg = 'socket test' + s.send(msg) + data = s.recv(1024) + if msg <> data: + print 'parent/client mismatch' + s.close() + finally: + os._exit(1) except socket.error, msg: raise TestFailed, msg diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py index f1db8df..7441a00 100755 --- a/Lib/test/test_strftime.py +++ b/Lib/test/test_strftime.py @@ -13,12 +13,12 @@ def main(): # Try a bunch of dates and times, chosen to vary through time of # day and daylight saving time for j in range(-5, 5): - for i in range(25): - strftest(now + (i + j*100)*23*3603) + for i in range(25): + strftest(now + (i + j*100)*23*3603) def strftest(now): if verbose: - print "strftime test for", time.ctime(now) + print "strftime test for", time.ctime(now) nowsecs = str(long(now))[:-1] gmt = time.gmtime(now) now = time.localtime(now) @@ -29,106 +29,106 @@ def strftest(now): jan1 = time.localtime(time.mktime((now[0], 1, 1) + (0,)*6)) try: - if now[8]: tz = time.tzname[1] - else: tz = time.tzname[0] + if now[8]: tz = time.tzname[1] + else: tz = time.tzname[0] except AttributeError: - tz = '' + tz = '' if now[3] > 12: clock12 = now[3] - 12 elif now[3] > 0: clock12 = now[3] else: clock12 = 12 expectations = ( - ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'), - ('%A', calendar.day_name[now[6]], 'full weekday name'), - ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'), - ('%B', calendar.month_name[now[1]], 'full month name'), - # %c see below - ('%d', '%02d' % now[2], 'day of month as number (00-31)'), - ('%H', '%02d' % now[3], 'hour (00-23)'), - ('%I', '%02d' % clock12, 'hour (01-12)'), - ('%j', '%03d' % now[7], 'julian day (001-366)'), - ('%m', '%02d' % now[1], 'month as number (01-12)'), - ('%M', '%02d' % now[4], 'minute, (00-59)'), - ('%p', ampm, 'AM or PM as appropriate'), - ('%S', '%02d' % now[5], 'seconds of current time (00-60)'), - ('%U', '%02d' % ((now[7] + jan1[6])/7), - 'week number of the year (Sun 1st)'), - ('%w', '%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'), - ('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)/7), - 'week number of the year (Mon 1st)'), - # %x see below - ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), - ('%y', '%02d' % (now[0]%100), 'year without century'), - ('%Y', '%d' % now[0], 'year with century'), - # %Z see below - ('%%', '%', 'single percent sign'), - ) + ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'), + ('%A', calendar.day_name[now[6]], 'full weekday name'), + ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'), + ('%B', calendar.month_name[now[1]], 'full month name'), + # %c see below + ('%d', '%02d' % now[2], 'day of month as number (00-31)'), + ('%H', '%02d' % now[3], 'hour (00-23)'), + ('%I', '%02d' % clock12, 'hour (01-12)'), + ('%j', '%03d' % now[7], 'julian day (001-366)'), + ('%m', '%02d' % now[1], 'month as number (01-12)'), + ('%M', '%02d' % now[4], 'minute, (00-59)'), + ('%p', ampm, 'AM or PM as appropriate'), + ('%S', '%02d' % now[5], 'seconds of current time (00-60)'), + ('%U', '%02d' % ((now[7] + jan1[6])/7), + 'week number of the year (Sun 1st)'), + ('%w', '%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'), + ('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)/7), + 'week number of the year (Mon 1st)'), + # %x see below + ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), + ('%y', '%02d' % (now[0]%100), 'year without century'), + ('%Y', '%d' % now[0], 'year with century'), + # %Z see below + ('%%', '%', 'single percent sign'), + ) nonstandard_expectations = ( - # These are standard but don't have predictable output - ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'), - ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), - '%m/%d/%y %H:%M:%S'), - ('(%Z)', '(%s)' % tz, 'time zone name'), - - # These are some platform specific extensions - ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'), - ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'), - ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'), - ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'), - ('%n', '\n', 'newline character'), - ('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm), - '%I:%M:%S %p'), - ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'), - ('%s', nowsecs, 'seconds since the Epoch in UCT'), - ('%t', '\t', 'tab character'), - ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), - ('%3y', '%03d' % (now[0]%100), - 'year without century rendered using fieldwidth'), - ) + # These are standard but don't have predictable output + ('%c', fixasctime(time.asctime(now)), 'near-asctime() format'), + ('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), + '%m/%d/%y %H:%M:%S'), + ('(%Z)', '(%s)' % tz, 'time zone name'), + + # These are some platform specific extensions + ('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'), + ('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-31)'), + ('%h', calendar.month_abbr[now[1]], 'abbreviated month name'), + ('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'), + ('%n', '\n', 'newline character'), + ('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm), + '%I:%M:%S %p'), + ('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'), + ('%s', nowsecs, 'seconds since the Epoch in UCT'), + ('%t', '\t', 'tab character'), + ('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), + ('%3y', '%03d' % (now[0]%100), + 'year without century rendered using fieldwidth'), + ) if verbose: - print "Strftime test, platform: %s, Python version: %s" % \ - (sys.platform, string.split(sys.version)[0]) + print "Strftime test, platform: %s, Python version: %s" % \ + (sys.platform, string.split(sys.version)[0]) for e in expectations: - try: - result = time.strftime(e[0], now) - except ValueError, error: - print "Standard '%s' format gave error:" % e[0], error - continue - if result == e[1]: continue - if result[0] == '%': - print "Does not support standard '%s' format (%s)" % (e[0], e[2]) - else: - print "Conflict for %s (%s):" % (e[0], e[2]) - print " Expected %s, but got %s" % (e[1], result) + try: + result = time.strftime(e[0], now) + except ValueError, error: + print "Standard '%s' format gave error:" % e[0], error + continue + if result == e[1]: continue + if result[0] == '%': + print "Does not support standard '%s' format (%s)" % (e[0], e[2]) + else: + print "Conflict for %s (%s):" % (e[0], e[2]) + print " Expected %s, but got %s" % (e[1], result) for e in nonstandard_expectations: - try: - result = time.strftime(e[0], now) - except ValueError, result: - if verbose: - print "Error for nonstandard '%s' format (%s): %s" % \ - (e[0], e[2], str(result)) - continue - if result == e[1]: - if verbose: - print "Supports nonstandard '%s' format (%s)" % (e[0], e[2]) - elif result[0] == '%': - if verbose: - print "Does not appear to support '%s' format (%s)" % (e[0], - e[2]) - else: - if verbose: - print "Conflict for nonstandard '%s' format (%s):" % (e[0], - e[2]) - print " Expected %s, but got %s" % (e[1], result) + try: + result = time.strftime(e[0], now) + except ValueError, result: + if verbose: + print "Error for nonstandard '%s' format (%s): %s" % \ + (e[0], e[2], str(result)) + continue + if result == e[1]: + if verbose: + print "Supports nonstandard '%s' format (%s)" % (e[0], e[2]) + elif result[0] == '%': + if verbose: + print "Does not appear to support '%s' format (%s)" % (e[0], + e[2]) + else: + if verbose: + print "Conflict for nonstandard '%s' format (%s):" % (e[0], + e[2]) + print " Expected %s, but got %s" % (e[1], result) def fixasctime(s): if s[8] == ' ': - s = s[:8] + '0' + s[9:] + s = s[:8] + '0' + s[9:] return s main() diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py index a4f1882..bd31058 100644 --- a/Lib/test/test_strop.py +++ b/Lib/test/test_strop.py @@ -3,19 +3,19 @@ import strop, sys def test(name, input, output, *args): if verbose: - print 'string.%s%s =? %s... ' % (name, (input,) + args, output), + print 'string.%s%s =? %s... ' % (name, (input,) + args, output), f = getattr(strop, name) try: - value = apply(f, (input,) + args) + value = apply(f, (input,) + args) except: - value = sys.exc_type + value = sys.exc_type if value != output: - if verbose: - print 'no' - print f, `input`, `output`, `value` + if verbose: + print 'no' + print f, `input`, `output`, `value` else: - if verbose: - print 'yes' + if verbose: + print 'yes' test('atoi', " 1 ", 1) test('atoi', " 1x", ValueError) diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index c1e7b9e..2c599d7 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -4,13 +4,13 @@ import struct def simple_err(func, *args): try: - apply(func, args) + apply(func, args) except struct.error: - pass + pass else: - raise TestFailed, "%s%s did not raise struct.error" % ( - func.__name__, args) -## pdb.set_trace() + raise TestFailed, "%s%s did not raise struct.error" % ( + func.__name__, args) +## pdb.set_trace() simple_err(struct.calcsize, 'Q') @@ -24,7 +24,7 @@ sz = struct.calcsize(fmt) sz3 = struct.calcsize(fmt3) if sz * 3 <> sz3: raise TestFailed, 'inconsistent sizes (3*%s -> 3*%d = %d, %s -> %d)' % ( - `fmt`, sz, 3*sz, `fmt3`, sz3) + `fmt`, sz, 3*sz, `fmt3`, sz3) simple_err(struct.pack, 'iii', 3) simple_err(struct.pack, 'i', 3, 3, 3) @@ -44,16 +44,16 @@ d = 3.1415 for prefix in ('', '@', '<', '>', '=', '!'): for format in ('xcbhilfd', 'xcBHILfd'): - format = prefix + format - if verbose: - print "trying:", format - s = struct.pack(format, c, b, h, i, l, f, d) - cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s) - if (cp <> c or bp <> b or hp <> h or ip <> i or lp <> l or - int(100 * fp) <> int(100 * f) or int(100 * dp) <> int(100 * d)): - # ^^^ calculate only to two decimal places - raise TestFailed, "unpack/pack not transitive (%s, %s)" % ( - str(format), str((cp, bp, hp, ip, lp, fp, dp))) + format = prefix + format + if verbose: + print "trying:", format + s = struct.pack(format, c, b, h, i, l, f, d) + cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s) + if (cp <> c or bp <> b or hp <> h or ip <> i or lp <> l or + int(100 * fp) <> int(100 * f) or int(100 * dp) <> int(100 * d)): + # ^^^ calculate only to two decimal places + raise TestFailed, "unpack/pack not transitive (%s, %s)" % ( + str(format), str((cp, bp, hp, ip, lp, fp, dp))) # Test some of the new features in detail @@ -98,24 +98,24 @@ def badpack(fmt, arg, got, exp): def badunpack(fmt, arg, got, exp): return "unpack(%s, %s) -> (%s,) # expected (%s,)" % ( - `fmt`, `arg`, `got`, `exp`) + `fmt`, `arg`, `got`, `exp`) isbigendian = struct.pack('=h', 1) == '\0\1' for fmt, arg, big, lil, asy in tests: if verbose: - print `fmt`, `arg`, `big`, `lil` + print `fmt`, `arg`, `big`, `lil` for (xfmt, exp) in [('>'+fmt, big), ('!'+fmt, big), ('<'+fmt, lil), - ('='+fmt, isbigendian and big or lil)]: - res = struct.pack(xfmt, arg) - if res != exp: - raise TestFailed, "pack(%s, %s) -> %s # expected %s" % ( - `fmt`, `arg`, `res`, `exp`) - n = struct.calcsize(xfmt) - if n != len(res): - raise TestFailed, "calcsize(%s) -> %d # expected %d" % ( - `xfmt`, n, len(res)) - rev = struct.unpack(xfmt, res)[0] - if rev != arg and not asy: - raise TestFailed, "unpack(%s, %s) -> (%s,) # expected (%s,)" % ( - `fmt`, `res`, `rev`, `arg`) + ('='+fmt, isbigendian and big or lil)]: + res = struct.pack(xfmt, arg) + if res != exp: + raise TestFailed, "pack(%s, %s) -> %s # expected %s" % ( + `fmt`, `arg`, `res`, `exp`) + n = struct.calcsize(xfmt) + if n != len(res): + raise TestFailed, "calcsize(%s) -> %d # expected %d" % ( + `xfmt`, n, len(res)) + rev = struct.unpack(xfmt, res)[0] + if rev != arg and not asy: + raise TestFailed, "unpack(%s, %s) -> (%s,) # expected (%s,)" % ( + `fmt`, `res`, `rev`, `arg`) diff --git a/Lib/test/test_sunaudiodev.py b/Lib/test/test_sunaudiodev.py index 7e9d1b1e..1438c09 100644 --- a/Lib/test/test_sunaudiodev.py +++ b/Lib/test/test_sunaudiodev.py @@ -3,29 +3,29 @@ import sunaudiodev import os def findfile(file): - if os.path.isabs(file): return file - import sys - path = sys.path - try: - path = [os.path.dirname(__file__)] + path - except NameError: - pass - for dn in path: - fn = os.path.join(dn, file) - if os.path.exists(fn): return fn - return file + if os.path.isabs(file): return file + import sys + path = sys.path + try: + path = [os.path.dirname(__file__)] + path + except NameError: + pass + for dn in path: + fn = os.path.join(dn, file) + if os.path.exists(fn): return fn + return file def play_sound_file(path): fp = open(path, 'r') data = fp.read() fp.close() try: - a = sunaudiodev.open('w') + a = sunaudiodev.open('w') except sunaudiodev.error, msg: - raise TestFailed, msg + raise TestFailed, msg else: - a.write(data) - a.close() + a.write(data) + a.close() def test(): play_sound_file(findfile('audiotest.au')) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index cfa18a3..03d081e 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -14,13 +14,13 @@ if long(time.mktime(time.localtime(t))) <> long(t): time.sleep(1.2) tt = time.gmtime(t) for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', - 'j', 'm', 'M', 'p', 'S', - 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): + 'j', 'm', 'M', 'p', 'S', + 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): format = ' %' + directive try: - time.strftime(format, tt) + time.strftime(format, tt) except ValueError: - print 'conversion specifier:', format, ' failed.' + print 'conversion specifier:', format, ' failed.' time.timezone time.tzname @@ -33,7 +33,7 @@ except TypeError: try: time.mktime((999999, 999999, 999999, 999999, - 999999, 999999, 999999, 999999, - 999999)) + 999999, 999999, 999999, 999999, + 999999)) except OverflowError: pass diff --git a/Lib/test/test_unpack.py b/Lib/test/test_unpack.py index 1f69504..1bfd478 100644 --- a/Lib/test/test_unpack.py +++ b/Lib/test/test_unpack.py @@ -5,8 +5,8 @@ l = [4, 5, 6] class Seq: def __getitem__(self, i): - if i >= 0 and i < 3: return i - raise IndexError + if i >= 0 and i < 3: return i + raise IndexError a = -1 b = -1 @@ -104,12 +104,12 @@ BozoError = 'BozoError' class BadSeq: def __getitem__(self, i): - if i >= 0 and i < 3: - return i - elif i == 3: - raise BozoError - else: - raise IndexError + if i >= 0 and i < 3: + return i + elif i == 3: + raise BozoError + else: + raise IndexError # trigger code while not expecting an IndexError |