mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Make reindent.py happy (convert everything to 4-space indents!).
This commit is contained in:
parent
2e6d25c5bb
commit
004d5e6880
70 changed files with 1215 additions and 1247 deletions
|
@ -3,32 +3,32 @@
|
||||||
"""
|
"""
|
||||||
"PYSTONE" Benchmark Program
|
"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.
|
Translated from ADA to C by Rick Richardson.
|
||||||
Every method to preserve ADA-likeness has been used,
|
Every method to preserve ADA-likeness has been used,
|
||||||
at the expense of C-ness.
|
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 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
|
First, it leaked memory: in Proc1(), NextRecord ends
|
||||||
up having a pointer to itself. I have corrected this
|
up having a pointer to itself. I have corrected this
|
||||||
by zapping NextRecord.PtrComp at the end of Proc1().
|
by zapping NextRecord.PtrComp at the end of Proc1().
|
||||||
|
|
||||||
Second, Proc3() used the operator != to compare a
|
Second, Proc3() used the operator != to compare a
|
||||||
record to None. This is rather inefficient and not
|
record to None. This is rather inefficient and not
|
||||||
true to the intention of the original benchmark (where
|
true to the intention of the original benchmark (where
|
||||||
a pointer comparison to None is intended; the !=
|
a pointer comparison to None is intended; the !=
|
||||||
operator attempts to find a method __cmp__ to do value
|
operator attempts to find a method __cmp__ to do value
|
||||||
comparison of the record). Version 1.1 runs 5-10
|
comparison of the record). Version 1.1 runs 5-10
|
||||||
percent faster than version 1.0, so benchmark figures
|
percent faster than version 1.0, so benchmark figures
|
||||||
of different versions can't be compared directly.
|
of different versions can't be compared directly.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -42,30 +42,30 @@ __version__ = "1.1"
|
||||||
|
|
||||||
class Record:
|
class Record:
|
||||||
|
|
||||||
def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0,
|
def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0,
|
||||||
IntComp = 0, StringComp = 0):
|
IntComp = 0, StringComp = 0):
|
||||||
self.PtrComp = PtrComp
|
self.PtrComp = PtrComp
|
||||||
self.Discr = Discr
|
self.Discr = Discr
|
||||||
self.EnumComp = EnumComp
|
self.EnumComp = EnumComp
|
||||||
self.IntComp = IntComp
|
self.IntComp = IntComp
|
||||||
self.StringComp = StringComp
|
self.StringComp = StringComp
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return Record(self.PtrComp, self.Discr, self.EnumComp,
|
return Record(self.PtrComp, self.Discr, self.EnumComp,
|
||||||
self.IntComp, self.StringComp)
|
self.IntComp, self.StringComp)
|
||||||
|
|
||||||
TRUE = 1
|
TRUE = 1
|
||||||
FALSE = 0
|
FALSE = 0
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
benchtime, stones = pystones()
|
benchtime, stones = pystones()
|
||||||
print "Pystone(%s) time for %d passes = %g" % \
|
print "Pystone(%s) time for %d passes = %g" % \
|
||||||
(__version__, LOOPS, benchtime)
|
(__version__, LOOPS, benchtime)
|
||||||
print "This machine benchmarks at %g pystones/second" % stones
|
print "This machine benchmarks at %g pystones/second" % stones
|
||||||
|
|
||||||
|
|
||||||
def pystones(loops=LOOPS):
|
def pystones(loops=LOOPS):
|
||||||
return Proc0(loops)
|
return Proc0(loops)
|
||||||
|
|
||||||
IntGlob = 0
|
IntGlob = 0
|
||||||
BoolGlob = FALSE
|
BoolGlob = FALSE
|
||||||
|
@ -77,176 +77,176 @@ PtrGlb = None
|
||||||
PtrGlbNext = None
|
PtrGlbNext = None
|
||||||
|
|
||||||
def Proc0(loops=LOOPS):
|
def Proc0(loops=LOOPS):
|
||||||
global IntGlob
|
global IntGlob
|
||||||
global BoolGlob
|
global BoolGlob
|
||||||
global Char1Glob
|
global Char1Glob
|
||||||
global Char2Glob
|
global Char2Glob
|
||||||
global Array1Glob
|
global Array1Glob
|
||||||
global Array2Glob
|
global Array2Glob
|
||||||
global PtrGlb
|
global PtrGlb
|
||||||
global PtrGlbNext
|
global PtrGlbNext
|
||||||
|
|
||||||
starttime = clock()
|
starttime = clock()
|
||||||
for i in range(loops):
|
for i in range(loops):
|
||||||
pass
|
pass
|
||||||
nulltime = clock() - starttime
|
nulltime = clock() - starttime
|
||||||
|
|
||||||
PtrGlbNext = Record()
|
PtrGlbNext = Record()
|
||||||
PtrGlb = Record()
|
PtrGlb = Record()
|
||||||
PtrGlb.PtrComp = PtrGlbNext
|
PtrGlb.PtrComp = PtrGlbNext
|
||||||
PtrGlb.Discr = Ident1
|
PtrGlb.Discr = Ident1
|
||||||
PtrGlb.EnumComp = Ident3
|
PtrGlb.EnumComp = Ident3
|
||||||
PtrGlb.IntComp = 40
|
PtrGlb.IntComp = 40
|
||||||
PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING"
|
PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING"
|
||||||
String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING"
|
String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING"
|
||||||
Array2Glob[8][7] = 10
|
Array2Glob[8][7] = 10
|
||||||
|
|
||||||
starttime = clock()
|
starttime = clock()
|
||||||
|
|
||||||
for i in range(loops):
|
for i in range(loops):
|
||||||
Proc5()
|
Proc5()
|
||||||
Proc4()
|
Proc4()
|
||||||
IntLoc1 = 2
|
IntLoc1 = 2
|
||||||
IntLoc2 = 3
|
IntLoc2 = 3
|
||||||
String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING"
|
String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING"
|
||||||
EnumLoc = Ident2
|
EnumLoc = Ident2
|
||||||
BoolGlob = not Func2(String1Loc, String2Loc)
|
BoolGlob = not Func2(String1Loc, String2Loc)
|
||||||
while IntLoc1 < IntLoc2:
|
while IntLoc1 < IntLoc2:
|
||||||
IntLoc3 = 5 * IntLoc1 - IntLoc2
|
IntLoc3 = 5 * IntLoc1 - IntLoc2
|
||||||
IntLoc3 = Proc7(IntLoc1, IntLoc2)
|
IntLoc3 = Proc7(IntLoc1, IntLoc2)
|
||||||
IntLoc1 = IntLoc1 + 1
|
IntLoc1 = IntLoc1 + 1
|
||||||
Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
|
Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
|
||||||
PtrGlb = Proc1(PtrGlb)
|
PtrGlb = Proc1(PtrGlb)
|
||||||
CharIndex = 'A'
|
CharIndex = 'A'
|
||||||
while CharIndex <= Char2Glob:
|
while CharIndex <= Char2Glob:
|
||||||
if EnumLoc == Func1(CharIndex, 'C'):
|
if EnumLoc == Func1(CharIndex, 'C'):
|
||||||
EnumLoc = Proc6(Ident1)
|
EnumLoc = Proc6(Ident1)
|
||||||
CharIndex = chr(ord(CharIndex)+1)
|
CharIndex = chr(ord(CharIndex)+1)
|
||||||
IntLoc3 = IntLoc2 * IntLoc1
|
IntLoc3 = IntLoc2 * IntLoc1
|
||||||
IntLoc2 = IntLoc3 / IntLoc1
|
IntLoc2 = IntLoc3 / IntLoc1
|
||||||
IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
|
IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
|
||||||
IntLoc1 = Proc2(IntLoc1)
|
IntLoc1 = Proc2(IntLoc1)
|
||||||
|
|
||||||
benchtime = clock() - starttime - nulltime
|
benchtime = clock() - starttime - nulltime
|
||||||
return benchtime, (loops / benchtime)
|
return benchtime, (loops / benchtime)
|
||||||
|
|
||||||
def Proc1(PtrParIn):
|
def Proc1(PtrParIn):
|
||||||
PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
|
PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
|
||||||
PtrParIn.IntComp = 5
|
PtrParIn.IntComp = 5
|
||||||
NextRecord.IntComp = PtrParIn.IntComp
|
NextRecord.IntComp = PtrParIn.IntComp
|
||||||
NextRecord.PtrComp = PtrParIn.PtrComp
|
NextRecord.PtrComp = PtrParIn.PtrComp
|
||||||
NextRecord.PtrComp = Proc3(NextRecord.PtrComp)
|
NextRecord.PtrComp = Proc3(NextRecord.PtrComp)
|
||||||
if NextRecord.Discr == Ident1:
|
if NextRecord.Discr == Ident1:
|
||||||
NextRecord.IntComp = 6
|
NextRecord.IntComp = 6
|
||||||
NextRecord.EnumComp = Proc6(PtrParIn.EnumComp)
|
NextRecord.EnumComp = Proc6(PtrParIn.EnumComp)
|
||||||
NextRecord.PtrComp = PtrGlb.PtrComp
|
NextRecord.PtrComp = PtrGlb.PtrComp
|
||||||
NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
|
NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
|
||||||
else:
|
else:
|
||||||
PtrParIn = NextRecord.copy()
|
PtrParIn = NextRecord.copy()
|
||||||
NextRecord.PtrComp = None
|
NextRecord.PtrComp = None
|
||||||
return PtrParIn
|
return PtrParIn
|
||||||
|
|
||||||
def Proc2(IntParIO):
|
def Proc2(IntParIO):
|
||||||
IntLoc = IntParIO + 10
|
IntLoc = IntParIO + 10
|
||||||
while 1:
|
while 1:
|
||||||
if Char1Glob == 'A':
|
if Char1Glob == 'A':
|
||||||
IntLoc = IntLoc - 1
|
IntLoc = IntLoc - 1
|
||||||
IntParIO = IntLoc - IntGlob
|
IntParIO = IntLoc - IntGlob
|
||||||
EnumLoc = Ident1
|
EnumLoc = Ident1
|
||||||
if EnumLoc == Ident1:
|
if EnumLoc == Ident1:
|
||||||
break
|
break
|
||||||
return IntParIO
|
return IntParIO
|
||||||
|
|
||||||
def Proc3(PtrParOut):
|
def Proc3(PtrParOut):
|
||||||
global IntGlob
|
global IntGlob
|
||||||
|
|
||||||
if PtrGlb is not None:
|
if PtrGlb is not None:
|
||||||
PtrParOut = PtrGlb.PtrComp
|
PtrParOut = PtrGlb.PtrComp
|
||||||
else:
|
else:
|
||||||
IntGlob = 100
|
IntGlob = 100
|
||||||
PtrGlb.IntComp = Proc7(10, IntGlob)
|
PtrGlb.IntComp = Proc7(10, IntGlob)
|
||||||
return PtrParOut
|
return PtrParOut
|
||||||
|
|
||||||
def Proc4():
|
def Proc4():
|
||||||
global Char2Glob
|
global Char2Glob
|
||||||
|
|
||||||
BoolLoc = Char1Glob == 'A'
|
BoolLoc = Char1Glob == 'A'
|
||||||
BoolLoc = BoolLoc or BoolGlob
|
BoolLoc = BoolLoc or BoolGlob
|
||||||
Char2Glob = 'B'
|
Char2Glob = 'B'
|
||||||
|
|
||||||
def Proc5():
|
def Proc5():
|
||||||
global Char1Glob
|
global Char1Glob
|
||||||
global BoolGlob
|
global BoolGlob
|
||||||
|
|
||||||
Char1Glob = 'A'
|
Char1Glob = 'A'
|
||||||
BoolGlob = FALSE
|
BoolGlob = FALSE
|
||||||
|
|
||||||
def Proc6(EnumParIn):
|
def Proc6(EnumParIn):
|
||||||
EnumParOut = EnumParIn
|
EnumParOut = EnumParIn
|
||||||
if not Func3(EnumParIn):
|
if not Func3(EnumParIn):
|
||||||
EnumParOut = Ident4
|
EnumParOut = Ident4
|
||||||
if EnumParIn == Ident1:
|
if EnumParIn == Ident1:
|
||||||
EnumParOut = Ident1
|
EnumParOut = Ident1
|
||||||
elif EnumParIn == Ident2:
|
elif EnumParIn == Ident2:
|
||||||
if IntGlob > 100:
|
if IntGlob > 100:
|
||||||
EnumParOut = Ident1
|
EnumParOut = Ident1
|
||||||
else:
|
else:
|
||||||
EnumParOut = Ident4
|
EnumParOut = Ident4
|
||||||
elif EnumParIn == Ident3:
|
elif EnumParIn == Ident3:
|
||||||
EnumParOut = Ident2
|
EnumParOut = Ident2
|
||||||
elif EnumParIn == Ident4:
|
elif EnumParIn == Ident4:
|
||||||
pass
|
pass
|
||||||
elif EnumParIn == Ident5:
|
elif EnumParIn == Ident5:
|
||||||
EnumParOut = Ident3
|
EnumParOut = Ident3
|
||||||
return EnumParOut
|
return EnumParOut
|
||||||
|
|
||||||
def Proc7(IntParI1, IntParI2):
|
def Proc7(IntParI1, IntParI2):
|
||||||
IntLoc = IntParI1 + 2
|
IntLoc = IntParI1 + 2
|
||||||
IntParOut = IntParI2 + IntLoc
|
IntParOut = IntParI2 + IntLoc
|
||||||
return IntParOut
|
return IntParOut
|
||||||
|
|
||||||
def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
|
def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
|
||||||
global IntGlob
|
global IntGlob
|
||||||
|
|
||||||
IntLoc = IntParI1 + 5
|
IntLoc = IntParI1 + 5
|
||||||
Array1Par[IntLoc] = IntParI2
|
Array1Par[IntLoc] = IntParI2
|
||||||
Array1Par[IntLoc+1] = Array1Par[IntLoc]
|
Array1Par[IntLoc+1] = Array1Par[IntLoc]
|
||||||
Array1Par[IntLoc+30] = IntLoc
|
Array1Par[IntLoc+30] = IntLoc
|
||||||
for IntIndex in range(IntLoc, IntLoc+2):
|
for IntIndex in range(IntLoc, IntLoc+2):
|
||||||
Array2Par[IntLoc][IntIndex] = IntLoc
|
Array2Par[IntLoc][IntIndex] = IntLoc
|
||||||
Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1
|
Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1
|
||||||
Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
|
Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
|
||||||
IntGlob = 5
|
IntGlob = 5
|
||||||
|
|
||||||
def Func1(CharPar1, CharPar2):
|
def Func1(CharPar1, CharPar2):
|
||||||
CharLoc1 = CharPar1
|
CharLoc1 = CharPar1
|
||||||
CharLoc2 = CharLoc1
|
CharLoc2 = CharLoc1
|
||||||
if CharLoc2 != CharPar2:
|
if CharLoc2 != CharPar2:
|
||||||
return Ident1
|
return Ident1
|
||||||
else:
|
else:
|
||||||
return Ident2
|
return Ident2
|
||||||
|
|
||||||
def Func2(StrParI1, StrParI2):
|
def Func2(StrParI1, StrParI2):
|
||||||
IntLoc = 1
|
IntLoc = 1
|
||||||
while IntLoc <= 1:
|
while IntLoc <= 1:
|
||||||
if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
|
if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
|
||||||
CharLoc = 'A'
|
CharLoc = 'A'
|
||||||
IntLoc = IntLoc + 1
|
IntLoc = IntLoc + 1
|
||||||
if CharLoc >= 'W' and CharLoc <= 'Z':
|
if CharLoc >= 'W' and CharLoc <= 'Z':
|
||||||
IntLoc = 7
|
IntLoc = 7
|
||||||
if CharLoc == 'X':
|
if CharLoc == 'X':
|
||||||
return TRUE
|
return TRUE
|
||||||
else:
|
else:
|
||||||
if StrParI1 > StrParI2:
|
if StrParI1 > StrParI2:
|
||||||
IntLoc = IntLoc + 7
|
IntLoc = IntLoc + 7
|
||||||
return TRUE
|
return TRUE
|
||||||
else:
|
else:
|
||||||
return FALSE
|
return FALSE
|
||||||
|
|
||||||
def Func3(EnumParIn):
|
def Func3(EnumParIn):
|
||||||
EnumLoc = EnumParIn
|
EnumLoc = EnumParIn
|
||||||
if EnumLoc == Ident3: return TRUE
|
if EnumLoc == Ident3: return TRUE
|
||||||
return FALSE
|
return FALSE
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Regex test suite and benchmark suite v1.5a2
|
# 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.
|
# only work with Python 1.5 or higher.
|
||||||
|
@ -15,16 +14,16 @@
|
||||||
# matching performs on large strings.
|
# matching performs on large strings.
|
||||||
|
|
||||||
benchmarks = [
|
benchmarks = [
|
||||||
('Python', 'Python'), # Simple text literal
|
('Python', 'Python'), # Simple text literal
|
||||||
('.*Python', 'Python'), # Bad text literal
|
('.*Python', 'Python'), # Bad text literal
|
||||||
('.*Python.*', 'Python'), # Worse 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'), # Alternation
|
||||||
('\\(Python\\|Perl\\|Tcl\\)', 'Perl'), # Grouped alternation
|
('\\(Python\\|Perl\\|Tcl\\)', 'Perl'), # Grouped alternation
|
||||||
('\\(Python\\)\\1', 'PythonPython'), # Backreference
|
('\\(Python\\)\\1', 'PythonPython'), # Backreference
|
||||||
# ('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization
|
# ('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization
|
||||||
('\\([a-z][a-z0-9]*,\\)+', 'a5,b7,c9,') # A few sets
|
('\\([a-z][a-z0-9]*,\\)+', 'a5,b7,c9,') # A few sets
|
||||||
]
|
]
|
||||||
|
|
||||||
# Test suite (for verifying correctness)
|
# Test suite (for verifying correctness)
|
||||||
|
@ -286,4 +285,3 @@ tests = [
|
||||||
('a\>', 'a!', SUCCEED, 'found', 'a'),
|
('a\>', 'a!', SUCCEED, 'found', 'a'),
|
||||||
('a\>', 'a', SUCCEED, 'found', 'a'),
|
('a\>', 'a', SUCCEED, 'found', 'a'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,3 @@ def main():
|
||||||
getattr(al, attr)
|
getattr(al, attr)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -16,173 +16,172 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
def testoverflow(type, lowerLimit, upperLimit):
|
def testoverflow(type, lowerLimit, upperLimit):
|
||||||
# should not overflow assigning lower limit
|
# should not overflow assigning lower limit
|
||||||
if verbose:
|
if verbose:
|
||||||
print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`)
|
print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`)
|
||||||
try:
|
try:
|
||||||
a = array.array(type, [lowerLimit])
|
a = array.array(type, [lowerLimit])
|
||||||
except:
|
except:
|
||||||
raise TestFailed, "array(%s) overflowed assigning %s" %\
|
raise TestFailed, "array(%s) overflowed assigning %s" %\
|
||||||
(`type`, `lowerLimit`)
|
(`type`, `lowerLimit`)
|
||||||
# should overflow assigning less than lower limit
|
# should overflow assigning less than lower limit
|
||||||
if verbose:
|
if verbose:
|
||||||
print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`)
|
print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`)
|
||||||
try:
|
try:
|
||||||
a = array.array(type, [lowerLimit-1])
|
a = array.array(type, [lowerLimit-1])
|
||||||
raise TestFailed, "array(%s) did not overflow assigning %s" %\
|
raise TestFailed, "array(%s) did not overflow assigning %s" %\
|
||||||
(`type`, `lowerLimit-1`)
|
(`type`, `lowerLimit-1`)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
pass
|
pass
|
||||||
# should not overflow assigning upper limit
|
# should not overflow assigning upper limit
|
||||||
if verbose:
|
if verbose:
|
||||||
print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`)
|
print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`)
|
||||||
try:
|
try:
|
||||||
a = array.array(type, [upperLimit])
|
a = array.array(type, [upperLimit])
|
||||||
except:
|
except:
|
||||||
raise TestFailed, "array(%s) overflowed assigning %s" %\
|
raise TestFailed, "array(%s) overflowed assigning %s" %\
|
||||||
(`type`, `upperLimit`)
|
(`type`, `upperLimit`)
|
||||||
# should overflow assigning more than upper limit
|
# should overflow assigning more than upper limit
|
||||||
if verbose:
|
if verbose:
|
||||||
print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`)
|
print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`)
|
||||||
try:
|
try:
|
||||||
a = array.array(type, [upperLimit+1])
|
a = array.array(type, [upperLimit+1])
|
||||||
raise TestFailed, "array(%s) did not overflow assigning %s" %\
|
raise TestFailed, "array(%s) did not overflow assigning %s" %\
|
||||||
(`type`, `upperLimit+1`)
|
(`type`, `upperLimit+1`)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def testtype(type, example):
|
def testtype(type, example):
|
||||||
|
|
||||||
a = array.array(type)
|
a = array.array(type)
|
||||||
a.append(example)
|
a.append(example)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 40*'*'
|
print 40*'*'
|
||||||
print 'array after append: ', a
|
print 'array after append: ', a
|
||||||
a.typecode
|
a.typecode
|
||||||
a.itemsize
|
a.itemsize
|
||||||
if a.typecode in ('i', 'b', 'h', 'l'):
|
if a.typecode in ('i', 'b', 'h', 'l'):
|
||||||
a.byteswap()
|
a.byteswap()
|
||||||
|
|
||||||
if a.typecode == 'c':
|
if a.typecode == 'c':
|
||||||
f = open(TESTFN, "w")
|
f = open(TESTFN, "w")
|
||||||
f.write("The quick brown fox jumps over the lazy dog.\n")
|
f.write("The quick brown fox jumps over the lazy dog.\n")
|
||||||
f.close()
|
f.close()
|
||||||
f = open(TESTFN, 'r')
|
f = open(TESTFN, 'r')
|
||||||
a.fromfile(f, 10)
|
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()
|
f.close()
|
||||||
a.tolist()
|
|
||||||
a.tostring()
|
|
||||||
if verbose:
|
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:
|
if verbose:
|
||||||
print 'array of %s converted to a string: ' \
|
print 'char array with list appended: ', a
|
||||||
% a.typecode, `a.tostring()`
|
|
||||||
|
|
||||||
if type == 'c':
|
a.insert(0, example)
|
||||||
a = array.array(type, "abcde")
|
if verbose:
|
||||||
a[:-1] = a
|
print 'array of %s after inserting another:' % a.typecode, a
|
||||||
if a != array.array(type, "abcdee"):
|
f = open(TESTFN, 'w')
|
||||||
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
a.tofile(f)
|
||||||
a = array.array(type, "abcde")
|
f.close()
|
||||||
a[1:] = a
|
a.tolist()
|
||||||
if a != array.array(type, "aabcde"):
|
a.tostring()
|
||||||
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
if verbose:
|
||||||
a = array.array(type, "abcde")
|
print 'array of %s converted to a list: ' % a.typecode, a.tolist()
|
||||||
a[1:-1] = a
|
if verbose:
|
||||||
if a != array.array(type, "aabcdee"):
|
print 'array of %s converted to a string: ' \
|
||||||
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
|
% a.typecode, `a.tostring()`
|
||||||
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
|
if type == 'c':
|
||||||
# to array of specific integral types
|
a = array.array(type, "abcde")
|
||||||
from math import pow
|
a[:-1] = a
|
||||||
if type in ('b', 'h', 'i', 'l'):
|
if a != array.array(type, "abcdee"):
|
||||||
# check signed and unsigned versions
|
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
||||||
a = array.array(type)
|
a = array.array(type, "abcde")
|
||||||
signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1))
|
a[1:] = a
|
||||||
signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L
|
if a != array.array(type, "aabcde"):
|
||||||
unsignedLowerLimit = 0
|
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
||||||
unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L
|
a = array.array(type, "abcde")
|
||||||
testoverflow(type, signedLowerLimit, signedUpperLimit)
|
a[1:-1] = a
|
||||||
testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit)
|
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()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Augmented assignment test.
|
# Augmented assignment test.
|
||||||
|
|
||||||
x = 2
|
x = 2
|
||||||
|
@ -55,22 +54,22 @@ print x
|
||||||
print x is y
|
print x is y
|
||||||
|
|
||||||
class aug_test:
|
class aug_test:
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.val = value
|
self.val = value
|
||||||
def __radd__(self, val):
|
def __radd__(self, val):
|
||||||
return self.val + val
|
return self.val + val
|
||||||
def __add__(self, val):
|
def __add__(self, val):
|
||||||
return aug_test(self.val + val)
|
return aug_test(self.val + val)
|
||||||
|
|
||||||
|
|
||||||
class aug_test2(aug_test):
|
class aug_test2(aug_test):
|
||||||
def __iadd__(self, val):
|
def __iadd__(self, val):
|
||||||
self.val = self.val + val
|
self.val = self.val + val
|
||||||
return self
|
return self
|
||||||
|
|
||||||
class aug_test3(aug_test):
|
class aug_test3(aug_test):
|
||||||
def __iadd__(self, val):
|
def __iadd__(self, val):
|
||||||
return aug_test3(self.val + val)
|
return aug_test3(self.val + val)
|
||||||
|
|
||||||
x = aug_test(1)
|
x = aug_test(1)
|
||||||
y = x
|
y = x
|
||||||
|
@ -97,93 +96,93 @@ print x.val
|
||||||
|
|
||||||
class testall:
|
class testall:
|
||||||
|
|
||||||
def __add__(self, val):
|
def __add__(self, val):
|
||||||
print "__add__ called"
|
print "__add__ called"
|
||||||
def __radd__(self, val):
|
def __radd__(self, val):
|
||||||
print "__radd__ called"
|
print "__radd__ called"
|
||||||
def __iadd__(self, val):
|
def __iadd__(self, val):
|
||||||
print "__iadd__ called"
|
print "__iadd__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __sub__(self, val):
|
def __sub__(self, val):
|
||||||
print "__sub__ called"
|
print "__sub__ called"
|
||||||
def __rsub__(self, val):
|
def __rsub__(self, val):
|
||||||
print "__rsub__ called"
|
print "__rsub__ called"
|
||||||
def __isub__(self, val):
|
def __isub__(self, val):
|
||||||
print "__isub__ called"
|
print "__isub__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __mul__(self, val):
|
def __mul__(self, val):
|
||||||
print "__mul__ called"
|
print "__mul__ called"
|
||||||
def __rmul__(self, val):
|
def __rmul__(self, val):
|
||||||
print "__rmul__ called"
|
print "__rmul__ called"
|
||||||
def __imul__(self, val):
|
def __imul__(self, val):
|
||||||
print "__imul__ called"
|
print "__imul__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __div__(self, val):
|
def __div__(self, val):
|
||||||
print "__div__ called"
|
print "__div__ called"
|
||||||
def __rdiv__(self, val):
|
def __rdiv__(self, val):
|
||||||
print "__rdiv__ called"
|
print "__rdiv__ called"
|
||||||
def __idiv__(self, val):
|
def __idiv__(self, val):
|
||||||
print "__idiv__ called"
|
print "__idiv__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __mod__(self, val):
|
def __mod__(self, val):
|
||||||
print "__mod__ called"
|
print "__mod__ called"
|
||||||
def __rmod__(self, val):
|
def __rmod__(self, val):
|
||||||
print "__rmod__ called"
|
print "__rmod__ called"
|
||||||
def __imod__(self, val):
|
def __imod__(self, val):
|
||||||
print "__imod__ called"
|
print "__imod__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __pow__(self, val):
|
def __pow__(self, val):
|
||||||
print "__pow__ called"
|
print "__pow__ called"
|
||||||
def __rpow__(self, val):
|
def __rpow__(self, val):
|
||||||
print "__rpow__ called"
|
print "__rpow__ called"
|
||||||
def __ipow__(self, val):
|
def __ipow__(self, val):
|
||||||
print "__ipow__ called"
|
print "__ipow__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __or__(self, val):
|
def __or__(self, val):
|
||||||
print "__or__ called"
|
print "__or__ called"
|
||||||
def __ror__(self, val):
|
def __ror__(self, val):
|
||||||
print "__ror__ called"
|
print "__ror__ called"
|
||||||
def __ior__(self, val):
|
def __ior__(self, val):
|
||||||
print "__ior__ called"
|
print "__ior__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __and__(self, val):
|
def __and__(self, val):
|
||||||
print "__and__ called"
|
print "__and__ called"
|
||||||
def __rand__(self, val):
|
def __rand__(self, val):
|
||||||
print "__rand__ called"
|
print "__rand__ called"
|
||||||
def __iand__(self, val):
|
def __iand__(self, val):
|
||||||
print "__iand__ called"
|
print "__iand__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __xor__(self, val):
|
def __xor__(self, val):
|
||||||
print "__xor__ called"
|
print "__xor__ called"
|
||||||
def __rxor__(self, val):
|
def __rxor__(self, val):
|
||||||
print "__rxor__ called"
|
print "__rxor__ called"
|
||||||
def __ixor__(self, val):
|
def __ixor__(self, val):
|
||||||
print "__ixor__ called"
|
print "__ixor__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __rshift__(self, val):
|
def __rshift__(self, val):
|
||||||
print "__rshift__ called"
|
print "__rshift__ called"
|
||||||
def __rrshift__(self, val):
|
def __rrshift__(self, val):
|
||||||
print "__rrshift__ called"
|
print "__rrshift__ called"
|
||||||
def __irshift__(self, val):
|
def __irshift__(self, val):
|
||||||
print "__irshift__ called"
|
print "__irshift__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __lshift__(self, val):
|
def __lshift__(self, val):
|
||||||
print "__lshift__ called"
|
print "__lshift__ called"
|
||||||
def __rlshift__(self, val):
|
def __rlshift__(self, val):
|
||||||
print "__rlshift__ called"
|
print "__rlshift__ called"
|
||||||
def __ilshift__(self, val):
|
def __ilshift__(self, val):
|
||||||
print "__ilshift__ called"
|
print "__ilshift__ called"
|
||||||
return self
|
return self
|
||||||
|
|
||||||
x = testall()
|
x = testall()
|
||||||
x + 1
|
x + 1
|
||||||
|
@ -229,4 +228,3 @@ x >>= 1
|
||||||
x << 1
|
x << 1
|
||||||
1 << x
|
1 << x
|
||||||
x <<= 1
|
x <<= 1
|
||||||
|
|
||||||
|
|
|
@ -6,35 +6,35 @@ print 'oct'
|
||||||
if oct(100) != '0144': raise TestFailed, 'oct(100)'
|
if oct(100) != '0144': raise TestFailed, 'oct(100)'
|
||||||
if oct(100L) != '0144L': raise TestFailed, 'oct(100L)'
|
if oct(100L) != '0144L': raise TestFailed, 'oct(100L)'
|
||||||
if oct(-100) not in ('037777777634', '01777777777777777777634'):
|
if oct(-100) not in ('037777777634', '01777777777777777777634'):
|
||||||
raise TestFailed, 'oct(-100)'
|
raise TestFailed, 'oct(-100)'
|
||||||
if oct(-100L) != '-0144L': raise TestFailed, 'oct(-100L)'
|
if oct(-100L) != '-0144L': raise TestFailed, 'oct(-100L)'
|
||||||
|
|
||||||
print 'open'
|
print 'open'
|
||||||
# NB the first 4 lines are also used to test input and raw_input, below
|
# NB the first 4 lines are also used to test input and raw_input, below
|
||||||
fp = open(TESTFN, 'w')
|
fp = open(TESTFN, 'w')
|
||||||
try:
|
try:
|
||||||
fp.write('1+1\n')
|
fp.write('1+1\n')
|
||||||
fp.write('1+1\n')
|
fp.write('1+1\n')
|
||||||
fp.write('The quick brown fox jumps over the lazy dog')
|
fp.write('The quick brown fox jumps over the lazy dog')
|
||||||
fp.write('.\n')
|
fp.write('.\n')
|
||||||
fp.write('Dear John\n')
|
fp.write('Dear John\n')
|
||||||
fp.write('XXX'*100)
|
fp.write('XXX'*100)
|
||||||
fp.write('YYY'*100)
|
fp.write('YYY'*100)
|
||||||
finally:
|
finally:
|
||||||
fp.close()
|
fp.close()
|
||||||
#
|
#
|
||||||
fp = open(TESTFN, 'r')
|
fp = open(TESTFN, 'r')
|
||||||
try:
|
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(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':
|
if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n':
|
||||||
raise TestFailed, 'readline() # default'
|
raise TestFailed, 'readline() # default'
|
||||||
if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short'
|
if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short'
|
||||||
if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)'
|
if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)'
|
||||||
if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)'
|
if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)'
|
||||||
if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate'
|
if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate'
|
||||||
finally:
|
finally:
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
print 'ord'
|
print 'ord'
|
||||||
if ord(' ') <> 32: raise TestFailed, '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)'
|
#if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)'
|
||||||
#
|
#
|
||||||
for x in 2, 2L, 2.0:
|
for x in 2, 2L, 2.0:
|
||||||
for y in 10, 10L, 10.0:
|
for y in 10, 10L, 10.0:
|
||||||
for z in 1000, 1000L, 1000.0:
|
for z in 1000, 1000L, 1000.0:
|
||||||
if fcmp(pow(x, y, z), 24.0):
|
if fcmp(pow(x, y, z), 24.0):
|
||||||
raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
|
raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
|
||||||
|
|
||||||
print 'range'
|
print 'range'
|
||||||
if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)'
|
if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)'
|
||||||
|
@ -107,45 +107,45 @@ import sys
|
||||||
fp = open(TESTFN, 'r')
|
fp = open(TESTFN, 'r')
|
||||||
savestdin = sys.stdin
|
savestdin = sys.stdin
|
||||||
try:
|
try:
|
||||||
sys.stdin = fp
|
sys.stdin = fp
|
||||||
if input() <> 2: raise TestFailed, 'input()'
|
if input() <> 2: raise TestFailed, 'input()'
|
||||||
if input('testing\n') <> 2: raise TestFailed, 'input()'
|
if input('testing\n') <> 2: raise TestFailed, 'input()'
|
||||||
if raw_input() <> 'The quick brown fox jumps over the lazy dog.':
|
if raw_input() <> 'The quick brown fox jumps over the lazy dog.':
|
||||||
raise TestFailed, 'raw_input()'
|
raise TestFailed, 'raw_input()'
|
||||||
if raw_input('testing\n') <> 'Dear John':
|
if raw_input('testing\n') <> 'Dear John':
|
||||||
raise TestFailed, 'raw_input(\'testing\\n\')'
|
raise TestFailed, 'raw_input(\'testing\\n\')'
|
||||||
finally:
|
finally:
|
||||||
sys.stdin = savestdin
|
sys.stdin = savestdin
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
print 'reduce'
|
print 'reduce'
|
||||||
if reduce(lambda x, y: x+y, ['a', 'b', 'c'], '') <> 'abc':
|
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,
|
if reduce(lambda x, y: x+y,
|
||||||
[['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']:
|
[['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']:
|
||||||
raise TestFailed, 'reduce(): append'
|
raise TestFailed, 'reduce(): append'
|
||||||
if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040:
|
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:
|
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:
|
class Squares:
|
||||||
def __init__(self, max):
|
def __init__(self, max):
|
||||||
self.max = max
|
self.max = max
|
||||||
self.sofar = []
|
self.sofar = []
|
||||||
def __len__(self): return len(self.sofar)
|
def __len__(self): return len(self.sofar)
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if not 0 <= i < self.max: raise IndexError
|
if not 0 <= i < self.max: raise IndexError
|
||||||
n = len(self.sofar)
|
n = len(self.sofar)
|
||||||
while n <= i:
|
while n <= i:
|
||||||
self.sofar.append(n*n)
|
self.sofar.append(n*n)
|
||||||
n = n+1
|
n = n+1
|
||||||
return self.sofar[i]
|
return self.sofar[i]
|
||||||
if reduce(lambda x, y: x+y, Squares(10)) != 285:
|
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:
|
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:
|
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'
|
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(1.0) <> 1.0: raise TestFailed, 'round(1.0)'
|
||||||
if round(10.0) <> 10.0: raise TestFailed, 'round(10.0)'
|
if round(10.0) <> 10.0: raise TestFailed, 'round(10.0)'
|
||||||
if round(1000000000.0) <> 1000000000.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(1e20) <> 1e20: raise TestFailed, 'round(1e20)'
|
||||||
|
|
||||||
if round(-1.0) <> -1.0: raise TestFailed, 'round(-1.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(-10.0) <> -10.0: raise TestFailed, 'round(-10.0)'
|
||||||
if round(-1000000000.0) <> -1000000000.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(-1e20) <> -1e20: raise TestFailed, 'round(-1e20)'
|
||||||
|
|
||||||
if round(0.1) <> 0.0: raise TestFailed, 'round(0.0)'
|
if round(0.1) <> 0.0: raise TestFailed, 'round(0.0)'
|
||||||
if round(1.1) <> 1.0: raise TestFailed, 'round(1.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(10.1) <> 10.0: raise TestFailed, 'round(10.0)'
|
||||||
if round(1000000000.1) <> 1000000000.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(-1.1) <> -1.0: raise TestFailed, 'round(-1.0)'
|
||||||
if round(-10.1) <> -10.0: raise TestFailed, 'round(-10.0)'
|
if round(-10.1) <> -10.0: raise TestFailed, 'round(-10.0)'
|
||||||
if round(-1000000000.1) <> -1000000000.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(0.9) <> 1.0: raise TestFailed, 'round(0.9)'
|
||||||
if round(9.9) <> 10.0: raise TestFailed, 'round(9.9)'
|
if round(9.9) <> 10.0: raise TestFailed, 'round(9.9)'
|
||||||
if round(999999999.9) <> 1000000000.0:
|
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(-0.9) <> -1.0: raise TestFailed, 'round(-0.9)'
|
||||||
if round(-9.9) <> -10.0: raise TestFailed, 'round(-9.9)'
|
if round(-9.9) <> -10.0: raise TestFailed, 'round(-9.9)'
|
||||||
if round(-999999999.9) <> -1000000000.0:
|
if round(-999999999.9) <> -1000000000.0:
|
||||||
raise TestFailed, 'round(-999999999.9)'
|
raise TestFailed, 'round(-999999999.9)'
|
||||||
|
|
||||||
print 'setattr'
|
print 'setattr'
|
||||||
import sys
|
import sys
|
||||||
|
@ -224,7 +224,7 @@ if tuple('spam') <> ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')"
|
||||||
|
|
||||||
print 'type'
|
print 'type'
|
||||||
if type('') <> type('123') or type('') == type(()):
|
if type('') <> type('123') or type('') == type(()):
|
||||||
raise TestFailed, 'type()'
|
raise TestFailed, 'type()'
|
||||||
|
|
||||||
print 'vars'
|
print 'vars'
|
||||||
a = b = None
|
a = b = None
|
||||||
|
@ -240,20 +240,20 @@ a.sort()
|
||||||
b.sort()
|
b.sort()
|
||||||
if a <> b: raise TestFailed, 'vars(sys)'
|
if a <> b: raise TestFailed, 'vars(sys)'
|
||||||
def f0():
|
def f0():
|
||||||
if vars() != {}: raise TestFailed, 'vars() in f0()'
|
if vars() != {}: raise TestFailed, 'vars() in f0()'
|
||||||
f0()
|
f0()
|
||||||
def f2():
|
def f2():
|
||||||
f0()
|
f0()
|
||||||
a = 1
|
a = 1
|
||||||
b = 2
|
b = 2
|
||||||
if vars() != {'a': a, 'b': b}: raise TestFailed, 'vars() in f2()'
|
if vars() != {'a': a, 'b': b}: raise TestFailed, 'vars() in f2()'
|
||||||
f2()
|
f2()
|
||||||
|
|
||||||
print 'xrange'
|
print 'xrange'
|
||||||
if tuple(xrange(10)) <> tuple(range(10)): raise TestFailed, 'xrange(10)'
|
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(5,10)) <> tuple(range(5,10)): raise TestFailed, 'xrange(5,10)'
|
||||||
if tuple(xrange(0,10,2)) <> tuple(range(0,10,2)):
|
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'
|
print 'zip'
|
||||||
a = (1, 2, 3)
|
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)
|
b = (4, 5, 6, 7)
|
||||||
if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - b is longer'
|
if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - b is longer'
|
||||||
class I:
|
class I:
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if i < 0 or i > 2: raise IndexError
|
if i < 0 or i > 2: raise IndexError
|
||||||
return i + 4
|
return i + 4
|
||||||
if zip(a, I()) <> t: raise TestFailed, 'zip(a, b) - b is instance'
|
if zip(a, I()) <> t: raise TestFailed, 'zip(a, b) - b is instance'
|
||||||
exc = 0
|
exc = 0
|
||||||
try:
|
try:
|
||||||
zip()
|
zip()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
exc = 1
|
exc = 1
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
raise TestFailed, 'zip() - no args, expected TypeError, got %s' % e
|
raise TestFailed, 'zip() - no args, expected TypeError, got %s' % e
|
||||||
if not exc:
|
if not exc:
|
||||||
raise TestFailed, 'zip() - no args, missing expected TypeError'
|
raise TestFailed, 'zip() - no args, missing expected TypeError'
|
||||||
|
|
||||||
exc = 0
|
exc = 0
|
||||||
try:
|
try:
|
||||||
zip(None)
|
zip(None)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
exc = 1
|
exc = 1
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
raise TestFailed, 'zip(None) - expected TypeError, got %s' % e
|
raise TestFailed, 'zip(None) - expected TypeError, got %s' % e
|
||||||
if not exc:
|
if not exc:
|
||||||
raise TestFailed, 'zip(None) - missing expected TypeError'
|
raise TestFailed, 'zip(None) - missing expected TypeError'
|
||||||
class G:
|
class G:
|
||||||
pass
|
pass
|
||||||
exc = 0
|
exc = 0
|
||||||
try:
|
try:
|
||||||
zip(a, G())
|
zip(a, G())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
exc = 1
|
exc = 1
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
raise TestFailed, 'zip(a, b) - b instance w/o __getitem__'
|
raise TestFailed, 'zip(a, b) - b instance w/o __getitem__'
|
||||||
if not exc:
|
if not exc:
|
||||||
raise TestFailed, 'zip(a, b) - missing expected AttributeError'
|
raise TestFailed, 'zip(a, b) - missing expected AttributeError'
|
||||||
|
|
||||||
|
|
||||||
# Epilogue -- unlink the temp file
|
# Epilogue -- unlink the temp file
|
||||||
|
|
|
@ -202,18 +202,17 @@ del testme
|
||||||
# Interfering tests
|
# Interfering tests
|
||||||
|
|
||||||
class ExtraTests:
|
class ExtraTests:
|
||||||
def __getattr__(self, *args):
|
def __getattr__(self, *args):
|
||||||
print "__getattr__:", args
|
print "__getattr__:", args
|
||||||
return "SomeVal"
|
return "SomeVal"
|
||||||
|
|
||||||
def __setattr__(self, *args):
|
def __setattr__(self, *args):
|
||||||
print "__setattr__:", args
|
print "__setattr__:", args
|
||||||
|
|
||||||
def __delattr__(self, *args):
|
def __delattr__(self, *args):
|
||||||
print "__delattr__:", args
|
print "__delattr__:", args
|
||||||
|
|
||||||
testme = ExtraTests()
|
testme = ExtraTests()
|
||||||
testme.spam
|
testme.spam
|
||||||
testme.eggs = "spam, spam, spam and ham"
|
testme.eggs = "spam, spam, spam and ham"
|
||||||
del testme.cardinal
|
del testme.cardinal
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,18 @@ from test_support import TestFailed
|
||||||
|
|
||||||
class base_set:
|
class base_set:
|
||||||
|
|
||||||
def __init__(self, el):
|
def __init__(self, el):
|
||||||
self.el = el
|
self.el = el
|
||||||
|
|
||||||
class set(base_set):
|
class set(base_set):
|
||||||
|
|
||||||
def __contains__(self, el):
|
def __contains__(self, el):
|
||||||
return self.el == el
|
return self.el == el
|
||||||
|
|
||||||
class seq(base_set):
|
class seq(base_set):
|
||||||
|
|
||||||
def __getitem__(self, n):
|
def __getitem__(self, n):
|
||||||
return [self.el][n]
|
return [self.el][n]
|
||||||
|
|
||||||
def check(ok, *args):
|
def check(ok, *args):
|
||||||
if not ok:
|
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)")
|
check(0 not in c, "0 in seq(1)")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
1 in a
|
1 in a
|
||||||
check(0, "in base_set did not raise error")
|
check(0, "in base_set did not raise error")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
1 not in a
|
1 not in a
|
||||||
check(0, "not in base_set did not raise error")
|
check(0, "not in base_set did not raise error")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Test char in string
|
# Test char in string
|
||||||
|
|
||||||
|
@ -46,22 +46,22 @@ check('c' in 'abc', "'c' not in 'abc'")
|
||||||
check('d' not in 'abc', "'d' in 'abc'")
|
check('d' not in 'abc', "'d' in 'abc'")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'' in 'abc'
|
'' in 'abc'
|
||||||
check(0, "'' in 'abc' did not raise error")
|
check(0, "'' in 'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'ab' in 'abc'
|
'ab' in 'abc'
|
||||||
check(0, "'ab' in 'abc' did not raise error")
|
check(0, "'ab' in 'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
None in 'abc'
|
None in 'abc'
|
||||||
check(0, "None in 'abc' did not raise error")
|
check(0, "None in 'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Test char in Unicode
|
# 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'")
|
check('d' not in u'abc', "'d' in u'abc'")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'' in u'abc'
|
'' in u'abc'
|
||||||
check(0, "'' in u'abc' did not raise error")
|
check(0, "'' in u'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'ab' in u'abc'
|
'ab' in u'abc'
|
||||||
check(0, "'ab' in u'abc' did not raise error")
|
check(0, "'ab' in u'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
None in u'abc'
|
None in u'abc'
|
||||||
check(0, "None in u'abc' did not raise error")
|
check(0, "None in u'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Test Unicode char in Unicode
|
# 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'")
|
check(u'd' not in u'abc', "u'd' in u'abc'")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u'' in u'abc'
|
u'' in u'abc'
|
||||||
check(0, "u'' in u'abc' did not raise error")
|
check(0, "u'' in u'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u'ab' in u'abc'
|
u'ab' in u'abc'
|
||||||
check(0, "u'ab' in u'abc' did not raise error")
|
check(0, "u'ab' in u'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Test Unicode char in string
|
# 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'")
|
check(u'd' not in 'abc', "u'd' in 'abc'")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u'' in 'abc'
|
u'' in 'abc'
|
||||||
check(0, "u'' in 'abc' did not raise error")
|
check(0, "u'' in 'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u'ab' in 'abc'
|
u'ab' in 'abc'
|
||||||
check(0, "u'ab' in 'abc' did not raise error")
|
check(0, "u'ab' in 'abc' did not raise error")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# A collection of tests on builtin sequence types
|
# A collection of tests on builtin sequence types
|
||||||
a = range(10)
|
a = range(10)
|
||||||
for i in 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(16 not in a, "16 not in %s" % `a`)
|
||||||
check(a not in a, "%s not in %s" % (`a`, `a`))
|
check(a not in a, "%s not in %s" % (`a`, `a`))
|
||||||
|
|
||||||
a = tuple(a)
|
a = tuple(a)
|
||||||
for i in 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(16 not in a, "16 not in %s" % `a`)
|
||||||
check(a not in a, "%s not in %s" % (`a`, `a`))
|
check(a not in a, "%s not in %s" % (`a`, `a`))
|
||||||
|
|
||||||
class Deviant1:
|
class Deviant1:
|
||||||
"""Behaves strangely when compared
|
"""Behaves strangely when compared
|
||||||
|
|
||||||
This class is designed to make sure that the contains code
|
This class is designed to make sure that the contains code
|
||||||
works when the list is modified during the check.
|
works when the list is modified during the check.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
aList = range(15)
|
aList = range(15)
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
if other == 12:
|
if other == 12:
|
||||||
self.aList.remove(12)
|
self.aList.remove(12)
|
||||||
self.aList.remove(13)
|
self.aList.remove(13)
|
||||||
self.aList.remove(14)
|
self.aList.remove(14)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
check(Deviant1() not in Deviant1.aList, "Deviant1 failed")
|
check(Deviant1() not in Deviant1.aList, "Deviant1 failed")
|
||||||
|
|
||||||
class Deviant2:
|
class Deviant2:
|
||||||
"""Behaves strangely when compared
|
"""Behaves strangely when compared
|
||||||
|
|
||||||
This class raises an exception during comparison. That in
|
This class raises an exception during comparison. That in
|
||||||
turn causes the comparison to fail with a TypeError.
|
turn causes the comparison to fail with a TypeError.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
if other == 4:
|
if other == 4:
|
||||||
raise RuntimeError, "gotcha"
|
raise RuntimeError, "gotcha"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
check(Deviant2() not in a, "oops")
|
check(Deviant2() not in a, "oops")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Simple test suite for Cookie.py
|
# Simple test suite for Cookie.py
|
||||||
|
|
||||||
import Cookie
|
import Cookie
|
||||||
|
@ -37,4 +36,3 @@ C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
|
||||||
assert C['Customer'].value == 'WILE_E_COYOTE'
|
assert C['Customer'].value == 'WILE_E_COYOTE'
|
||||||
assert C['Customer']['version'] == '1'
|
assert C['Customer']['version'] == '1'
|
||||||
assert C['Customer']['path'] == '/acme'
|
assert C['Customer']['path'] == '/acme'
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,16 @@ import os
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
fn = string.replace(fn, "\\", "\\\\")
|
fn = string.replace(fn, "\\", "\\\\")
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
print "error!"
|
print "error!"
|
||||||
print "evaluated: " + str(fn)
|
print "evaluated: " + str(fn)
|
||||||
print "should be: " + str(wantResult)
|
print "should be: " + str(wantResult)
|
||||||
print " returned: " + str(gotResult)
|
print " returned: " + str(gotResult)
|
||||||
print ""
|
print ""
|
||||||
global errors
|
global errors
|
||||||
errors = errors + 1
|
errors = errors + 1
|
||||||
|
|
||||||
tester('dospath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
|
tester('dospath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
|
||||||
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")
|
"/home/swen/spam")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
print str(errors) + " errors."
|
print str(errors) + " errors."
|
||||||
else:
|
else:
|
||||||
print "No errors. Thank your lucky stars."
|
print "No errors. Thank your lucky stars."
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import base64
|
import base64
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
|
||||||
def test_api_1(localedir, mofile):
|
def test_api_1(localedir, mofile):
|
||||||
print 'test api 1'
|
print 'test api 1'
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ gettext message catalog library.''')
|
||||||
print _('mullusk')
|
print _('mullusk')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_api_2(localedir, mofile):
|
def test_api_2(localedir, mofile):
|
||||||
print 'test api 2'
|
print 'test api 2'
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ gettext message catalog library.''')
|
||||||
return gettext.dgettext('gettext')
|
return gettext.dgettext('gettext')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GNU_MO_DATA = '''\
|
GNU_MO_DATA = '''\
|
||||||
3hIElQAAAAAFAAAAHAAAAEQAAAAHAAAAbAAAAAAAAACIAAAAFQAAAIkAAAChAAAAnwAAAAcAAABB
|
3hIElQAAAAAFAAAAHAAAAEQAAAAHAAAAbAAAAAAAAACIAAAAFQAAAIkAAAChAAAAnwAAAAcAAABB
|
||||||
AQAACwAAAEkBAAAbAQAAVQEAABYAAABxAgAAoQAAAIgCAAAFAAAAKgMAAAkAAAAwAwAAAQAAAAQA
|
AQAACwAAAEkBAAAbAQAAVQEAABYAAABxAgAAoQAAAIgCAAAFAAAAKgMAAAkAAAAwAwAAAQAAAAQA
|
||||||
|
@ -123,7 +123,7 @@ bCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1ciBUQUgKdHJnZ3JrZyB6cmZmbnRyIHBuZ255
|
||||||
YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA==
|
YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA==
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
|
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
|
||||||
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
|
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ finally:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# For reference, here's the .po file used to created the .mo data above.
|
# For reference, here's the .po file used to created the .mo data above.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -25,37 +25,37 @@ if 0xff <> 255: raise TestFailed, 'hex int'
|
||||||
if 0377 <> 255: raise TestFailed, 'octal int'
|
if 0377 <> 255: raise TestFailed, 'octal int'
|
||||||
if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
|
if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
|
||||||
try:
|
try:
|
||||||
from sys import maxint
|
from sys import maxint
|
||||||
except ImportError:
|
except ImportError:
|
||||||
maxint = 2147483647
|
maxint = 2147483647
|
||||||
if maxint == 2147483647:
|
if maxint == 2147483647:
|
||||||
if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
|
if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
|
||||||
# XXX -2147483648
|
# XXX -2147483648
|
||||||
if 037777777777 != -1: raise TestFailed, 'oct -1'
|
if 037777777777 != -1: raise TestFailed, 'oct -1'
|
||||||
if 0xffffffff != -1: raise TestFailed, 'hex -1'
|
if 0xffffffff != -1: raise TestFailed, 'hex -1'
|
||||||
for s in '2147483648', '040000000000', '0x100000000':
|
for s in '2147483648', '040000000000', '0x100000000':
|
||||||
try:
|
try:
|
||||||
x = eval(s)
|
x = eval(s)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
continue
|
continue
|
||||||
## raise TestFailed, \
|
## raise TestFailed, \
|
||||||
print \
|
print \
|
||||||
'No OverflowError on huge integer literal ' + `s`
|
'No OverflowError on huge integer literal ' + `s`
|
||||||
elif eval('maxint == 9223372036854775807'):
|
elif eval('maxint == 9223372036854775807'):
|
||||||
if eval('-9223372036854775807-1 != 01000000000000000000000'):
|
if eval('-9223372036854775807-1 != 01000000000000000000000'):
|
||||||
raise TestFailed, 'max negative int'
|
raise TestFailed, 'max negative int'
|
||||||
if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1'
|
if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1'
|
||||||
if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1'
|
if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1'
|
||||||
for s in '9223372036854775808', '02000000000000000000000', \
|
for s in '9223372036854775808', '02000000000000000000000', \
|
||||||
'0x10000000000000000':
|
'0x10000000000000000':
|
||||||
try:
|
try:
|
||||||
x = eval(s)
|
x = eval(s)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
continue
|
continue
|
||||||
raise TestFailed, \
|
raise TestFailed, \
|
||||||
'No OverflowError on huge integer literal ' + `s`
|
'No OverflowError on huge integer literal ' + `s`
|
||||||
else:
|
else:
|
||||||
print 'Weird maxint value', maxint
|
print 'Weird maxint value', maxint
|
||||||
|
|
||||||
print '1.1.2.2 Long integers'
|
print '1.1.2.2 Long integers'
|
||||||
x = 0L
|
x = 0L
|
||||||
|
@ -84,7 +84,7 @@ x = 3.1e4
|
||||||
print '1.1.3 String literals'
|
print '1.1.3 String literals'
|
||||||
|
|
||||||
##def assert(s):
|
##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) == 0 and x == y)
|
||||||
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
||||||
|
@ -146,7 +146,7 @@ print 'funcdef'
|
||||||
### fpdef: NAME | '(' fplist ')'
|
### fpdef: NAME | '(' fplist ')'
|
||||||
### fplist: fpdef (',' fpdef)* [',']
|
### fplist: fpdef (',' fpdef)* [',']
|
||||||
### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
|
### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
|
||||||
### argument: [test '='] test # Really [keyword '='] test
|
### argument: [test '='] test # Really [keyword '='] test
|
||||||
def f1(): pass
|
def f1(): pass
|
||||||
f1()
|
f1()
|
||||||
f1(*())
|
f1(*())
|
||||||
|
@ -270,7 +270,7 @@ print >> sys.stdout, 0 or 1
|
||||||
|
|
||||||
# test printing to an instance
|
# test printing to an instance
|
||||||
class Gulp:
|
class Gulp:
|
||||||
def write(self, msg): pass
|
def write(self, msg): pass
|
||||||
|
|
||||||
gulp = Gulp()
|
gulp = Gulp()
|
||||||
print >> gulp, 1, 2, 3
|
print >> gulp, 1, 2, 3
|
||||||
|
@ -281,34 +281,34 @@ print >> gulp, 0 or 1
|
||||||
|
|
||||||
# test print >> None
|
# test print >> None
|
||||||
def driver():
|
def driver():
|
||||||
oldstdout = sys.stdout
|
oldstdout = sys.stdout
|
||||||
sys.stdout = Gulp()
|
sys.stdout = Gulp()
|
||||||
try:
|
try:
|
||||||
tellme(Gulp())
|
tellme(Gulp())
|
||||||
tellme()
|
tellme()
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = oldstdout
|
sys.stdout = oldstdout
|
||||||
|
|
||||||
# we should see this once
|
# we should see this once
|
||||||
def tellme(file=sys.stdout):
|
def tellme(file=sys.stdout):
|
||||||
print >> file, 'hello world'
|
print >> file, 'hello world'
|
||||||
|
|
||||||
driver()
|
driver()
|
||||||
|
|
||||||
# we should not see this at all
|
# we should not see this at all
|
||||||
def tellme(file=None):
|
def tellme(file=None):
|
||||||
print >> file, 'goodbye universe'
|
print >> file, 'goodbye universe'
|
||||||
|
|
||||||
driver()
|
driver()
|
||||||
|
|
||||||
# syntax errors
|
# syntax errors
|
||||||
def check_syntax(statement):
|
def check_syntax(statement):
|
||||||
try:
|
try:
|
||||||
compile(statement, '<string>', 'exec')
|
compile(statement, '<string>', 'exec')
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print 'Missing SyntaxError: "%s"' % statement
|
print 'Missing SyntaxError: "%s"' % statement
|
||||||
check_syntax('print ,')
|
check_syntax('print ,')
|
||||||
check_syntax('print >> x,')
|
check_syntax('print >> x,')
|
||||||
|
|
||||||
|
@ -350,26 +350,26 @@ from sys import path, argv
|
||||||
|
|
||||||
print 'global_stmt' # 'global' NAME (',' NAME)*
|
print 'global_stmt' # 'global' NAME (',' NAME)*
|
||||||
def f():
|
def f():
|
||||||
global a
|
global a
|
||||||
global a, b
|
global a, b
|
||||||
global one, two, three, four, five, six, seven, eight, nine, ten
|
global one, two, three, four, five, six, seven, eight, nine, ten
|
||||||
|
|
||||||
print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]]
|
print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]]
|
||||||
def f():
|
def f():
|
||||||
z = None
|
z = None
|
||||||
del z
|
del z
|
||||||
exec 'z=1+1\n'
|
exec 'z=1+1\n'
|
||||||
if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n'
|
if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n'
|
||||||
del z
|
del z
|
||||||
exec 'z=1+1'
|
exec 'z=1+1'
|
||||||
if z <> 2: raise TestFailed, 'exec \'z=1+1\''
|
if z <> 2: raise TestFailed, 'exec \'z=1+1\''
|
||||||
z = None
|
z = None
|
||||||
del z
|
del z
|
||||||
exec u'z=1+1\n'
|
exec u'z=1+1\n'
|
||||||
if z <> 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
if z <> 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
||||||
del z
|
del z
|
||||||
exec u'z=1+1'
|
exec u'z=1+1'
|
||||||
if z <> 2: raise TestFailed, 'exec u\'z=1+1\''
|
if z <> 2: raise TestFailed, 'exec u\'z=1+1\''
|
||||||
f()
|
f()
|
||||||
g = {}
|
g = {}
|
||||||
exec 'z = 1' in g
|
exec 'z = 1' in g
|
||||||
|
@ -408,17 +408,17 @@ for i in 1, 2, 3: pass
|
||||||
for i, j, k in (): pass
|
for i, j, k in (): pass
|
||||||
else: pass
|
else: pass
|
||||||
class Squares:
|
class Squares:
|
||||||
def __init__(self, max):
|
def __init__(self, max):
|
||||||
self.max = max
|
self.max = max
|
||||||
self.sofar = []
|
self.sofar = []
|
||||||
def __len__(self): return len(self.sofar)
|
def __len__(self): return len(self.sofar)
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if not 0 <= i < self.max: raise IndexError
|
if not 0 <= i < self.max: raise IndexError
|
||||||
n = len(self.sofar)
|
n = len(self.sofar)
|
||||||
while n <= i:
|
while n <= i:
|
||||||
self.sofar.append(n*n)
|
self.sofar.append(n*n)
|
||||||
n = n+1
|
n = n+1
|
||||||
return self.sofar[i]
|
return self.sofar[i]
|
||||||
n = 0
|
n = 0
|
||||||
for x in Squares(10): n = n+x
|
for x in Squares(10): n = n+x
|
||||||
if n != 285: raise TestFailed, 'for over growing sequence'
|
if n != 285: raise TestFailed, 'for over growing sequence'
|
||||||
|
@ -428,11 +428,11 @@ print 'try_stmt'
|
||||||
### | 'try' ':' suite 'finally' ':' suite
|
### | 'try' ':' suite 'finally' ':' suite
|
||||||
### except_clause: 'except' [expr [',' expr]]
|
### except_clause: 'except' [expr [',' expr]]
|
||||||
try:
|
try:
|
||||||
1/0
|
1/0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
try: 1/0
|
try: 1/0
|
||||||
except EOFError: pass
|
except EOFError: pass
|
||||||
except TypeError, msg: pass
|
except TypeError, msg: pass
|
||||||
|
@ -449,16 +449,16 @@ finally: pass
|
||||||
print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
|
print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
|
||||||
if 1: pass
|
if 1: pass
|
||||||
if 1:
|
if 1:
|
||||||
pass
|
pass
|
||||||
if 1:
|
if 1:
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
#
|
#
|
||||||
pass
|
pass
|
||||||
#
|
#
|
||||||
|
|
||||||
print 'test'
|
print 'test'
|
||||||
### and_test ('or' and_test)*
|
### and_test ('or' and_test)*
|
||||||
|
@ -598,9 +598,9 @@ class C1(B): pass
|
||||||
class C2(B): pass
|
class C2(B): pass
|
||||||
class D(C1, C2, B): pass
|
class D(C1, C2, B): pass
|
||||||
class C:
|
class C:
|
||||||
def meth1(self): pass
|
def meth1(self): pass
|
||||||
def meth2(self, arg): pass
|
def meth2(self, arg): pass
|
||||||
def meth3(self, a1, a2): pass
|
def meth3(self, a1, a2): pass
|
||||||
|
|
||||||
# list comprehension tests
|
# list comprehension tests
|
||||||
nums = [1, 2, 3, 4, 5]
|
nums = [1, 2, 3, 4, 5]
|
||||||
|
@ -622,7 +622,7 @@ try:
|
||||||
eval("[x if y]")
|
eval("[x if y]")
|
||||||
print "FAIL: should have raised a SyntaxError!"
|
print "FAIL: should have raised a SyntaxError!"
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
print "good: got a SyntaxError as expected"
|
print "good: got a SyntaxError as expected"
|
||||||
|
|
||||||
suppliers = [
|
suppliers = [
|
||||||
(1, "Boeing"),
|
(1, "Boeing"),
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
import gzip, tempfile
|
import gzip, tempfile
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@ import test_support
|
||||||
|
|
||||||
|
|
||||||
def same_hash(*objlist):
|
def same_hash(*objlist):
|
||||||
# hash each object given an raise TestFailed if
|
# hash each object given an raise TestFailed if
|
||||||
# the hash values are not all the same
|
# the hash values are not all the same
|
||||||
hashed = map(hash, objlist)
|
hashed = map(hash, objlist)
|
||||||
for h in hashed[1:]:
|
for h in hashed[1:]:
|
||||||
if h != hashed[0]:
|
if h != hashed[0]:
|
||||||
raise TestFailed, "hashed values differ: %s" % `objlist`
|
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(long(1.23e300), float(1.23e300))
|
||||||
|
|
||||||
same_hash(float(0.5), complex(0.5, 0.0))
|
same_hash(float(0.5), complex(0.5, 0.0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ def expect(got_this, expect_this):
|
||||||
# we have to check >4GB) files
|
# we have to check >4GB) files
|
||||||
|
|
||||||
if test_support.verbose:
|
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 = open(name, 'w')
|
||||||
f.seek(size)
|
f.seek(size)
|
||||||
f.write('a')
|
f.write('a')
|
||||||
|
@ -117,16 +117,16 @@ f.close()
|
||||||
# XXX has truncate ever worked on Windows? specifically on WinNT I get:
|
# XXX has truncate ever worked on Windows? specifically on WinNT I get:
|
||||||
# "IOError: [Errno 13] Permission denied"
|
# "IOError: [Errno 13] Permission denied"
|
||||||
##try:
|
##try:
|
||||||
## newsize = size - 10
|
## newsize = size - 10
|
||||||
## f.seek(newsize)
|
## f.seek(newsize)
|
||||||
## f.truncate()
|
## f.truncate()
|
||||||
## expect(f.tell(), newsize)
|
## expect(f.tell(), newsize)
|
||||||
## newsize = newsize - 1
|
## newsize = newsize - 1
|
||||||
## f.seek(0)
|
## f.seek(0)
|
||||||
## f.truncate(newsize)
|
## f.truncate(newsize)
|
||||||
## expect(f.tell(), newsize)
|
## expect(f.tell(), newsize)
|
||||||
##except AttributeError:
|
##except AttributeError:
|
||||||
## pass
|
## pass
|
||||||
|
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
print >>sys.stderr, name, "exists:", os.path.exists(name)
|
print >>sys.stderr, name, "exists:", os.path.exists(name)
|
||||||
|
|
|
@ -257,4 +257,3 @@ test_division()
|
||||||
test_bitop_identities()
|
test_bitop_identities()
|
||||||
test_format()
|
test_format()
|
||||||
test_misc()
|
test_misc()
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ print 'math module, testing with eps', seps
|
||||||
import math
|
import math
|
||||||
|
|
||||||
def testit(name, value, expected):
|
def testit(name, value, expected):
|
||||||
if abs(value-expected) > eps:
|
if abs(value-expected) > eps:
|
||||||
raise TestFailed, '%s returned %f, expected %f'%\
|
raise TestFailed, '%s returned %f, expected %f'%\
|
||||||
(name, value, expected)
|
(name, value, expected)
|
||||||
|
|
||||||
print 'constants'
|
print 'constants'
|
||||||
testit('pi', math.pi, 3.1415926)
|
testit('pi', math.pi, 3.1415926)
|
||||||
|
@ -85,9 +85,9 @@ testit('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
|
||||||
|
|
||||||
print 'frexp'
|
print 'frexp'
|
||||||
def testfrexp(name, (mant, exp), (emant, eexp)):
|
def testfrexp(name, (mant, exp), (emant, eexp)):
|
||||||
if abs(mant-emant) > eps or exp <> eexp:
|
if abs(mant-emant) > eps or exp <> eexp:
|
||||||
raise TestFailed, '%s returned %s, expected %s'%\
|
raise TestFailed, '%s returned %s, expected %s'%\
|
||||||
(name, `mant, exp`, `emant,eexp`)
|
(name, `mant, exp`, `emant,eexp`)
|
||||||
|
|
||||||
testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
|
testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
|
||||||
testfrexp('frexp(0)', math.frexp(0), (0, 0))
|
testfrexp('frexp(0)', math.frexp(0), (0, 0))
|
||||||
|
@ -116,9 +116,9 @@ testit('log10(10)', math.log10(10), 1)
|
||||||
|
|
||||||
print 'modf'
|
print 'modf'
|
||||||
def testmodf(name, (v1, v2), (e1, e2)):
|
def testmodf(name, (v1, v2), (e1, e2)):
|
||||||
if abs(v1-e1) > eps or abs(v2-e2):
|
if abs(v1-e1) > eps or abs(v2-e2):
|
||||||
raise TestFailed, '%s returned %s, expected %s'%\
|
raise TestFailed, '%s returned %s, expected %s'%\
|
||||||
(name, `v1,v2`, `e1,e2`)
|
(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))
|
||||||
testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
|
testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
|
||||||
|
|
|
@ -4,15 +4,15 @@ import string
|
||||||
from md5 import md5
|
from md5 import md5
|
||||||
|
|
||||||
def hexstr(s):
|
def hexstr(s):
|
||||||
h = string.hexdigits
|
h = string.hexdigits
|
||||||
r = ''
|
r = ''
|
||||||
for c in s:
|
for c in s:
|
||||||
i = ord(c)
|
i = ord(c)
|
||||||
r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
|
r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def md5test(s):
|
def md5test(s):
|
||||||
return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest())
|
return 'MD5 ("' + s + '") = ' + hexstr(md5(s).digest())
|
||||||
|
|
||||||
print 'MD5 test suite:'
|
print 'MD5 test suite:'
|
||||||
print md5test('')
|
print md5test('')
|
||||||
|
@ -27,4 +27,4 @@ print md5test('12345678901234567890123456789012345678901234567890123456789012345
|
||||||
m = md5('testing the hexdigest method')
|
m = md5('testing the hexdigest method')
|
||||||
h = m.hexdigest()
|
h = m.hexdigest()
|
||||||
if hexstr(m.digest()) <> h:
|
if hexstr(m.digest()) <> h:
|
||||||
print 'hexdigest() failed'
|
print 'hexdigest() failed'
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import mmap
|
import mmap
|
||||||
import string, os, re, sys
|
import string, os, re, sys
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,16 @@ import os
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
fn = string.replace(fn, "\\", "\\\\")
|
fn = string.replace(fn, "\\", "\\\\")
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
print "error!"
|
print "error!"
|
||||||
print "evaluated: " + str(fn)
|
print "evaluated: " + str(fn)
|
||||||
print "should be: " + str(wantResult)
|
print "should be: " + str(wantResult)
|
||||||
print " returned: " + str(gotResult)
|
print " returned: " + str(gotResult)
|
||||||
print ""
|
print ""
|
||||||
global errors
|
global errors
|
||||||
errors = errors + 1
|
errors = errors + 1
|
||||||
|
|
||||||
tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
|
tester('ntpath.splitdrive("c:\\foo\\bar")', ('c:', '\\foo\\bar'))
|
||||||
tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")', ('\\\\conky\\mountpoint', '\\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")
|
"/home/swen/spam")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
print str(errors) + " errors."
|
print str(errors) + " errors."
|
||||||
else:
|
else:
|
||||||
print "No errors. Thank your lucky stars."
|
print "No errors. Thank your lucky stars."
|
||||||
|
|
||||||
|
|
|
@ -9,18 +9,18 @@ print 'XXX Not yet fully implemented'
|
||||||
print '2.1 try inside for loop'
|
print '2.1 try inside for loop'
|
||||||
n = 0
|
n = 0
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
n = n+i
|
n = n+i
|
||||||
try: 1/0
|
try: 1/0
|
||||||
except NameError: pass
|
except NameError: pass
|
||||||
except ZeroDivisionError: pass
|
except ZeroDivisionError: pass
|
||||||
except TypeError: pass
|
except TypeError: pass
|
||||||
try: pass
|
try: pass
|
||||||
except: pass
|
except: pass
|
||||||
try: pass
|
try: pass
|
||||||
finally: pass
|
finally: pass
|
||||||
n = n+i
|
n = n+i
|
||||||
if n <> 90:
|
if n <> 90:
|
||||||
raise TestFailed, 'try inside for'
|
raise TestFailed, 'try inside for'
|
||||||
|
|
||||||
|
|
||||||
print '2.2 raise class exceptions'
|
print '2.2 raise class exceptions'
|
||||||
|
@ -50,12 +50,12 @@ b = BClass()
|
||||||
|
|
||||||
try: raise AClass, b
|
try: raise AClass, b
|
||||||
except BClass, v:
|
except BClass, v:
|
||||||
if v != b: raise TestFailed
|
if v != b: raise TestFailed
|
||||||
else: raise TestFailed
|
else: raise TestFailed
|
||||||
|
|
||||||
try: raise b
|
try: raise b
|
||||||
except AClass, v:
|
except AClass, v:
|
||||||
if v != b: raise TestFailed
|
if v != b: raise TestFailed
|
||||||
|
|
||||||
# not enough arguments
|
# not enough arguments
|
||||||
try: raise BClass, a
|
try: raise BClass, a
|
||||||
|
|
|
@ -19,4 +19,3 @@ if not os.isatty(slave):
|
||||||
|
|
||||||
os.write(slave, 'Ping!')
|
os.write(slave, 'Ping!')
|
||||||
print os.read(master, 1024)
|
print os.read(master, 1024)
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@ import string
|
||||||
errors = 0
|
errors = 0
|
||||||
|
|
||||||
def tester(fn, wantResult):
|
def tester(fn, wantResult):
|
||||||
gotResult = eval(fn)
|
gotResult = eval(fn)
|
||||||
if wantResult != gotResult:
|
if wantResult != gotResult:
|
||||||
print "error!"
|
print "error!"
|
||||||
print "evaluated: " + str(fn)
|
print "evaluated: " + str(fn)
|
||||||
print "should be: " + str(wantResult)
|
print "should be: " + str(wantResult)
|
||||||
print " returned: " + str(gotResult)
|
print " returned: " + str(gotResult)
|
||||||
print ""
|
print ""
|
||||||
global errors
|
global errors
|
||||||
errors = errors + 1
|
errors = errors + 1
|
||||||
|
|
||||||
tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar'))
|
tester('posixpath.splitdrive("/foo/bar")', ('', '/foo/bar'))
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
|
||||||
"/home/swen/spam")
|
"/home/swen/spam")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
print str(errors) + " errors."
|
print str(errors) + " errors."
|
||||||
else:
|
else:
|
||||||
print "No errors. Thank your lucky stars."
|
print "No errors. Thank your lucky stars."
|
||||||
|
|
||||||
|
|
|
@ -62,13 +62,13 @@ def powtest(type):
|
||||||
elif type == long:
|
elif type == long:
|
||||||
jl, jh = 0, 15
|
jl, jh = 0, 15
|
||||||
for i in range(il, ih+1):
|
for i in range(il, ih+1):
|
||||||
for j in range(jl, jh+1):
|
for j in range(jl, jh+1):
|
||||||
for k in range(kl, kh+1):
|
for k in range(kl, kh+1):
|
||||||
if k != 0:
|
if k != 0:
|
||||||
if compare(pow(type(i),j,k), pow(type(i),j)% type(k)):
|
if compare(pow(type(i),j,k), pow(type(i),j)% type(k)):
|
||||||
raise ValueError, "pow(" +str(i)+ "," +str(j)+ \
|
raise ValueError, "pow(" +str(i)+ "," +str(j)+ \
|
||||||
"," +str(k)+ ") != pow(" +str(i)+ "," + \
|
"," +str(k)+ ") != pow(" +str(i)+ "," + \
|
||||||
str(j)+ ") % " +str(k)
|
str(j)+ ") % " +str(k)
|
||||||
|
|
||||||
|
|
||||||
print 'Testing integer mode...'
|
print 'Testing integer mode...'
|
||||||
|
@ -104,17 +104,17 @@ print pow(5.0,2) % -8, pow(5.0,2,-8)
|
||||||
print
|
print
|
||||||
|
|
||||||
for i in range(-10, 11):
|
for i in range(-10, 11):
|
||||||
for j in range(0, 6):
|
for j in range(0, 6):
|
||||||
for k in range(-7, 11):
|
for k in range(-7, 11):
|
||||||
if j >= 0 and k != 0:
|
if j >= 0 and k != 0:
|
||||||
o = pow(i,j) % k
|
o = pow(i,j) % k
|
||||||
n = pow(i,j,k)
|
n = pow(i,j,k)
|
||||||
if o != n: print 'Integer mismatch:', i,j,k
|
if o != n: print 'Integer mismatch:', i,j,k
|
||||||
if j >= 0 and k <> 0:
|
if j >= 0 and k <> 0:
|
||||||
o = pow(long(i),j) % k
|
o = pow(long(i),j) % k
|
||||||
n = pow(long(i),j,k)
|
n = pow(long(i),j,k)
|
||||||
if o != n: print 'Long mismatch:', i,j,k
|
if o != n: print 'Long mismatch:', i,j,k
|
||||||
if i >= 0 and k <> 0:
|
if i >= 0 and k <> 0:
|
||||||
o = pow(float(i),j) % k
|
o = pow(float(i),j) % k
|
||||||
n = pow(float(i),j,k)
|
n = pow(float(i),j,k)
|
||||||
if o != n: print 'Float mismatch:', i,j,k
|
if o != n: print 'Float mismatch:', i,j,k
|
||||||
|
|
|
@ -88,4 +88,3 @@ else:
|
||||||
os.close(master_fd)
|
os.close(master_fd)
|
||||||
|
|
||||||
# pty.fork() passed.
|
# pty.fork() passed.
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ for t in tests:
|
||||||
# string), so we'll ignore patterns that feature it.
|
# string), so we'll ignore patterns that feature it.
|
||||||
|
|
||||||
if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \
|
if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \
|
||||||
and result != None:
|
and result != None:
|
||||||
obj = re.compile(pattern)
|
obj = re.compile(pattern)
|
||||||
result = obj.search(s, result.start(0), result.end(0) + 1)
|
result = obj.search(s, result.start(0), result.end(0) + 1)
|
||||||
if result == None:
|
if result == None:
|
||||||
|
|
|
@ -5,24 +5,24 @@ import rgbimg, os, uu
|
||||||
from test_support import verbose, unlink, findfile
|
from test_support import verbose, unlink, findfile
|
||||||
|
|
||||||
class error(Exception):
|
class error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print 'RGBimg test suite:'
|
print 'RGBimg test suite:'
|
||||||
|
|
||||||
def testimg(rgb_file, raw_file):
|
def testimg(rgb_file, raw_file):
|
||||||
rgb_file = findfile(rgb_file)
|
rgb_file = findfile(rgb_file)
|
||||||
raw_file = findfile(raw_file)
|
raw_file = findfile(raw_file)
|
||||||
width, height = rgbimg.sizeofimage(rgb_file)
|
width, height = rgbimg.sizeofimage(rgb_file)
|
||||||
rgb = rgbimg.longimagedata(rgb_file)
|
rgb = rgbimg.longimagedata(rgb_file)
|
||||||
if len(rgb) != width * height * 4:
|
if len(rgb) != width * height * 4:
|
||||||
raise error, 'bad image length'
|
raise error, 'bad image length'
|
||||||
raw = open(raw_file, 'rb').read()
|
raw = open(raw_file, 'rb').read()
|
||||||
if rgb != raw:
|
if rgb != raw:
|
||||||
raise error, \
|
raise error, \
|
||||||
'images don\'t match for '+rgb_file+' and '+raw_file
|
'images don\'t match for '+rgb_file+' and '+raw_file
|
||||||
for depth in [1, 3, 4]:
|
for depth in [1, 3, 4]:
|
||||||
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
||||||
os.unlink('@.rgb')
|
os.unlink('@.rgb')
|
||||||
|
|
||||||
table = [
|
table = [
|
||||||
('testrgb.uue', 'test.rgb'),
|
('testrgb.uue', 'test.rgb'),
|
||||||
|
@ -41,23 +41,23 @@ if verbose:
|
||||||
|
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if 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')
|
testimg('test.rgb', 'test.rawimg')
|
||||||
|
|
||||||
ttob = rgbimg.ttob(1)
|
ttob = rgbimg.ttob(1)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should be zero'
|
raise error, 'ttob should be zero'
|
||||||
|
|
||||||
testimg('test.rgb', 'test.rawimg.rev')
|
testimg('test.rgb', 'test.rawimg.rev')
|
||||||
|
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 1:
|
if ttob != 1:
|
||||||
raise error, 'ttob should be one'
|
raise error, 'ttob should be one'
|
||||||
|
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should be zero'
|
raise error, 'ttob should be zero'
|
||||||
|
|
||||||
for source, target in table:
|
for source, target in table:
|
||||||
unlink(findfile(target))
|
unlink(findfile(target))
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# regression test for SAX 2.0
|
# regression test for SAX 2.0
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
|
|
@ -34,30 +34,29 @@ else:
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
import sys
|
import sys
|
||||||
if sys.platform[:3] in ('win', 'mac', 'os2'):
|
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:
|
if verbose:
|
||||||
print "Can't test select easily on", sys.platform
|
print 'EOF'
|
||||||
return
|
break
|
||||||
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
|
continue
|
||||||
p = os.popen(cmd, 'r')
|
print 'Unexpected return values from select():', rfd, wfd, xfd
|
||||||
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
|
p.close()
|
||||||
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()
|
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
|
||||||
|
|
|
@ -8,36 +8,36 @@ if sys.platform[:3] in ('win', 'os2'):
|
||||||
raise TestSkipped, "Can't test signal on %s" % sys.platform[:3]
|
raise TestSkipped, "Can't test signal on %s" % sys.platform[:3]
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
x = '-x'
|
x = '-x'
|
||||||
else:
|
else:
|
||||||
x = '+x'
|
x = '+x'
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
|
||||||
# Shell script that will send us asynchronous signals
|
# Shell script that will send us asynchronous signals
|
||||||
script = """
|
script = """
|
||||||
(
|
(
|
||||||
set %(x)s
|
set %(x)s
|
||||||
sleep 2
|
sleep 2
|
||||||
kill -5 %(pid)d
|
kill -5 %(pid)d
|
||||||
sleep 2
|
sleep 2
|
||||||
kill -2 %(pid)d
|
kill -2 %(pid)d
|
||||||
sleep 2
|
sleep 2
|
||||||
kill -3 %(pid)d
|
kill -3 %(pid)d
|
||||||
) &
|
) &
|
||||||
""" % vars()
|
""" % vars()
|
||||||
|
|
||||||
def handlerA(*args):
|
def handlerA(*args):
|
||||||
if verbose:
|
if verbose:
|
||||||
print "handlerA", args
|
print "handlerA", args
|
||||||
|
|
||||||
HandlerBCalled = "HandlerBCalled" # Exception
|
HandlerBCalled = "HandlerBCalled" # Exception
|
||||||
|
|
||||||
def handlerB(*args):
|
def handlerB(*args):
|
||||||
if verbose:
|
if verbose:
|
||||||
print "handlerB", args
|
print "handlerB", args
|
||||||
raise HandlerBCalled, 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(5, handlerA)
|
||||||
signal.signal(2, handlerB)
|
signal.signal(2, handlerB)
|
||||||
signal.signal(3, signal.SIG_IGN)
|
signal.signal(3, signal.SIG_IGN)
|
||||||
|
@ -48,19 +48,19 @@ os.system(script)
|
||||||
print "starting pause() loop..."
|
print "starting pause() loop..."
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
if verbose:
|
if verbose:
|
||||||
print "call pause()..."
|
print "call pause()..."
|
||||||
try:
|
try:
|
||||||
signal.pause()
|
signal.pause()
|
||||||
if verbose:
|
if verbose:
|
||||||
print "pause() returned"
|
print "pause() returned"
|
||||||
except HandlerBCalled:
|
except HandlerBCalled:
|
||||||
if verbose:
|
if verbose:
|
||||||
print "HandlerBCalled exception caught"
|
print "HandlerBCalled exception caught"
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if verbose:
|
if verbose:
|
||||||
print "KeyboardInterrupt (assume the alarm() went off)"
|
print "KeyboardInterrupt (assume the alarm() went off)"
|
||||||
|
|
|
@ -20,7 +20,7 @@ def test(name, input, output, *args):
|
||||||
f = getattr(string, name)
|
f = getattr(string, name)
|
||||||
value = apply(f, (input,) + args)
|
value = apply(f, (input,) + args)
|
||||||
except:
|
except:
|
||||||
value = sys.exc_type
|
value = sys.exc_type
|
||||||
if value != output:
|
if value != output:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'no'
|
print 'no'
|
||||||
|
@ -35,4 +35,3 @@ string_tests.run_method_tests(test)
|
||||||
string.whitespace
|
string.whitespace
|
||||||
string.lowercase
|
string.lowercase
|
||||||
string.uppercase
|
string.uppercase
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ def test(name, input, output, *args):
|
||||||
try:
|
try:
|
||||||
value = apply(f, (input,) + args)
|
value = apply(f, (input,) + args)
|
||||||
except:
|
except:
|
||||||
value = sys.exc_type
|
value = sys.exc_type
|
||||||
if value != output:
|
if value != output:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'no'
|
print 'no'
|
||||||
|
|
|
@ -2,72 +2,72 @@
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Base class for regression test exceptions."""
|
"""Base class for regression test exceptions."""
|
||||||
|
|
||||||
class TestFailed(Error):
|
class TestFailed(Error):
|
||||||
"""Test failed."""
|
"""Test failed."""
|
||||||
|
|
||||||
class TestSkipped(Error):
|
class TestSkipped(Error):
|
||||||
"""Test skipped.
|
"""Test skipped.
|
||||||
|
|
||||||
This can be raised to indicate that a test was deliberatly
|
This can be raised to indicate that a test was deliberatly
|
||||||
skipped, but not because a feature wasn't available. For
|
skipped, but not because a feature wasn't available. For
|
||||||
example, if some resource can't be used, such as the network
|
example, if some resource can't be used, such as the network
|
||||||
appears to be unavailable, this should be raised instead of
|
appears to be unavailable, this should be raised instead of
|
||||||
TestFailed.
|
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
|
use_large_resources = 1 # Flag set to 0 by regrtest.py
|
||||||
|
|
||||||
def unload(name):
|
def unload(name):
|
||||||
import sys
|
import sys
|
||||||
try:
|
try:
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def forget(modname):
|
def forget(modname):
|
||||||
unload(modname)
|
unload(modname)
|
||||||
import sys, os
|
import sys, os
|
||||||
for dirname in sys.path:
|
for dirname in sys.path:
|
||||||
try:
|
try:
|
||||||
os.unlink(os.path.join(dirname, modname + '.pyc'))
|
os.unlink(os.path.join(dirname, modname + '.pyc'))
|
||||||
except os.error:
|
except os.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
FUZZ = 1e-6
|
FUZZ = 1e-6
|
||||||
|
|
||||||
def fcmp(x, y): # fuzzy comparison function
|
def fcmp(x, y): # fuzzy comparison function
|
||||||
if type(x) == type(0.0) or type(y) == type(0.0):
|
if type(x) == type(0.0) or type(y) == type(0.0):
|
||||||
try:
|
try:
|
||||||
x, y = coerce(x, y)
|
x, y = coerce(x, y)
|
||||||
fuzz = (abs(x) + abs(y)) * FUZZ
|
fuzz = (abs(x) + abs(y)) * FUZZ
|
||||||
if abs(x-y) <= fuzz:
|
if abs(x-y) <= fuzz:
|
||||||
return 0
|
return 0
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
elif type(x) == type(y) and type(x) in (type(()), type([])):
|
elif type(x) == type(y) and type(x) in (type(()), type([])):
|
||||||
for i in range(min(len(x), len(y))):
|
for i in range(min(len(x), len(y))):
|
||||||
outcome = fcmp(x[i], y[i])
|
outcome = fcmp(x[i], y[i])
|
||||||
if outcome <> 0:
|
if outcome <> 0:
|
||||||
return outcome
|
return outcome
|
||||||
return cmp(len(x), len(y))
|
return cmp(len(x), len(y))
|
||||||
return cmp(x, y)
|
return cmp(x, y)
|
||||||
|
|
||||||
TESTFN = '@test' # Filename used for testing
|
TESTFN = '@test' # Filename used for testing
|
||||||
from os import unlink
|
from os import unlink
|
||||||
|
|
||||||
def findfile(file, here=__file__):
|
def findfile(file, here=__file__):
|
||||||
import os
|
import os
|
||||||
if os.path.isabs(file):
|
if os.path.isabs(file):
|
||||||
return file
|
return file
|
||||||
import sys
|
import sys
|
||||||
path = sys.path
|
path = sys.path
|
||||||
path = [os.path.dirname(here)] + path
|
path = [os.path.dirname(here)] + path
|
||||||
for dn in path:
|
for dn in path:
|
||||||
fn = os.path.join(dn, file)
|
fn = os.path.join(dn, file)
|
||||||
if os.path.exists(fn): return fn
|
if os.path.exists(fn): return fn
|
||||||
return file
|
return file
|
||||||
|
|
|
@ -16,98 +16,98 @@ done.acquire()
|
||||||
numtasks = 10
|
numtasks = 10
|
||||||
|
|
||||||
def task(ident):
|
def task(ident):
|
||||||
global running
|
global running
|
||||||
rmutex.acquire()
|
rmutex.acquire()
|
||||||
delay = random.random() * numtasks
|
delay = random.random() * numtasks
|
||||||
rmutex.release()
|
rmutex.release()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'task', ident, 'done'
|
print 'task', ident, 'done'
|
||||||
mutex.acquire()
|
mutex.acquire()
|
||||||
running = running - 1
|
running = running - 1
|
||||||
if running == 0:
|
if running == 0:
|
||||||
done.release()
|
done.release()
|
||||||
mutex.release()
|
mutex.release()
|
||||||
|
|
||||||
next_ident = 0
|
next_ident = 0
|
||||||
def newtask():
|
def newtask():
|
||||||
global next_ident, running
|
global next_ident, running
|
||||||
mutex.acquire()
|
mutex.acquire()
|
||||||
next_ident = next_ident + 1
|
next_ident = next_ident + 1
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'creating task', next_ident
|
print 'creating task', next_ident
|
||||||
thread.start_new_thread(task, (next_ident,))
|
thread.start_new_thread(task, (next_ident,))
|
||||||
running = running + 1
|
running = running + 1
|
||||||
mutex.release()
|
mutex.release()
|
||||||
|
|
||||||
for i in range(numtasks):
|
for i in range(numtasks):
|
||||||
newtask()
|
newtask()
|
||||||
|
|
||||||
print 'waiting for all tasks to complete'
|
print 'waiting for all tasks to complete'
|
||||||
done.acquire()
|
done.acquire()
|
||||||
print 'all tasks done'
|
print 'all tasks done'
|
||||||
|
|
||||||
class barrier:
|
class barrier:
|
||||||
def __init__(self, n):
|
def __init__(self, n):
|
||||||
self.n = n
|
self.n = n
|
||||||
self.waiting = 0
|
self.waiting = 0
|
||||||
self.checkin = thread.allocate_lock()
|
self.checkin = thread.allocate_lock()
|
||||||
self.checkout = thread.allocate_lock()
|
self.checkout = thread.allocate_lock()
|
||||||
self.checkout.acquire()
|
self.checkout.acquire()
|
||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
checkin, checkout = self.checkin, self.checkout
|
checkin, checkout = self.checkin, self.checkout
|
||||||
|
|
||||||
checkin.acquire()
|
checkin.acquire()
|
||||||
self.waiting = self.waiting + 1
|
self.waiting = self.waiting + 1
|
||||||
if self.waiting == self.n:
|
if self.waiting == self.n:
|
||||||
self.waiting = self.n - 1
|
self.waiting = self.n - 1
|
||||||
checkout.release()
|
checkout.release()
|
||||||
return
|
return
|
||||||
checkin.release()
|
checkin.release()
|
||||||
|
|
||||||
checkout.acquire()
|
checkout.acquire()
|
||||||
self.waiting = self.waiting - 1
|
self.waiting = self.waiting - 1
|
||||||
if self.waiting == 0:
|
if self.waiting == 0:
|
||||||
checkin.release()
|
checkin.release()
|
||||||
return
|
return
|
||||||
checkout.release()
|
checkout.release()
|
||||||
|
|
||||||
numtrips = 3
|
numtrips = 3
|
||||||
def task2(ident):
|
def task2(ident):
|
||||||
global running
|
global running
|
||||||
for i in range(numtrips):
|
for i in range(numtrips):
|
||||||
if ident == 0:
|
if ident == 0:
|
||||||
# give it a good chance to enter the next
|
# give it a good chance to enter the next
|
||||||
# barrier before the others are all out
|
# barrier before the others are all out
|
||||||
# of the current one
|
# of the current one
|
||||||
delay = 0.001
|
delay = 0.001
|
||||||
else:
|
else:
|
||||||
rmutex.acquire()
|
rmutex.acquire()
|
||||||
delay = random.random() * numtasks
|
delay = random.random() * numtasks
|
||||||
rmutex.release()
|
rmutex.release()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
print 'task', ident, 'will run for', round(delay, 1), 'sec'
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'task', ident, 'entering barrier', i
|
print 'task', ident, 'entering barrier', i
|
||||||
bar.enter()
|
bar.enter()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'task', ident, 'leaving barrier', i
|
print 'task', ident, 'leaving barrier', i
|
||||||
mutex.acquire()
|
mutex.acquire()
|
||||||
running = running - 1
|
running = running - 1
|
||||||
if running == 0:
|
if running == 0:
|
||||||
done.release()
|
done.release()
|
||||||
mutex.release()
|
mutex.release()
|
||||||
|
|
||||||
print '\n*** Barrier Test ***'
|
print '\n*** Barrier Test ***'
|
||||||
if done.acquire(0):
|
if done.acquire(0):
|
||||||
raise ValueError, "'done' should have remained acquired"
|
raise ValueError, "'done' should have remained acquired"
|
||||||
bar = barrier(numtasks)
|
bar = barrier(numtasks)
|
||||||
running = numtasks
|
running = numtasks
|
||||||
for i in range(numtasks):
|
for i in range(numtasks):
|
||||||
thread.start_new_thread(task2, (i,))
|
thread.start_new_thread(task2, (i,))
|
||||||
done.acquire()
|
done.acquire()
|
||||||
print 'all tasks done'
|
print 'all tasks done'
|
||||||
|
|
|
@ -7,4 +7,3 @@ file = open(findfile('tokenize_tests.py'))
|
||||||
tokenize.tokenize(file.readline)
|
tokenize.tokenize(file.readline)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'finished'
|
print 'finished'
|
||||||
|
|
||||||
|
|
|
@ -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 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, 'mixed comparisons'
|
||||||
if -1 <> -1L or -1 <> -1.0 or -1L <> -1.0:
|
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
|
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'
|
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
|
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
|
# Test for a particular bug in integer multiply
|
||||||
xsize, ysize, zsize = 238, 356, 4
|
xsize, ysize, zsize = 238, 356, 4
|
||||||
if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
|
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'
|
print '6.4.2 Long integers'
|
||||||
if 12L + 24L <> 36L: raise TestFailed, 'long op'
|
if 12L + 24L <> 36L: raise TestFailed, 'long op'
|
||||||
if 12L + (-24L) <> -12L: 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, 2, 3, 4, 5]
|
||||||
a[:-1] = a
|
a[:-1] = a
|
||||||
if a != [1, 2, 3, 4, 5, 5]:
|
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, 2, 3, 4, 5]
|
||||||
a[1:] = a
|
a[1:] = a
|
||||||
if a != [1, 1, 2, 3, 4, 5]:
|
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, 2, 3, 4, 5]
|
||||||
a[1:-1] = a
|
a[1:-1] = a
|
||||||
if a != [1, 1, 2, 3, 4, 5, 5]:
|
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'
|
print '6.5.3a Additional list operations'
|
||||||
|
@ -213,9 +213,9 @@ z.sort(myComparison)
|
||||||
# Test extreme cases with long ints
|
# Test extreme cases with long ints
|
||||||
a = [0,1,2,3,4]
|
a = [0,1,2,3,4]
|
||||||
if a[ -pow(2,128L): 3 ] != [0,1,2]:
|
if a[ -pow(2,128L): 3 ] != [0,1,2]:
|
||||||
raise TestFailed, "list slicing with too-small long integer"
|
raise TestFailed, "list slicing with too-small long integer"
|
||||||
if a[ 3: pow(2,145L) ] != [3,4]:
|
if a[ 3: pow(2,145L) ] != [3,4]:
|
||||||
raise TestFailed, "list slicing with too-large long integer"
|
raise TestFailed, "list slicing with too-large long integer"
|
||||||
|
|
||||||
print '6.6 Mappings == Dictionaries'
|
print '6.6 Mappings == Dictionaries'
|
||||||
d = {}
|
d = {}
|
||||||
|
@ -256,12 +256,12 @@ if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg'
|
||||||
# dict.setdefault()
|
# dict.setdefault()
|
||||||
d = {}
|
d = {}
|
||||||
if d.setdefault('key0') <> None:
|
if d.setdefault('key0') <> None:
|
||||||
raise TestFailed, 'missing {} setdefault, no 2nd arg'
|
raise TestFailed, 'missing {} setdefault, no 2nd arg'
|
||||||
if d.setdefault('key0') <> None:
|
if d.setdefault('key0') <> None:
|
||||||
raise TestFailed, 'present {} setdefault, no 2nd arg'
|
raise TestFailed, 'present {} setdefault, no 2nd arg'
|
||||||
d.setdefault('key', []).append(3)
|
d.setdefault('key', []).append(3)
|
||||||
if d['key'][0] <> 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)
|
d.setdefault('key', []).append(4)
|
||||||
if len(d['key']) <> 2:
|
if len(d['key']) <> 2:
|
||||||
raise TestFailed, 'present {} setdefault, w/ 2nd arg'
|
raise TestFailed, 'present {} setdefault, w/ 2nd arg'
|
||||||
|
|
|
@ -52,31 +52,30 @@ k_cchMaxUnicodeName = 83
|
||||||
|
|
||||||
s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}"
|
s = "\N{" + "1" * (k_cchMaxUnicodeName + 2) + "}"
|
||||||
try:
|
try:
|
||||||
unicode(s, 'unicode-escape', 'strict')
|
unicode(s, 'unicode-escape', 'strict')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise AssertionError, "failed to raise an exception when presented " \
|
raise AssertionError, "failed to raise an exception when presented " \
|
||||||
"with a UCN > k_cchMaxUnicodeName"
|
"with a UCN > k_cchMaxUnicodeName"
|
||||||
try:
|
try:
|
||||||
unicode("\N{blah}", 'unicode-escape', 'strict')
|
unicode("\N{blah}", 'unicode-escape', 'strict')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
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:
|
try:
|
||||||
unicode("\N{SPACE", 'unicode-escape', 'strict')
|
unicode("\N{SPACE", 'unicode-escape', 'strict')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
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:
|
try:
|
||||||
unicode("\NSPACE", 'unicode-escape', 'strict')
|
unicode("\NSPACE", 'unicode-escape', 'strict')
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
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."
|
print "done."
|
||||||
|
|
||||||
|
|
|
@ -179,41 +179,41 @@ if 0:
|
||||||
|
|
||||||
# Non surrogate above surrogate value, fixup required
|
# Non surrogate above surrogate value, fixup required
|
||||||
def test_lecmp(s, s2):
|
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):
|
def test_fixup(s):
|
||||||
s2 = u'\ud800\udc01'
|
s2 = u'\ud800\udc01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud900\udc01'
|
s2 = u'\ud900\udc01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\uda00\udc01'
|
s2 = u'\uda00\udc01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\udb00\udc01'
|
s2 = u'\udb00\udc01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud800\udd01'
|
s2 = u'\ud800\udd01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud900\udd01'
|
s2 = u'\ud900\udd01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\uda00\udd01'
|
s2 = u'\uda00\udd01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\udb00\udd01'
|
s2 = u'\udb00\udd01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud800\ude01'
|
s2 = u'\ud800\ude01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud900\ude01'
|
s2 = u'\ud900\ude01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\uda00\ude01'
|
s2 = u'\uda00\ude01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\udb00\ude01'
|
s2 = u'\udb00\ude01'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud800\udfff'
|
s2 = u'\ud800\udfff'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\ud900\udfff'
|
s2 = u'\ud900\udfff'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\uda00\udfff'
|
s2 = u'\uda00\udfff'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
s2 = u'\udb00\udfff'
|
s2 = u'\udb00\udfff'
|
||||||
test_lecmp(s, s2)
|
test_lecmp(s, s2)
|
||||||
|
|
||||||
test_fixup(u'\ue000')
|
test_fixup(u'\ue000')
|
||||||
test_fixup(u'\uff61')
|
test_fixup(u'\uff61')
|
||||||
|
@ -515,4 +515,3 @@ assert (u"abc" "def") == u"abcdef"
|
||||||
assert (u"abc" u"def" "ghi") == u"abcdefghi"
|
assert (u"abc" u"def" "ghi") == u"abcdefghi"
|
||||||
assert ("abc" "def" u"ghi") == u"abcdefghi"
|
assert ("abc" "def" u"ghi") == u"abcdefghi"
|
||||||
print 'done.'
|
print 'done.'
|
||||||
|
|
||||||
|
|
|
@ -28,5 +28,3 @@ out2_2 = "abc?def"
|
||||||
|
|
||||||
assert urllib.quote(in2) == out2_1, "urllib.quote problem"
|
assert urllib.quote(in2) == out2_1, "urllib.quote problem"
|
||||||
assert urllib.quote(in2, '?') == out2_2, "urllib.quote problem"
|
assert urllib.quote(in2, '?') == out2_2, "urllib.quote problem"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -144,4 +144,3 @@ if remote_name is not None:
|
||||||
else:
|
else:
|
||||||
print "Remote registry calls can be tested using",
|
print "Remote registry calls can be tested using",
|
||||||
print "'test_winreg.py --remote \\\\machine_name'"
|
print "'test_winreg.py --remote \\\\machine_name'"
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,3 @@ import winsound
|
||||||
for i in range(100, 2000, 100):
|
for i in range(100, 2000, 100):
|
||||||
winsound.Beep(i, 75)
|
winsound.Beep(i, 75)
|
||||||
print "Hopefully you heard some sounds increasing in frequency!"
|
print "Hopefully you heard some sounds increasing in frequency!"
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ testdoc = """\
|
||||||
|
|
||||||
import xmllib
|
import xmllib
|
||||||
if verbose:
|
if verbose:
|
||||||
parser = xmllib.TestXMLParser()
|
parser = xmllib.TestXMLParser()
|
||||||
else:
|
else:
|
||||||
parser = xmllib.XMLParser()
|
parser = xmllib.XMLParser()
|
||||||
|
|
||||||
for c in testdoc:
|
for c in testdoc:
|
||||||
parser.feed(c)
|
parser.feed(c)
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
|
@ -4,23 +4,22 @@ srcname = "junk9630.tmp"
|
||||||
zipname = "junk9708.tmp"
|
zipname = "junk9708.tmp"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fp = open(srcname, "w") # Make a source file with some lines
|
fp = open(srcname, "w") # Make a source file with some lines
|
||||||
for i in range(0, 1000):
|
for i in range(0, 1000):
|
||||||
fp.write("Test of zipfile line %d.\n" % i)
|
fp.write("Test of zipfile line %d.\n" % i)
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
|
zip = zipfile.ZipFile(zipname, "w") # Create the ZIP archive
|
||||||
zip.write(srcname, srcname)
|
zip.write(srcname, srcname)
|
||||||
zip.write(srcname, "another.name")
|
zip.write(srcname, "another.name")
|
||||||
zip.close()
|
zip.close()
|
||||||
|
|
||||||
zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive
|
zip = zipfile.ZipFile(zipname, "r") # Read the ZIP archive
|
||||||
zip.read("another.name")
|
zip.read("another.name")
|
||||||
zip.read(srcname)
|
zip.read(srcname)
|
||||||
zip.close()
|
zip.close()
|
||||||
finally:
|
finally:
|
||||||
if os.path.isfile(srcname): # Remove temporary files
|
if os.path.isfile(srcname): # Remove temporary files
|
||||||
os.unlink(srcname)
|
os.unlink(srcname)
|
||||||
if os.path.isfile(zipname):
|
if os.path.isfile(zipname):
|
||||||
os.unlink(zipname)
|
os.unlink(zipname)
|
||||||
|
|
||||||
|
|
|
@ -158,4 +158,3 @@ LAERTES
|
||||||
|
|
||||||
Farewell.
|
Farewell.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue