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,6 +1,5 @@
|
||||||
|
|
||||||
# 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.
|
||||||
|
|
||||||
# The 3 possible outcomes for each pattern
|
# The 3 possible outcomes for each pattern
|
||||||
|
@ -9,22 +8,22 @@
|
||||||
# Benchmark suite (needs expansion)
|
# Benchmark suite (needs expansion)
|
||||||
#
|
#
|
||||||
# The benchmark suite does not test correctness, just speed. The
|
# The benchmark suite does not test correctness, just speed. The
|
||||||
# first element of each tuple is the regex pattern; the second is a
|
# first element of each tuple is the regex pattern; the second is a
|
||||||
# string to match it against. The benchmarking code will embed the
|
# string to match it against. The benchmarking code will embed the
|
||||||
# second string inside several sizes of padding, to test how regex
|
# second string inside several sizes of padding, to test how regex
|
||||||
# matching performs on large strings.
|
# 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'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
|
||||||
"""Execute a test suite.
|
"""Execute a test suite.
|
||||||
|
|
||||||
This also parses command-line options and modifies its behavior
|
This also parses command-line options and modifies its behavior
|
||||||
accordingly.
|
accordingly.
|
||||||
|
|
||||||
tests -- a list of strings containing test names (optional)
|
tests -- a list of strings containing test names (optional)
|
||||||
testdir -- the directory in which to look for tests (optional)
|
testdir -- the directory in which to look for tests (optional)
|
||||||
|
|
||||||
Users other than the Python test suite will certainly want to
|
Users other than the Python test suite will certainly want to
|
||||||
specify testdir; if it's omitted, the directory containing the
|
specify testdir; if it's omitted, the directory containing the
|
||||||
Python test suite is searched for.
|
Python test suite is searched for.
|
||||||
|
|
||||||
If the tests argument is omitted, the tests listed on the
|
If the tests argument is omitted, the tests listed on the
|
||||||
command-line will be used. If that's empty, too, then all *.py
|
command-line will be used. If that's empty, too, then all *.py
|
||||||
|
@ -65,7 +65,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
|
||||||
command line.
|
command line.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl', ['have-resources'])
|
opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl', ['have-resources'])
|
||||||
except getopt.error, msg:
|
except getopt.error, msg:
|
||||||
|
|
|
@ -81,7 +81,7 @@ def main():
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Toplevel headers
|
# Toplevel headers
|
||||||
|
|
||||||
toplevel = MimeWriter(sys.stdout)
|
toplevel = MimeWriter(sys.stdout)
|
||||||
toplevel.addheader("From", "bwarsaw@cnri.reston.va.us")
|
toplevel.addheader("From", "bwarsaw@cnri.reston.va.us")
|
||||||
toplevel.addheader("Date", "Mon Feb 12 17:21:48 EST 1996")
|
toplevel.addheader("Date", "Mon Feb 12 17:21:48 EST 1996")
|
||||||
|
@ -89,7 +89,7 @@ def main():
|
||||||
toplevel.addheader("MIME-Version", "1.0")
|
toplevel.addheader("MIME-Version", "1.0")
|
||||||
|
|
||||||
# Toplevel body parts
|
# Toplevel body parts
|
||||||
|
|
||||||
f = toplevel.startmultipartbody("knowbot", "801spam999",
|
f = toplevel.startmultipartbody("knowbot", "801spam999",
|
||||||
[("version", "0.1")], prefix=0)
|
[("version", "0.1")], prefix=0)
|
||||||
f.write("This is a multi-part message in MIME format.\n")
|
f.write("This is a multi-part message in MIME format.\n")
|
||||||
|
@ -100,7 +100,7 @@ def main():
|
||||||
md.startmultipartbody("knowbot-metadata", "802spam999")
|
md.startmultipartbody("knowbot-metadata", "802spam999")
|
||||||
|
|
||||||
# Metadata part 1
|
# Metadata part 1
|
||||||
|
|
||||||
md1 = md.nextpart()
|
md1 = md.nextpart()
|
||||||
md1.addheader("KP-Metadata-Type", "simple")
|
md1.addheader("KP-Metadata-Type", "simple")
|
||||||
md1.addheader("KP-Access", "read-only")
|
md1.addheader("KP-Access", "read-only")
|
||||||
|
|
|
@ -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()`
|
|
||||||
|
a.insert(0, example)
|
||||||
|
if verbose:
|
||||||
|
print 'array of %s after inserting another:' % a.typecode, a
|
||||||
|
f = open(TESTFN, 'w')
|
||||||
|
a.tofile(f)
|
||||||
|
f.close()
|
||||||
|
a.tolist()
|
||||||
|
a.tostring()
|
||||||
|
if verbose:
|
||||||
|
print 'array of %s converted to a list: ' % a.typecode, a.tolist()
|
||||||
|
if verbose:
|
||||||
|
print 'array of %s converted to a string: ' \
|
||||||
|
% a.typecode, `a.tostring()`
|
||||||
|
|
||||||
|
if type == 'c':
|
||||||
|
a = array.array(type, "abcde")
|
||||||
|
a[:-1] = a
|
||||||
|
if a != array.array(type, "abcdee"):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
||||||
|
a = array.array(type, "abcde")
|
||||||
|
a[1:] = a
|
||||||
|
if a != array.array(type, "aabcde"):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
||||||
|
a = array.array(type, "abcde")
|
||||||
|
a[1:-1] = a
|
||||||
|
if a != array.array(type, "aabcdee"):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
|
||||||
|
if a.index("e") != 5:
|
||||||
|
raise TestFailed, "array(%s) index-test" % `type`
|
||||||
|
if a.count("a") != 2:
|
||||||
|
raise TestFailed, "array(%s) count-test" % `type`
|
||||||
|
a.remove("e")
|
||||||
|
if a != array.array(type, "aabcde"):
|
||||||
|
raise TestFailed, "array(%s) remove-test" % `type`
|
||||||
|
if a.pop(0) != "a":
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
if a.pop(1) != "b":
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
a.extend(array.array(type, "xyz"))
|
||||||
|
if a != array.array(type, "acdexyz"):
|
||||||
|
raise TestFailed, "array(%s) extend-test" % `type`
|
||||||
|
a.pop()
|
||||||
|
a.pop()
|
||||||
|
a.pop()
|
||||||
|
x = a.pop()
|
||||||
|
if x != 'e':
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
if a != array.array(type, "acd"):
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
a.reverse()
|
||||||
|
if a != array.array(type, "dca"):
|
||||||
|
raise TestFailed, "array(%s) reverse-test" % `type`
|
||||||
|
else:
|
||||||
|
a = array.array(type, [1, 2, 3, 4, 5])
|
||||||
|
a[:-1] = a
|
||||||
|
if a != array.array(type, [1, 2, 3, 4, 5, 5]):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
||||||
|
a = array.array(type, [1, 2, 3, 4, 5])
|
||||||
|
a[1:] = a
|
||||||
|
if a != array.array(type, [1, 1, 2, 3, 4, 5]):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
||||||
|
a = array.array(type, [1, 2, 3, 4, 5])
|
||||||
|
a[1:-1] = a
|
||||||
|
if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]):
|
||||||
|
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
|
||||||
|
if a.index(5) != 5:
|
||||||
|
raise TestFailed, "array(%s) index-test" % `type`
|
||||||
|
if a.count(1) != 2:
|
||||||
|
raise TestFailed, "array(%s) count-test" % `type`
|
||||||
|
a.remove(5)
|
||||||
|
if a != array.array(type, [1, 1, 2, 3, 4, 5]):
|
||||||
|
raise TestFailed, "array(%s) remove-test" % `type`
|
||||||
|
if a.pop(0) != 1:
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
if a.pop(1) != 2:
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
a.extend(array.array(type, [7, 8, 9]))
|
||||||
|
if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]):
|
||||||
|
raise TestFailed, "array(%s) extend-test" % `type`
|
||||||
|
a.pop()
|
||||||
|
a.pop()
|
||||||
|
a.pop()
|
||||||
|
x = a.pop()
|
||||||
|
if x != 5:
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
if a != array.array(type, [1, 3, 4]):
|
||||||
|
raise TestFailed, "array(%s) pop-test" % `type`
|
||||||
|
a.reverse()
|
||||||
|
if a != array.array(type, [4, 3, 1]):
|
||||||
|
raise TestFailed, "array(%s) reverse-test" % `type`
|
||||||
|
|
||||||
|
# test that overflow exceptions are raised as expected for assignment
|
||||||
|
# to array of specific integral types
|
||||||
|
from math import pow
|
||||||
|
if type in ('b', 'h', 'i', 'l'):
|
||||||
|
# check signed and unsigned versions
|
||||||
|
a = array.array(type)
|
||||||
|
signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1))
|
||||||
|
signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L
|
||||||
|
unsignedLowerLimit = 0
|
||||||
|
unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L
|
||||||
|
testoverflow(type, signedLowerLimit, signedUpperLimit)
|
||||||
|
testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit)
|
||||||
|
|
||||||
|
|
||||||
if type == 'c':
|
|
||||||
a = array.array(type, "abcde")
|
|
||||||
a[:-1] = a
|
|
||||||
if a != array.array(type, "abcdee"):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
|
||||||
a = array.array(type, "abcde")
|
|
||||||
a[1:] = a
|
|
||||||
if a != array.array(type, "aabcde"):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
|
||||||
a = array.array(type, "abcde")
|
|
||||||
a[1:-1] = a
|
|
||||||
if a != array.array(type, "aabcdee"):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
|
|
||||||
if a.index("e") != 5:
|
|
||||||
raise TestFailed, "array(%s) index-test" % `type`
|
|
||||||
if a.count("a") != 2:
|
|
||||||
raise TestFailed, "array(%s) count-test" % `type`
|
|
||||||
a.remove("e")
|
|
||||||
if a != array.array(type, "aabcde"):
|
|
||||||
raise TestFailed, "array(%s) remove-test" % `type`
|
|
||||||
if a.pop(0) != "a":
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
if a.pop(1) != "b":
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
a.extend(array.array(type, "xyz"))
|
|
||||||
if a != array.array(type, "acdexyz"):
|
|
||||||
raise TestFailed, "array(%s) extend-test" % `type`
|
|
||||||
a.pop()
|
|
||||||
a.pop()
|
|
||||||
a.pop()
|
|
||||||
x = a.pop()
|
|
||||||
if x != 'e':
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
if a != array.array(type, "acd"):
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
a.reverse()
|
|
||||||
if a != array.array(type, "dca"):
|
|
||||||
raise TestFailed, "array(%s) reverse-test" % `type`
|
|
||||||
else:
|
|
||||||
a = array.array(type, [1, 2, 3, 4, 5])
|
|
||||||
a[:-1] = a
|
|
||||||
if a != array.array(type, [1, 2, 3, 4, 5, 5]):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
|
|
||||||
a = array.array(type, [1, 2, 3, 4, 5])
|
|
||||||
a[1:] = a
|
|
||||||
if a != array.array(type, [1, 1, 2, 3, 4, 5]):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
|
|
||||||
a = array.array(type, [1, 2, 3, 4, 5])
|
|
||||||
a[1:-1] = a
|
|
||||||
if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]):
|
|
||||||
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
|
|
||||||
if a.index(5) != 5:
|
|
||||||
raise TestFailed, "array(%s) index-test" % `type`
|
|
||||||
if a.count(1) != 2:
|
|
||||||
raise TestFailed, "array(%s) count-test" % `type`
|
|
||||||
a.remove(5)
|
|
||||||
if a != array.array(type, [1, 1, 2, 3, 4, 5]):
|
|
||||||
raise TestFailed, "array(%s) remove-test" % `type`
|
|
||||||
if a.pop(0) != 1:
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
if a.pop(1) != 2:
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
a.extend(array.array(type, [7, 8, 9]))
|
|
||||||
if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]):
|
|
||||||
raise TestFailed, "array(%s) extend-test" % `type`
|
|
||||||
a.pop()
|
|
||||||
a.pop()
|
|
||||||
a.pop()
|
|
||||||
x = a.pop()
|
|
||||||
if x != 5:
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
if a != array.array(type, [1, 3, 4]):
|
|
||||||
raise TestFailed, "array(%s) pop-test" % `type`
|
|
||||||
a.reverse()
|
|
||||||
if a != array.array(type, [4, 3, 1]):
|
|
||||||
raise TestFailed, "array(%s) reverse-test" % `type`
|
|
||||||
|
|
||||||
# test that overflow exceptions are raised as expected for assignment
|
|
||||||
# to array of specific integral types
|
|
||||||
from math import pow
|
|
||||||
if type in ('b', 'h', 'i', 'l'):
|
|
||||||
# check signed and unsigned versions
|
|
||||||
a = array.array(type)
|
|
||||||
signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1))
|
|
||||||
signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L
|
|
||||||
unsignedLowerLimit = 0
|
|
||||||
unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L
|
|
||||||
testoverflow(type, signedLowerLimit, signedUpperLimit)
|
|
||||||
testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Augmented assignment test.
|
# Augmented assignment test.
|
||||||
|
|
||||||
x = 2
|
x = 2
|
||||||
|
@ -55,29 +54,29 @@ 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
|
||||||
x += 10
|
x += 10
|
||||||
|
|
||||||
print isinstance(x, aug_test)
|
print isinstance(x, aug_test)
|
||||||
print y is not x
|
print y is not x
|
||||||
print x.val
|
print x.val
|
||||||
|
|
||||||
x = aug_test2(2)
|
x = aug_test2(2)
|
||||||
|
@ -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
|
||||||
|
|
|
@ -20,7 +20,7 @@ def test():
|
||||||
start = 'Jack is my hero'
|
start = 'Jack is my hero'
|
||||||
f.write(start)
|
f.write(start)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
binhex.binhex(fname1, fname2)
|
binhex.binhex(fname1, fname2)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'binhex'
|
print 'binhex'
|
||||||
|
|
|
@ -12,7 +12,7 @@ def test(openmethod, what):
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print '\nTesting: ', what
|
print '\nTesting: ', what
|
||||||
|
|
||||||
fname = tempfile.mktemp()
|
fname = tempfile.mktemp()
|
||||||
f = openmethod(fname, 'c')
|
f = openmethod(fname, 'c')
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -110,7 +110,7 @@ basic(r"""
|
||||||
[Foo Bar]
|
[Foo Bar]
|
||||||
foo=bar
|
foo=bar
|
||||||
[Spacey Bar]
|
[Spacey Bar]
|
||||||
foo = bar
|
foo = bar
|
||||||
[Commented Bar]
|
[Commented Bar]
|
||||||
foo: bar ; comment
|
foo: bar ; comment
|
||||||
""")
|
""")
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
|
|
||||||
class HackedSysModule:
|
class HackedSysModule:
|
||||||
# The regression test will have real values in sys.argv, which
|
# The regression test will have real values in sys.argv, which
|
||||||
# will completely confuse the test of the cgi module
|
# will completely confuse the test of the cgi module
|
||||||
argv = []
|
argv = []
|
||||||
stdin = sys.stdin
|
stdin = sys.stdin
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ def do_test(buf, method):
|
||||||
|
|
||||||
# A list of test cases. Each test case is a a two-tuple that contains
|
# A list of test cases. Each test case is a a two-tuple that contains
|
||||||
# a string with the query and a dictionary with the expected result.
|
# a string with the query and a dictionary with the expected result.
|
||||||
|
|
||||||
parse_test_cases = [
|
parse_test_cases = [
|
||||||
("", ValueError("bad query field: ''")),
|
("", ValueError("bad query field: ''")),
|
||||||
("&", ValueError("bad query field: ''")),
|
("&", ValueError("bad query field: ''")),
|
||||||
|
@ -90,7 +90,7 @@ parse_test_cases = [
|
||||||
'ss': ['env'],
|
'ss': ['env'],
|
||||||
'view': ['bustomer'],
|
'view': ['bustomer'],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse",
|
("group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse",
|
||||||
{'SUBMIT': ['Browse'],
|
{'SUBMIT': ['Browse'],
|
||||||
'_assigned_to': ['31392'],
|
'_assigned_to': ['31392'],
|
||||||
|
|
|
@ -67,7 +67,7 @@ testmeths = [
|
||||||
class AllTests:
|
class AllTests:
|
||||||
def __coerce__(self, *args):
|
def __coerce__(self, *args):
|
||||||
print "__coerce__:", args
|
print "__coerce__:", args
|
||||||
return (self,) + args
|
return (self,) + args
|
||||||
|
|
||||||
def __hash__(self, *args):
|
def __hash__(self, *args):
|
||||||
print "__hash__:", args
|
print "__hash__:", args
|
||||||
|
@ -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
|
||||||
|
@ -8,8 +7,8 @@ import Cookie
|
||||||
cases = [
|
cases = [
|
||||||
('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
|
('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
|
||||||
('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
|
('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
|
||||||
{'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
|
{'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
|
||||||
]
|
]
|
||||||
|
|
||||||
for data, dict in cases:
|
for data, dict in cases:
|
||||||
C = Cookie.SimpleCookie() ; C.load(data)
|
C = Cookie.SimpleCookie() ; C.load(data)
|
||||||
|
@ -37,4 +36,3 @@ C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
|
||||||
assert C['Customer'].value == 'WILE_E_COYOTE'
|
assert C['Customer'].value == 'WILE_E_COYOTE'
|
||||||
assert C['Customer']['version'] == '1'
|
assert C['Customer']['version'] == '1'
|
||||||
assert C['Customer']['path'] == '/acme'
|
assert C['Customer']['path'] == '/acme'
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from test_support import verbose
|
from test_support import verbose
|
||||||
import crypt
|
import crypt
|
||||||
|
|
||||||
c = crypt.crypt('mypassword', 'ab')
|
c = crypt.crypt('mypassword', 'ab')
|
||||||
|
|
|
@ -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."
|
||||||
|
|
||||||
|
|
|
@ -27,21 +27,21 @@ except TypeError, err:
|
||||||
print "TypeError:", err
|
print "TypeError:", err
|
||||||
else:
|
else:
|
||||||
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
g(*())
|
g(*())
|
||||||
except TypeError, err:
|
except TypeError, err:
|
||||||
print "TypeError:", err
|
print "TypeError:", err
|
||||||
else:
|
else:
|
||||||
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
g(*(), **{})
|
g(*(), **{})
|
||||||
except TypeError, err:
|
except TypeError, err:
|
||||||
print "TypeError:", err
|
print "TypeError:", err
|
||||||
else:
|
else:
|
||||||
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
print "should raise TypeError: not enough arguments; expected 1, got 0"
|
||||||
|
|
||||||
g(1)
|
g(1)
|
||||||
g(1, 2)
|
g(1, 2)
|
||||||
g(1, 2, 3)
|
g(1, 2, 3)
|
||||||
|
@ -63,7 +63,7 @@ except AttributeError, attr:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print "should raise AttributeError: __getitem__"
|
print "should raise AttributeError: __getitem__"
|
||||||
|
|
||||||
class Nothing:
|
class Nothing:
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return 5
|
return 5
|
||||||
|
@ -92,14 +92,14 @@ kw = saboteur(a=1, **d)
|
||||||
assert d == {}
|
assert d == {}
|
||||||
# break the cycle
|
# break the cycle
|
||||||
del kw['x']
|
del kw['x']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
g(1, 2, 3, **{'x':4, 'y':5})
|
g(1, 2, 3, **{'x':4, 'y':5})
|
||||||
except TypeError, err:
|
except TypeError, err:
|
||||||
print err
|
print err
|
||||||
else:
|
else:
|
||||||
print "should raise TypeError: keyword parameter redefined"
|
print "should raise TypeError: keyword parameter redefined"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
g(1, 2, 3, a=4, b=5, *(6, 7), **{'a':8, 'b':9})
|
g(1, 2, 3, a=4, b=5, *(6, 7), **{'a':8, 'b':9})
|
||||||
except TypeError, err:
|
except TypeError, err:
|
||||||
|
|
|
@ -15,7 +15,7 @@ f = open(filename, 'w')
|
||||||
rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
|
rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETFL, os.O_NONBLOCK)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Status from fnctl with O_NONBLOCK: ', rv
|
print 'Status from fnctl with O_NONBLOCK: ', rv
|
||||||
|
|
||||||
if sys.platform in ('netbsd1', 'Darwin1.2',
|
if sys.platform in ('netbsd1', 'Darwin1.2',
|
||||||
'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
|
'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
|
||||||
'bsdos2', 'bsdos3', 'bsdos4',
|
'bsdos2', 'bsdos3', 'bsdos4',
|
||||||
|
@ -27,7 +27,7 @@ else:
|
||||||
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
|
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'struct.pack: ', `lockdata`
|
print 'struct.pack: ', `lockdata`
|
||||||
|
|
||||||
rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
|
rv = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW, lockdata)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'String from fcntl with F_SETLKW: ', `rv`
|
print 'String from fcntl with F_SETLKW: ', `rv`
|
||||||
|
|
|
@ -134,15 +134,15 @@ def test_del():
|
||||||
gc.enable()
|
gc.enable()
|
||||||
gc.set_threshold(1)
|
gc.set_threshold(1)
|
||||||
|
|
||||||
class A:
|
class A:
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
dir(self)
|
dir(self)
|
||||||
a = A()
|
a = A()
|
||||||
del a
|
del a
|
||||||
|
|
||||||
gc.disable()
|
gc.disable()
|
||||||
apply(gc.set_threshold, thresholds)
|
apply(gc.set_threshold, thresholds)
|
||||||
|
|
||||||
|
|
||||||
def test_all():
|
def test_all():
|
||||||
run_test("lists", test_list)
|
run_test("lists", test_list)
|
||||||
|
@ -161,7 +161,7 @@ def test():
|
||||||
print "disabling automatic collection"
|
print "disabling automatic collection"
|
||||||
enabled = gc.isenabled()
|
enabled = gc.isenabled()
|
||||||
gc.disable()
|
gc.disable()
|
||||||
assert not gc.isenabled()
|
assert not gc.isenabled()
|
||||||
debug = gc.get_debug()
|
debug = gc.get_debug()
|
||||||
gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak
|
gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"""Test script for the gdbm module
|
"""Test script for the gdbm module
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import gdbm
|
import gdbm
|
||||||
from gdbm import error
|
from gdbm import error
|
||||||
from test_support import verbose, TestFailed
|
from test_support import verbose, TestFailed
|
||||||
|
@ -15,7 +15,7 @@ g['12345678910'] = '019237410982340912840198242'
|
||||||
a = g.keys()
|
a = g.keys()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Test gdbm file keys: ', a
|
print 'Test gdbm file keys: ', a
|
||||||
|
|
||||||
g.has_key('a')
|
g.has_key('a')
|
||||||
g.close()
|
g.close()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -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.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -146,5 +146,5 @@ def main():
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'winclose'
|
print 'winclose'
|
||||||
gl.winclose(w)
|
gl.winclose(w)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -142,11 +142,11 @@ print 'funcdef'
|
||||||
### parameters: '(' [varargslist] ')'
|
### parameters: '(' [varargslist] ')'
|
||||||
### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
|
### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
|
||||||
### | ('**'|'*' '*') NAME)
|
### | ('**'|'*' '*') NAME)
|
||||||
### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
|
### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
|
||||||
### 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"),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"""Test script for the grp module
|
"""Test script for the grp module
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import grp
|
import grp
|
||||||
from test_support import verbose
|
from test_support import verbose
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
import gzip, tempfile
|
import gzip, tempfile
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ while 1:
|
||||||
line_length = (line_length + 1) % 50
|
line_length = (line_length + 1) % 50
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Try .readlines()
|
# Try .readlines()
|
||||||
|
|
||||||
f = gzip.GzipFile(filename, 'rb')
|
f = gzip.GzipFile(filename, 'rb')
|
||||||
L = f.readlines()
|
L = f.readlines()
|
||||||
|
@ -47,7 +46,7 @@ f.close()
|
||||||
f = gzip.GzipFile(filename, 'rb')
|
f = gzip.GzipFile(filename, 'rb')
|
||||||
while 1:
|
while 1:
|
||||||
L = f.readlines(150)
|
L = f.readlines(150)
|
||||||
if L == []: break
|
if L == []: break
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ def main(use_rgbimg=1):
|
||||||
image, width, height = getrgbimage('test.rgb')
|
image, width, height = getrgbimage('test.rgb')
|
||||||
else:
|
else:
|
||||||
image, width, height = getimage('test.rgb')
|
image, width, height = getimage('test.rgb')
|
||||||
|
|
||||||
# Return the selected part of image, which should by width by height
|
# Return the selected part of image, which should by width by height
|
||||||
# in size and consist of pixels of psize bytes.
|
# in size and consist of pixels of psize bytes.
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -28,7 +28,7 @@ def main(use_rgbimg=1):
|
||||||
# Return image scaled to size newwidth by newheight. No interpolation
|
# Return image scaled to size newwidth by newheight. No interpolation
|
||||||
# is done, scaling is done by simple-minded pixel duplication or removal.
|
# is done, scaling is done by simple-minded pixel duplication or removal.
|
||||||
# Therefore, computer-generated images or dithered images will
|
# Therefore, computer-generated images or dithered images will
|
||||||
# not look nice after scaling.
|
# not look nice after scaling.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'scale'
|
print 'scale'
|
||||||
scaleimage = imageop.scale(image, 4, width, height, 1, 1)
|
scaleimage = imageop.scale(image, 4, width, height, 1, 1)
|
||||||
|
@ -36,7 +36,7 @@ def main(use_rgbimg=1):
|
||||||
# Run a vertical low-pass filter over an image. It does so by computing
|
# Run a vertical low-pass filter over an image. It does so by computing
|
||||||
# each destination pixel as the average of two vertically-aligned source
|
# each destination pixel as the average of two vertically-aligned source
|
||||||
# pixels. The main use of this routine is to forestall excessive flicker
|
# pixels. The main use of this routine is to forestall excessive flicker
|
||||||
# if the image two vertically-aligned source pixels, hence the name.
|
# if the image two vertically-aligned source pixels, hence the name.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'tovideo'
|
print 'tovideo'
|
||||||
videoimage = imageop.tovideo (image, 4, width, height)
|
videoimage = imageop.tovideo (image, 4, width, height)
|
||||||
|
@ -50,7 +50,7 @@ def main(use_rgbimg=1):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'rgb82rgb'
|
print 'rgb82rgb'
|
||||||
image = imageop.rgb82rgb(greyimage, width, height)
|
image = imageop.rgb82rgb(greyimage, width, height)
|
||||||
|
|
||||||
# Convert an rgb image to an 8 bit greyscale image
|
# Convert an rgb image to an 8 bit greyscale image
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'rgb2grey'
|
print 'rgb2grey'
|
||||||
|
@ -60,13 +60,13 @@ def main(use_rgbimg=1):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey2rgb'
|
print 'grey2rgb'
|
||||||
image = imageop.grey2rgb(greyimage, width, height)
|
image = imageop.grey2rgb(greyimage, width, height)
|
||||||
|
|
||||||
# Convert a 8-bit deep greyscale image to a 1-bit deep image by
|
# Convert a 8-bit deep greyscale image to a 1-bit deep image by
|
||||||
# thresholding all the pixels. The resulting image is tightly packed
|
# thresholding all the pixels. The resulting image is tightly packed
|
||||||
# and is probably only useful as an argument to mono2grey.
|
# and is probably only useful as an argument to mono2grey.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey2mono'
|
print 'grey2mono'
|
||||||
monoimage = imageop.grey2mono (greyimage, width, height, 0)
|
monoimage = imageop.grey2mono (greyimage, width, height, 0)
|
||||||
|
|
||||||
# monoimage, width, height = getimage('monotest.rgb')
|
# monoimage, width, height = getimage('monotest.rgb')
|
||||||
# Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
|
# Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
|
||||||
|
@ -85,30 +85,30 @@ def main(use_rgbimg=1):
|
||||||
monoimage = imageop.dither2mono (greyimage, width, height)
|
monoimage = imageop.dither2mono (greyimage, width, height)
|
||||||
|
|
||||||
# Convert an 8-bit greyscale image to a 4-bit greyscale image without
|
# Convert an 8-bit greyscale image to a 4-bit greyscale image without
|
||||||
# dithering.
|
# dithering.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey2grey4'
|
print 'grey2grey4'
|
||||||
grey4image = imageop.grey2grey4 (greyimage, width, height)
|
grey4image = imageop.grey2grey4 (greyimage, width, height)
|
||||||
|
|
||||||
# Convert an 8-bit greyscale image to a 2-bit greyscale image without
|
# Convert an 8-bit greyscale image to a 2-bit greyscale image without
|
||||||
# dithering.
|
# dithering.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey2grey2'
|
print 'grey2grey2'
|
||||||
grey2image = imageop.grey2grey2 (greyimage, width, height)
|
grey2image = imageop.grey2grey2 (greyimage, width, height)
|
||||||
|
|
||||||
# Convert an 8-bit greyscale image to a 2-bit greyscale image with
|
# Convert an 8-bit greyscale image to a 2-bit greyscale image with
|
||||||
# dithering. As for dither2mono, the dithering algorithm is currently
|
# dithering. As for dither2mono, the dithering algorithm is currently
|
||||||
# very simple.
|
# very simple.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'dither2grey2'
|
print 'dither2grey2'
|
||||||
grey2image = imageop.dither2grey2 (greyimage, width, height)
|
grey2image = imageop.dither2grey2 (greyimage, width, height)
|
||||||
|
|
||||||
# Convert a 4-bit greyscale image to an 8-bit greyscale image.
|
# Convert a 4-bit greyscale image to an 8-bit greyscale image.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey42grey'
|
print 'grey42grey'
|
||||||
greyimage = imageop.grey42grey (grey4image, width, height)
|
greyimage = imageop.grey42grey (grey4image, width, height)
|
||||||
|
|
||||||
# Convert a 2-bit greyscale image to an 8-bit greyscale image.
|
# Convert a 2-bit greyscale image to an 8-bit greyscale image.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'grey22grey'
|
print 'grey22grey'
|
||||||
image = imageop.grey22grey (grey2image, width, height)
|
image = imageop.grey22grey (grey2image, width, height)
|
||||||
|
@ -132,14 +132,14 @@ def getrgbimage(name):
|
||||||
|
|
||||||
image = rgbimg.longimagedata(name)
|
image = rgbimg.longimagedata(name)
|
||||||
return (image, sizes[0], sizes[1])
|
return (image, sizes[0], sizes[1])
|
||||||
|
|
||||||
def getimage(name):
|
def getimage(name):
|
||||||
"""return a tuple consisting of
|
"""return a tuple consisting of
|
||||||
image (in 'imgfile' format) width and height
|
image (in 'imgfile' format) width and height
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import imgfile
|
import imgfile
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sizes = imgfile.getsizes(name)
|
sizes = imgfile.getsizes(name)
|
||||||
except imgfile.error:
|
except imgfile.error:
|
||||||
|
|
|
@ -8,7 +8,7 @@ from test_support import verbose, unlink, findfile
|
||||||
|
|
||||||
import imgfile, uu, os
|
import imgfile, uu, os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
uu.decode(findfile('testrgb.uue'), 'test.rgb')
|
uu.decode(findfile('testrgb.uue'), 'test.rgb')
|
||||||
|
@ -16,7 +16,7 @@ def main():
|
||||||
|
|
||||||
# Test a 3 byte color image
|
# Test a 3 byte color image
|
||||||
testimage('test.rgb')
|
testimage('test.rgb')
|
||||||
|
|
||||||
# Test a 1 byte greyscale image
|
# Test a 1 byte greyscale image
|
||||||
testimage('greytest.rgb')
|
testimage('greytest.rgb')
|
||||||
|
|
||||||
|
@ -57,18 +57,18 @@ def testimage(name):
|
||||||
# and returns it as a python string. The string has either 1 byte
|
# and returns it as a python string. The string has either 1 byte
|
||||||
# greyscale pixels or 4 byte RGBA pixels. The bottom left pixel
|
# greyscale pixels or 4 byte RGBA pixels. The bottom left pixel
|
||||||
# is the first in the string. This format is suitable to pass
|
# is the first in the string. This format is suitable to pass
|
||||||
# to gl.lrectwrite, for instance.
|
# to gl.lrectwrite, for instance.
|
||||||
image = imgfile.read(name)
|
image = imgfile.read(name)
|
||||||
|
|
||||||
# This function writes the RGB or greyscale data in data to
|
# This function writes the RGB or greyscale data in data to
|
||||||
# image file file. x and y give the size of the image, z is
|
# image file file. x and y give the size of the image, z is
|
||||||
# 1 for 1 byte greyscale images or 3 for RGB images (which
|
# 1 for 1 byte greyscale images or 3 for RGB images (which
|
||||||
# are stored as 4 byte values of which only the lower three
|
# are stored as 4 byte values of which only the lower three
|
||||||
# bytes are used). These are the formats returned by gl.lrectread.
|
# bytes are used). These are the formats returned by gl.lrectread.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Writing output file'
|
print 'Writing output file'
|
||||||
imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2])
|
imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2])
|
||||||
|
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes))
|
print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes))
|
||||||
|
@ -91,18 +91,18 @@ def testimage(name):
|
||||||
# This function sets a global flag which defines whether the
|
# This function sets a global flag which defines whether the
|
||||||
# scan lines of the image are read or written from bottom to
|
# scan lines of the image are read or written from bottom to
|
||||||
# top (flag is zero, compatible with SGI GL) or from top to
|
# top (flag is zero, compatible with SGI GL) or from top to
|
||||||
# bottom(flag is one, compatible with X). The default is zero.
|
# bottom(flag is one, compatible with X). The default is zero.
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Switching to X compatibility'
|
print 'Switching to X compatibility'
|
||||||
imgfile.ttob (1)
|
imgfile.ttob (1)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Filtering with "triangle"'
|
print 'Filtering with "triangle"'
|
||||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'triangle', 3.0)
|
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'triangle', 3.0)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Switching back to SGI compatibility'
|
print 'Switching back to SGI compatibility'
|
||||||
imgfile.ttob (0)
|
imgfile.ttob (0)
|
||||||
|
|
||||||
if verbose: print 'Filtering with "quadratic"'
|
if verbose: print 'Filtering with "quadratic"'
|
||||||
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic')
|
simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic')
|
||||||
if verbose: print 'Filtering with "gaussian"'
|
if verbose: print 'Filtering with "gaussian"'
|
||||||
|
@ -110,7 +110,7 @@ def testimage(name):
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'Writing output file'
|
print 'Writing output file'
|
||||||
imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2])
|
imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2])
|
||||||
|
|
||||||
os.unlink(outputfile)
|
os.unlink(outputfile)
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
REPS = 65580
|
REPS = 65580
|
||||||
|
|
||||||
l = eval("[" + "2," * REPS + "]")
|
l = eval("[" + "2," * REPS + "]")
|
||||||
print len(l)
|
print len(l)
|
||||||
|
|
|
@ -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'
|
||||||
|
|
|
@ -16,9 +16,9 @@ tstfile = os.path.join(os.path.dirname(base), "test.xml")
|
||||||
del base
|
del base
|
||||||
|
|
||||||
def confirm(test, testname = "Test"):
|
def confirm(test, testname = "Test"):
|
||||||
if test:
|
if test:
|
||||||
print "Passed " + testname
|
print "Passed " + testname
|
||||||
else:
|
else:
|
||||||
print "Failed " + testname
|
print "Failed " + testname
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ def testInsertBefore():
|
||||||
docel = dom.documentElement
|
docel = dom.documentElement
|
||||||
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
||||||
# docel.childNodes[1])
|
# docel.childNodes[1])
|
||||||
|
|
||||||
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
|
||||||
# docel.childNodes[0])
|
# docel.childNodes[0])
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def testRemoveAttrNS():
|
||||||
dom = Document()
|
dom = Document()
|
||||||
child = dom.appendChild(
|
child = dom.appendChild(
|
||||||
dom.createElementNS("http://www.python.org", "python:abc"))
|
dom.createElementNS("http://www.python.org", "python:abc"))
|
||||||
child.setAttributeNS("http://www.w3.org", "xmlns:python",
|
child.setAttributeNS("http://www.w3.org", "xmlns:python",
|
||||||
"http://www.python.org")
|
"http://www.python.org")
|
||||||
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
|
child.setAttributeNS("http://www.python.org", "python:abcattr", "foo")
|
||||||
confirm(len(child.attributes) == 2)
|
confirm(len(child.attributes) == 2)
|
||||||
|
@ -141,7 +141,7 @@ def testRemoveAttrNS():
|
||||||
confirm(len(child.attributes) == 1)
|
confirm(len(child.attributes) == 1)
|
||||||
|
|
||||||
dom.unlink()
|
dom.unlink()
|
||||||
|
|
||||||
def testRemoveAttributeNode():
|
def testRemoveAttributeNode():
|
||||||
dom = Document()
|
dom = Document()
|
||||||
child = dom.appendChild(dom.createElement("foo"))
|
child = dom.appendChild(dom.createElement("foo"))
|
||||||
|
@ -313,11 +313,11 @@ def testSiblings():
|
||||||
root = doc.documentElement
|
root = doc.documentElement
|
||||||
(pi, text, elm) = root.childNodes
|
(pi, text, elm) = root.childNodes
|
||||||
|
|
||||||
confirm(pi.nextSibling is text and
|
confirm(pi.nextSibling is text and
|
||||||
pi.previousSibling is None and
|
pi.previousSibling is None and
|
||||||
text.nextSibling is elm and
|
text.nextSibling is elm and
|
||||||
text.previousSibling is pi and
|
text.previousSibling is pi and
|
||||||
elm.nextSibling is None and
|
elm.nextSibling is None and
|
||||||
elm.previousSibling is text, "testSiblings")
|
elm.previousSibling is text, "testSiblings")
|
||||||
|
|
||||||
doc.unlink()
|
doc.unlink()
|
||||||
|
@ -347,7 +347,7 @@ def testSAX2DOM():
|
||||||
sax2dom.startElement("subelm", {})
|
sax2dom.startElement("subelm", {})
|
||||||
sax2dom.characters("text")
|
sax2dom.characters("text")
|
||||||
sax2dom.endElement("subelm")
|
sax2dom.endElement("subelm")
|
||||||
sax2dom.characters("text")
|
sax2dom.characters("text")
|
||||||
sax2dom.endElement("doc")
|
sax2dom.endElement("doc")
|
||||||
sax2dom.endDocument()
|
sax2dom.endDocument()
|
||||||
|
|
||||||
|
@ -370,11 +370,11 @@ def testSAX2DOM():
|
||||||
elm1.parentNode is root and
|
elm1.parentNode is root and
|
||||||
text2.parentNode is root and
|
text2.parentNode is root and
|
||||||
text3.parentNode is elm1, "testSAX2DOM - parents")
|
text3.parentNode is elm1, "testSAX2DOM - parents")
|
||||||
|
|
||||||
doc.unlink()
|
doc.unlink()
|
||||||
|
|
||||||
# --- MAIN PROGRAM
|
# --- MAIN PROGRAM
|
||||||
|
|
||||||
names = globals().keys()
|
names = globals().keys()
|
||||||
names.sort()
|
names.sort()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import mmap
|
import mmap
|
||||||
import string, os, re, sys
|
import string, os, re, sys
|
||||||
|
|
||||||
|
@ -6,10 +5,10 @@ PAGESIZE = mmap.PAGESIZE
|
||||||
|
|
||||||
def test_both():
|
def test_both():
|
||||||
"Test mmap module on Unix systems and Windows"
|
"Test mmap module on Unix systems and Windows"
|
||||||
|
|
||||||
# Create an mmap'ed file
|
# Create an mmap'ed file
|
||||||
f = open('foo', 'w+')
|
f = open('foo', 'w+')
|
||||||
|
|
||||||
# Write 2 pages worth of data to the file
|
# Write 2 pages worth of data to the file
|
||||||
f.write('\0'* PAGESIZE)
|
f.write('\0'* PAGESIZE)
|
||||||
f.write('foo')
|
f.write('foo')
|
||||||
|
@ -17,11 +16,11 @@ def test_both():
|
||||||
|
|
||||||
m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
|
m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Simple sanity checks
|
# Simple sanity checks
|
||||||
print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages'
|
print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages'
|
||||||
assert string.find(m, 'foo') == PAGESIZE
|
assert string.find(m, 'foo') == PAGESIZE
|
||||||
|
|
||||||
print ' Length of file:', len(m) / float(PAGESIZE), 'pages'
|
print ' Length of file:', len(m) / float(PAGESIZE), 'pages'
|
||||||
assert len(m) == 2*PAGESIZE
|
assert len(m) == 2*PAGESIZE
|
||||||
|
|
||||||
|
@ -29,12 +28,12 @@ def test_both():
|
||||||
assert m[0] == '\0'
|
assert m[0] == '\0'
|
||||||
print ' Contents of first 3 bytes:', repr(m[0:3])
|
print ' Contents of first 3 bytes:', repr(m[0:3])
|
||||||
assert m[0:3] == '\0\0\0'
|
assert m[0:3] == '\0\0\0'
|
||||||
|
|
||||||
# Modify the file's content
|
# Modify the file's content
|
||||||
print "\n Modifying file's content..."
|
print "\n Modifying file's content..."
|
||||||
m[0] = '3'
|
m[0] = '3'
|
||||||
m[PAGESIZE +3: PAGESIZE +3+3]='bar'
|
m[PAGESIZE +3: PAGESIZE +3+3]='bar'
|
||||||
|
|
||||||
# Check that the modification worked
|
# Check that the modification worked
|
||||||
print ' Contents of byte 0:', repr(m[0])
|
print ' Contents of byte 0:', repr(m[0])
|
||||||
assert m[0] == '3'
|
assert m[0] == '3'
|
||||||
|
@ -42,7 +41,7 @@ def test_both():
|
||||||
assert m[0:3] == '3\0\0'
|
assert m[0:3] == '3\0\0'
|
||||||
print ' Contents of second page:', repr(m[PAGESIZE-1 : PAGESIZE + 7])
|
print ' Contents of second page:', repr(m[PAGESIZE-1 : PAGESIZE + 7])
|
||||||
assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0'
|
assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0'
|
||||||
|
|
||||||
m.flush()
|
m.flush()
|
||||||
|
|
||||||
# Test doing a regular expression match in an mmap'ed file
|
# Test doing a regular expression match in an mmap'ed file
|
||||||
|
@ -51,11 +50,11 @@ def test_both():
|
||||||
print ' ERROR: regex match on mmap failed!'
|
print ' ERROR: regex match on mmap failed!'
|
||||||
else:
|
else:
|
||||||
start, end = match.span(0)
|
start, end = match.span(0)
|
||||||
length = end - start
|
length = end - start
|
||||||
|
|
||||||
print ' Regex match on mmap (page start, length of match):',
|
print ' Regex match on mmap (page start, length of match):',
|
||||||
print start / float(PAGESIZE), length
|
print start / float(PAGESIZE), length
|
||||||
|
|
||||||
assert start == PAGESIZE
|
assert start == PAGESIZE
|
||||||
assert end == PAGESIZE + 6
|
assert end == PAGESIZE + 6
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ def test_both():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
assert 0, 'Could seek beyond the new size'
|
assert 0, 'Could seek beyond the new size'
|
||||||
|
|
||||||
m.close()
|
m.close()
|
||||||
os.unlink("foo")
|
os.unlink("foo")
|
||||||
print ' Test passed'
|
print ' Test passed'
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,15 @@ print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception'
|
||||||
# SourceForge bug #112558:
|
# SourceForge bug #112558:
|
||||||
# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
|
# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
|
||||||
|
|
||||||
class BadDictKey:
|
class BadDictKey:
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.__class__)
|
return hash(self.__class__)
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
if isinstance(other, self.__class__):
|
if isinstance(other, self.__class__):
|
||||||
print "raising error"
|
print "raising error"
|
||||||
raise RuntimeError, "gotcha"
|
raise RuntimeError, "gotcha"
|
||||||
return other
|
return other
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
x1 = BadDictKey()
|
x1 = BadDictKey()
|
||||||
|
|
|
@ -137,7 +137,7 @@ def dotest(pickle):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print "accepted insecure string: %s" % repr(buf)
|
print "accepted insecure string: %s" % repr(buf)
|
||||||
|
|
||||||
|
|
||||||
import pickle
|
import pickle
|
||||||
dotest(pickle)
|
dotest(pickle)
|
||||||
|
|
|
@ -78,7 +78,7 @@ def runtest(hier, code):
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
("t1", [("t1", None), ("t1 __init__.py", "")], "import t1"),
|
("t1", [("t1", None), ("t1 __init__.py", "")], "import t1"),
|
||||||
|
|
||||||
("t2", [
|
("t2", [
|
||||||
("t2", None),
|
("t2", None),
|
||||||
("t2 __init__.py", "'doc for t2'; print __name__, 'loading'"),
|
("t2 __init__.py", "'doc for t2'; print __name__, 'loading'"),
|
||||||
|
@ -108,7 +108,7 @@ print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__
|
||||||
from t2 import *
|
from t2 import *
|
||||||
print dir()
|
print dir()
|
||||||
"""),
|
"""),
|
||||||
|
|
||||||
("t3", [
|
("t3", [
|
||||||
("t3", None),
|
("t3", None),
|
||||||
("t3 __init__.py", "print __name__, 'loading'"),
|
("t3 __init__.py", "print __name__, 'loading'"),
|
||||||
|
@ -124,7 +124,7 @@ reload(t3)
|
||||||
reload(t3.sub)
|
reload(t3.sub)
|
||||||
reload(t3.sub.subsub)
|
reload(t3.sub.subsub)
|
||||||
"""),
|
"""),
|
||||||
|
|
||||||
("t4", [
|
("t4", [
|
||||||
("t4.py", "print 'THIS SHOULD NOT BE PRINTED (t4.py)'"),
|
("t4.py", "print 'THIS SHOULD NOT BE PRINTED (t4.py)'"),
|
||||||
("t4", None),
|
("t4", None),
|
||||||
|
@ -172,7 +172,7 @@ from t6 import *
|
||||||
print fixdir(dir(t6))
|
print fixdir(dir(t6))
|
||||||
print dir()
|
print dir()
|
||||||
"""),
|
"""),
|
||||||
|
|
||||||
("t7", [
|
("t7", [
|
||||||
("t7.py", "print 'Importing t7.py'"),
|
("t7.py", "print 'Importing t7.py'"),
|
||||||
("t7", None),
|
("t7", None),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Test case for the os.poll() function
|
# Test case for the os.poll() function
|
||||||
|
|
||||||
import sys, os, select, random
|
import sys, os, select, random
|
||||||
from test_support import verbose, TestSkipped, TESTFN
|
from test_support import verbose, TestSkipped, TESTFN
|
||||||
|
|
||||||
|
|
|
@ -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."
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ import sys
|
||||||
import test_support
|
import test_support
|
||||||
|
|
||||||
def powtest(type):
|
def powtest(type):
|
||||||
if type != float:
|
if type != float:
|
||||||
print " Testing 2-argument pow() function..."
|
print " Testing 2-argument pow() function..."
|
||||||
for i in range(-1000, 1000):
|
for i in range(-1000, 1000):
|
||||||
if pow(type(i), 0) != 1:
|
if pow(type(i), 0) != 1:
|
||||||
raise ValueError, 'pow('+str(i)+',0) != 1'
|
raise ValueError, 'pow('+str(i)+',0) != 1'
|
||||||
if pow(type(i), 1) != type(i):
|
if pow(type(i), 1) != type(i):
|
||||||
raise ValueError, 'pow('+str(i)+',1) != '+str(i)
|
raise ValueError, 'pow('+str(i)+',1) != '+str(i)
|
||||||
|
@ -17,7 +17,7 @@ def powtest(type):
|
||||||
for i in range(-100, 100):
|
for i in range(-100, 100):
|
||||||
if pow(type(i), 3) != i*i*i:
|
if pow(type(i), 3) != i*i*i:
|
||||||
raise ValueError, 'pow('+str(i)+',3) != '+str(i*i*i)
|
raise ValueError, 'pow('+str(i)+',3) != '+str(i*i*i)
|
||||||
|
|
||||||
pow2 = 1
|
pow2 = 1
|
||||||
for i in range(0,31):
|
for i in range(0,31):
|
||||||
if pow(2, i) != pow2:
|
if pow(2, i) != pow2:
|
||||||
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ while bynames.has_key(fakename):
|
||||||
# should never happen... if so, just forget it
|
# should never happen... if so, just forget it
|
||||||
break
|
break
|
||||||
fakename = string.join(map(None, chars), '')
|
fakename = string.join(map(None, chars), '')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pwd.getpwnam(fakename)
|
pwd.getpwnam(fakename)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
# XXX TypeErrors on calling handlers, or on bad return values from a
|
# XXX TypeErrors on calling handlers, or on bad return values from a
|
||||||
# handler, are obscure and unhelpful.
|
# handler, are obscure and unhelpful.
|
||||||
|
|
||||||
from xml.parsers import expat
|
from xml.parsers import expat
|
||||||
|
|
||||||
class Outputter:
|
class Outputter:
|
||||||
def StartElementHandler(self, name, attrs):
|
def StartElementHandler(self, name, attrs):
|
||||||
print 'Start element:\n\t', repr(name), attrs
|
print 'Start element:\n\t', repr(name), attrs
|
||||||
|
|
||||||
def EndElementHandler(self, name):
|
def EndElementHandler(self, name):
|
||||||
print 'End element:\n\t', repr(name)
|
print 'End element:\n\t', repr(name)
|
||||||
|
|
||||||
|
@ -43,11 +43,11 @@ class Outputter:
|
||||||
def UnparsedEntityDeclHandler(self, *args):
|
def UnparsedEntityDeclHandler(self, *args):
|
||||||
entityName, base, systemId, publicId, notationName = args
|
entityName, base, systemId, publicId, notationName = args
|
||||||
print 'Unparsed entity decl:\n\t', args
|
print 'Unparsed entity decl:\n\t', args
|
||||||
|
|
||||||
def NotStandaloneHandler(self, userData):
|
def NotStandaloneHandler(self, userData):
|
||||||
print 'Not standalone'
|
print 'Not standalone'
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def ExternalEntityRefHandler(self, *args):
|
def ExternalEntityRefHandler(self, *args):
|
||||||
context, base, sysId, pubId = args
|
context, base, sysId, pubId = args
|
||||||
print 'External entity ref:', args
|
print 'External entity ref:', args
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -69,7 +69,7 @@ for t in tests:
|
||||||
if len(t)==5:
|
if len(t)==5:
|
||||||
pattern, s, outcome, repl, expected = t
|
pattern, s, outcome, repl, expected = t
|
||||||
elif len(t)==3:
|
elif len(t)==3:
|
||||||
pattern, s, outcome = t
|
pattern, s, outcome = t
|
||||||
else:
|
else:
|
||||||
raise ValueError, ('Test tuples should have 3 or 5 fields',t)
|
raise ValueError, ('Test tuples should have 3 or 5 fields',t)
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ for t in tests:
|
||||||
obj=regex.compile(pattern)
|
obj=regex.compile(pattern)
|
||||||
except regex.error:
|
except regex.error:
|
||||||
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
|
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
|
||||||
else:
|
else:
|
||||||
# Regex syntax errors aren't yet reported, so for
|
# Regex syntax errors aren't yet reported, so for
|
||||||
# the official test suite they'll be quietly ignored.
|
# the official test suite they'll be quietly ignored.
|
||||||
pass
|
pass
|
||||||
#print '=== Syntax error:', t
|
#print '=== Syntax error:', t
|
||||||
|
|
|
@ -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$
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ def test_xmlgen_basic():
|
||||||
def test_xmlgen_content():
|
def test_xmlgen_content():
|
||||||
result = StringIO()
|
result = StringIO()
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
|
|
||||||
gen.startDocument()
|
gen.startDocument()
|
||||||
gen.startElement("doc", {})
|
gen.startElement("doc", {})
|
||||||
gen.characters("huhei")
|
gen.characters("huhei")
|
||||||
|
@ -87,7 +86,7 @@ def test_xmlgen_content():
|
||||||
def test_xmlgen_pi():
|
def test_xmlgen_pi():
|
||||||
result = StringIO()
|
result = StringIO()
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
|
|
||||||
gen.startDocument()
|
gen.startDocument()
|
||||||
gen.processingInstruction("test", "data")
|
gen.processingInstruction("test", "data")
|
||||||
gen.startElement("doc", {})
|
gen.startElement("doc", {})
|
||||||
|
@ -99,7 +98,7 @@ def test_xmlgen_pi():
|
||||||
def test_xmlgen_content_escape():
|
def test_xmlgen_content_escape():
|
||||||
result = StringIO()
|
result = StringIO()
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
|
|
||||||
gen.startDocument()
|
gen.startDocument()
|
||||||
gen.startElement("doc", {})
|
gen.startElement("doc", {})
|
||||||
gen.characters("<huhei&")
|
gen.characters("<huhei&")
|
||||||
|
@ -111,7 +110,7 @@ def test_xmlgen_content_escape():
|
||||||
def test_xmlgen_ignorable():
|
def test_xmlgen_ignorable():
|
||||||
result = StringIO()
|
result = StringIO()
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
|
|
||||||
gen.startDocument()
|
gen.startDocument()
|
||||||
gen.startElement("doc", {})
|
gen.startElement("doc", {})
|
||||||
gen.ignorableWhitespace(" ")
|
gen.ignorableWhitespace(" ")
|
||||||
|
@ -125,7 +124,7 @@ ns_uri = "http://www.python.org/xml-ns/saxtest/"
|
||||||
def test_xmlgen_ns():
|
def test_xmlgen_ns():
|
||||||
result = StringIO()
|
result = StringIO()
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
|
|
||||||
gen.startDocument()
|
gen.startDocument()
|
||||||
gen.startPrefixMapping("ns1", ns_uri)
|
gen.startPrefixMapping("ns1", ns_uri)
|
||||||
gen.startElementNS((ns_uri, "doc"), "ns1:doc", {})
|
gen.startElementNS((ns_uri, "doc"), "ns1:doc", {})
|
||||||
|
@ -147,7 +146,7 @@ def test_filter_basic():
|
||||||
gen = XMLGenerator(result)
|
gen = XMLGenerator(result)
|
||||||
filter = XMLFilterBase()
|
filter = XMLFilterBase()
|
||||||
filter.setContentHandler(gen)
|
filter.setContentHandler(gen)
|
||||||
|
|
||||||
filter.startDocument()
|
filter.startDocument()
|
||||||
filter.startElement("doc", {})
|
filter.startElement("doc", {})
|
||||||
filter.characters("content")
|
filter.characters("content")
|
||||||
|
@ -170,7 +169,7 @@ class TestDTDHandler:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._notations = []
|
self._notations = []
|
||||||
self._entities = []
|
self._entities = []
|
||||||
|
|
||||||
def notationDecl(self, name, publicId, systemId):
|
def notationDecl(self, name, publicId, systemId):
|
||||||
self._notations.append((name, publicId, systemId))
|
self._notations.append((name, publicId, systemId))
|
||||||
|
|
||||||
|
@ -214,7 +213,7 @@ def test_expat_entityresolver():
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
return result.getvalue() == start + "<doc><entity></entity></doc>"
|
return result.getvalue() == start + "<doc><entity></entity></doc>"
|
||||||
|
|
||||||
# ===== Attributes support
|
# ===== Attributes support
|
||||||
|
|
||||||
class AttrGatherer(ContentHandler):
|
class AttrGatherer(ContentHandler):
|
||||||
|
@ -224,7 +223,7 @@ class AttrGatherer(ContentHandler):
|
||||||
|
|
||||||
def startElementNS(self, name, qname, attrs):
|
def startElementNS(self, name, qname, attrs):
|
||||||
self._attrs = attrs
|
self._attrs = attrs
|
||||||
|
|
||||||
def test_expat_attrs_empty():
|
def test_expat_attrs_empty():
|
||||||
parser = create_parser()
|
parser = create_parser()
|
||||||
gather = AttrGatherer()
|
gather = AttrGatherer()
|
||||||
|
@ -264,7 +263,7 @@ def test_expat_nsattrs_wattr():
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
attrs = gather._attrs
|
attrs = gather._attrs
|
||||||
|
|
||||||
return attrs.getLength() == 1 and \
|
return attrs.getLength() == 1 and \
|
||||||
attrs.getNames() == [(ns_uri, "attr")] and \
|
attrs.getNames() == [(ns_uri, "attr")] and \
|
||||||
attrs.getQNames() == [] and \
|
attrs.getQNames() == [] and \
|
||||||
|
@ -376,13 +375,13 @@ def verify_empty_attrs(attrs):
|
||||||
gqnk = 0
|
gqnk = 0
|
||||||
except KeyError:
|
except KeyError:
|
||||||
gqnk = 1
|
gqnk = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
attrs["attr"]
|
attrs["attr"]
|
||||||
gik = 0
|
gik = 0
|
||||||
except KeyError:
|
except KeyError:
|
||||||
gik = 1
|
gik = 1
|
||||||
|
|
||||||
return attrs.getLength() == 0 and \
|
return attrs.getLength() == 0 and \
|
||||||
attrs.getNames() == [] and \
|
attrs.getNames() == [] and \
|
||||||
attrs.getQNames() == [] and \
|
attrs.getQNames() == [] and \
|
||||||
|
@ -444,13 +443,13 @@ def verify_empty_nsattrs(attrs):
|
||||||
gqnk = 0
|
gqnk = 0
|
||||||
except KeyError:
|
except KeyError:
|
||||||
gqnk = 1
|
gqnk = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
attrs[(ns_uri, "attr")]
|
attrs[(ns_uri, "attr")]
|
||||||
gik = 0
|
gik = 0
|
||||||
except KeyError:
|
except KeyError:
|
||||||
gik = 1
|
gik = 1
|
||||||
|
|
||||||
return attrs.getLength() == 0 and \
|
return attrs.getLength() == 0 and \
|
||||||
attrs.getNames() == [] and \
|
attrs.getNames() == [] and \
|
||||||
attrs.getQNames() == [] and \
|
attrs.getQNames() == [] and \
|
||||||
|
@ -469,7 +468,7 @@ def test_nsattrs_empty():
|
||||||
def test_nsattrs_wattr():
|
def test_nsattrs_wattr():
|
||||||
attrs = AttributesNSImpl({(ns_uri, "attr") : "val"},
|
attrs = AttributesNSImpl({(ns_uri, "attr") : "val"},
|
||||||
{(ns_uri, "attr") : "ns:attr"})
|
{(ns_uri, "attr") : "ns:attr"})
|
||||||
|
|
||||||
return attrs.getLength() == 1 and \
|
return attrs.getLength() == 1 and \
|
||||||
attrs.getNames() == [(ns_uri, "attr")] and \
|
attrs.getNames() == [(ns_uri, "attr")] and \
|
||||||
attrs.getQNames() == ["ns:attr"] and \
|
attrs.getQNames() == ["ns:attr"] and \
|
||||||
|
@ -485,7 +484,7 @@ def test_nsattrs_wattr():
|
||||||
attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \
|
attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \
|
||||||
attrs[(ns_uri, "attr")] == "val" and \
|
attrs[(ns_uri, "attr")] == "val" and \
|
||||||
attrs.getQNameByName((ns_uri, "attr")) == "ns:attr"
|
attrs.getQNameByName((ns_uri, "attr")) == "ns:attr"
|
||||||
|
|
||||||
|
|
||||||
# ===== Main program
|
# ===== Main program
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Nope:
|
||||||
class Almost:
|
class Almost:
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
return 'fileno'
|
return 'fileno'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rfd, wfd, xfd = select.select([Nope()], [], [])
|
rfd, wfd, xfd = select.select([Nope()], [], [])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -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'
|
||||||
|
|
|
@ -94,7 +94,7 @@ tests = [
|
||||||
]
|
]
|
||||||
|
|
||||||
def badpack(fmt, arg, got, exp):
|
def badpack(fmt, arg, got, exp):
|
||||||
return
|
return
|
||||||
|
|
||||||
def badunpack(fmt, arg, got, exp):
|
def badunpack(fmt, arg, got, exp):
|
||||||
return "unpack(%s, %s) -> (%s,) # expected (%s,)" % (
|
return "unpack(%s, %s) -> (%s,) # expected (%s,)" % (
|
||||||
|
|
|
@ -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'
|
||||||
|
@ -212,10 +212,10 @@ 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')
|
||||||
|
@ -321,13 +321,13 @@ assert u"%c" % (u"a",) == u'a'
|
||||||
assert u"%c" % ("a",) == u'a'
|
assert u"%c" % ("a",) == u'a'
|
||||||
assert u"%c" % (34,) == u'"'
|
assert u"%c" % (34,) == u'"'
|
||||||
assert u"%c" % (36,) == u'$'
|
assert u"%c" % (36,) == u'$'
|
||||||
value = u"%r, %r" % (u"abc", "abc")
|
value = u"%r, %r" % (u"abc", "abc")
|
||||||
if value != u"u'abc', 'abc'":
|
if value != u"u'abc', 'abc'":
|
||||||
print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")'
|
print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")'
|
||||||
|
|
||||||
assert u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def'
|
assert u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def'
|
||||||
try:
|
try:
|
||||||
value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"}
|
value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print '*** formatting failed for "%s"' % "u'abc, def'"
|
print '*** formatting failed for "%s"' % "u'abc, def'"
|
||||||
else:
|
else:
|
||||||
|
@ -453,7 +453,7 @@ for encoding in (
|
||||||
'cp037', 'cp1026',
|
'cp037', 'cp1026',
|
||||||
'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
|
'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
|
||||||
'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
|
'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
|
||||||
'cp863', 'cp865', 'cp866',
|
'cp863', 'cp865', 'cp866',
|
||||||
'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
|
'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
|
||||||
'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
|
'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
|
||||||
'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
|
'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
|
||||||
|
@ -465,10 +465,10 @@ for encoding in (
|
||||||
|
|
||||||
'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
|
'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
|
||||||
'cp1006', 'cp875', 'iso8859_8',
|
'cp1006', 'cp875', 'iso8859_8',
|
||||||
|
|
||||||
### These have undefined mappings:
|
### These have undefined mappings:
|
||||||
#'cp424',
|
#'cp424',
|
||||||
|
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
assert unicode(s,encoding).encode(encoding) == s
|
assert unicode(s,encoding).encode(encoding) == s
|
||||||
|
@ -483,21 +483,21 @@ for encoding in (
|
||||||
'cp037', 'cp1026',
|
'cp037', 'cp1026',
|
||||||
'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
|
'cp437', 'cp500', 'cp737', 'cp775', 'cp850',
|
||||||
'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
|
'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
|
||||||
'cp863', 'cp865', 'cp866',
|
'cp863', 'cp865', 'cp866',
|
||||||
'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
|
'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
|
||||||
'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
|
'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6',
|
||||||
'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
|
'iso8859_7', 'iso8859_9', 'koi8_r', 'latin_1',
|
||||||
'mac_cyrillic', 'mac_latin2',
|
'mac_cyrillic', 'mac_latin2',
|
||||||
|
|
||||||
### These have undefined mappings:
|
### These have undefined mappings:
|
||||||
#'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
|
#'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
|
||||||
#'cp1256', 'cp1257', 'cp1258',
|
#'cp1256', 'cp1257', 'cp1258',
|
||||||
#'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
|
#'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
|
||||||
#'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
|
#'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
|
||||||
|
|
||||||
### These fail the round-trip:
|
### These fail the round-trip:
|
||||||
#'cp1006', 'cp875', 'iso8859_8',
|
#'cp1006', 'cp875', 'iso8859_8',
|
||||||
|
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
assert unicode(s,encoding).encode(encoding) == s
|
assert unicode(s,encoding).encode(encoding) == s
|
||||||
|
@ -515,4 +515,3 @@ assert (u"abc" "def") == u"abcdef"
|
||||||
assert (u"abc" u"def" "ghi") == u"abcdefghi"
|
assert (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.'
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ def test_methods():
|
||||||
for i in range(65536):
|
for i in range(65536):
|
||||||
char = unichr(i)
|
char = unichr(i)
|
||||||
data = [
|
data = [
|
||||||
|
|
||||||
# Predicates (single char)
|
# Predicates (single char)
|
||||||
char.isalnum() and u'1' or u'0',
|
char.isalnum() and u'1' or u'0',
|
||||||
char.isalpha() and u'1' or u'0',
|
char.isalpha() and u'1' or u'0',
|
||||||
|
@ -26,7 +26,7 @@ def test_methods():
|
||||||
char.isspace() and u'1' or u'0',
|
char.isspace() and u'1' or u'0',
|
||||||
char.istitle() and u'1' or u'0',
|
char.istitle() and u'1' or u'0',
|
||||||
char.isupper() and u'1' or u'0',
|
char.isupper() and u'1' or u'0',
|
||||||
|
|
||||||
# Predicates (multiple chars)
|
# Predicates (multiple chars)
|
||||||
(char + u'abc').isalnum() and u'1' or u'0',
|
(char + u'abc').isalnum() and u'1' or u'0',
|
||||||
(char + u'abc').isalpha() and u'1' or u'0',
|
(char + u'abc').isalpha() and u'1' or u'0',
|
||||||
|
@ -42,13 +42,13 @@ def test_methods():
|
||||||
char.lower(),
|
char.lower(),
|
||||||
char.upper(),
|
char.upper(),
|
||||||
char.title(),
|
char.title(),
|
||||||
|
|
||||||
# Mappings (multiple chars)
|
# Mappings (multiple chars)
|
||||||
(char + u'abc').lower(),
|
(char + u'abc').lower(),
|
||||||
(char + u'ABC').upper(),
|
(char + u'ABC').upper(),
|
||||||
(char + u'abc').title(),
|
(char + u'abc').title(),
|
||||||
(char + u'ABC').title(),
|
(char + u'ABC').title(),
|
||||||
|
|
||||||
]
|
]
|
||||||
h.update(u''.join(data).encode(encoding))
|
h.update(u''.join(data).encode(encoding))
|
||||||
return h.hexdigest()
|
return h.hexdigest()
|
||||||
|
@ -68,7 +68,7 @@ def test_unicodedata():
|
||||||
unicodedata.decomposition(char),
|
unicodedata.decomposition(char),
|
||||||
str(unicodedata.mirrored(char)),
|
str(unicodedata.mirrored(char)),
|
||||||
str(unicodedata.combining(char)),
|
str(unicodedata.combining(char)),
|
||||||
]
|
]
|
||||||
h.update(''.join(data))
|
h.update(''.join(data))
|
||||||
return h.hexdigest()
|
return h.hexdigest()
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ def ignore():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
LAERTES
|
LAERTES
|
||||||
|
|
||||||
O, fear me not.
|
O, fear me not.
|
||||||
I stay too long: but here my father comes.
|
I stay too long: but here my father comes.
|
||||||
|
@ -106,7 +106,7 @@ LAERTES
|
||||||
A double blessing is a double grace,
|
A double blessing is a double grace,
|
||||||
Occasion smiles upon a second leave.
|
Occasion smiles upon a second leave.
|
||||||
|
|
||||||
LORD POLONIUS
|
LORD POLONIUS
|
||||||
|
|
||||||
Yet here, Laertes! aboard, aboard, for shame!
|
Yet here, Laertes! aboard, aboard, for shame!
|
||||||
The wind sits in the shoulder of your sail,
|
The wind sits in the shoulder of your sail,
|
||||||
|
@ -136,26 +136,25 @@ LORD POLONIUS
|
||||||
Thou canst not then be false to any man.
|
Thou canst not then be false to any man.
|
||||||
Farewell: my blessing season this in thee!
|
Farewell: my blessing season this in thee!
|
||||||
|
|
||||||
LAERTES
|
LAERTES
|
||||||
|
|
||||||
Most humbly do I take my leave, my lord.
|
Most humbly do I take my leave, my lord.
|
||||||
|
|
||||||
LORD POLONIUS
|
LORD POLONIUS
|
||||||
|
|
||||||
The time invites you; go; your servants tend.
|
The time invites you; go; your servants tend.
|
||||||
|
|
||||||
LAERTES
|
LAERTES
|
||||||
|
|
||||||
Farewell, Ophelia; and remember well
|
Farewell, Ophelia; and remember well
|
||||||
What I have said to you.
|
What I have said to you.
|
||||||
|
|
||||||
OPHELIA
|
OPHELIA
|
||||||
|
|
||||||
'Tis in my memory lock'd,
|
'Tis in my memory lock'd,
|
||||||
And you yourself shall keep the key of it.
|
And you yourself shall keep the key of it.
|
||||||
|
|
||||||
LAERTES
|
LAERTES
|
||||||
|
|
||||||
Farewell.
|
Farewell.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue