Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
004d5e68
Commit
004d5e68
authored
Oct 23, 2000
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make reindent.py happy (convert everything to 4-space indents!).
parent
2e6d25c5
Changes
70
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
70 changed files
with
1229 additions
and
1261 deletions
+1229
-1261
Lib/test/pystone.py
Lib/test/pystone.py
+182
-182
Lib/test/regex_tests.py
Lib/test/regex_tests.py
+11
-13
Lib/test/regrtest.py
Lib/test/regrtest.py
+3
-3
Lib/test/test_MimeWriter.py
Lib/test/test_MimeWriter.py
+3
-3
Lib/test/test_al.py
Lib/test/test_al.py
+0
-1
Lib/test/test_array.py
Lib/test/test_array.py
+160
-161
Lib/test/test_augassign.py
Lib/test/test_augassign.py
+99
-101
Lib/test/test_b2.py
Lib/test/test_b2.py
+82
-82
Lib/test/test_binhex.py
Lib/test/test_binhex.py
+1
-1
Lib/test/test_bsddb.py
Lib/test/test_bsddb.py
+1
-1
Lib/test/test_cfgparser.py
Lib/test/test_cfgparser.py
+1
-1
Lib/test/test_cgi.py
Lib/test/test_cgi.py
+3
-3
Lib/test/test_class.py
Lib/test/test_class.py
+8
-9
Lib/test/test_contains.py
Lib/test/test_contains.py
+65
-65
Lib/test/test_cookie.py
Lib/test/test_cookie.py
+2
-4
Lib/test/test_crypt.py
Lib/test/test_crypt.py
+1
-1
Lib/test/test_dospath.py
Lib/test/test_dospath.py
+12
-13
Lib/test/test_extcall.py
Lib/test/test_extcall.py
+6
-6
Lib/test/test_fcntl.py
Lib/test/test_fcntl.py
+2
-2
Lib/test/test_gc.py
Lib/test/test_gc.py
+5
-5
Lib/test/test_gdbm.py
Lib/test/test_gdbm.py
+2
-2
Lib/test/test_gettext.py
Lib/test/test_gettext.py
+5
-5
Lib/test/test_gl.py
Lib/test/test_gl.py
+1
-1
Lib/test/test_grammar.py
Lib/test/test_grammar.py
+90
-90
Lib/test/test_grp.py
Lib/test/test_grp.py
+1
-1
Lib/test/test_gzip.py
Lib/test/test_gzip.py
+2
-3
Lib/test/test_hash.py
Lib/test/test_hash.py
+6
-9
Lib/test/test_imageop.py
Lib/test/test_imageop.py
+18
-18
Lib/test/test_imgfile.py
Lib/test/test_imgfile.py
+12
-12
Lib/test/test_largefile.py
Lib/test/test_largefile.py
+10
-10
Lib/test/test_long.py
Lib/test/test_long.py
+0
-1
Lib/test/test_longexp.py
Lib/test/test_longexp.py
+2
-2
Lib/test/test_math.py
Lib/test/test_math.py
+9
-9
Lib/test/test_md5.py
Lib/test/test_md5.py
+8
-8
Lib/test/test_minidom.py
Lib/test/test_minidom.py
+13
-13
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+10
-11
Lib/test/test_ntpath.py
Lib/test/test_ntpath.py
+12
-13
Lib/test/test_opcodes.py
Lib/test/test_opcodes.py
+13
-13
Lib/test/test_openpty.py
Lib/test/test_openpty.py
+0
-1
Lib/test/test_operations.py
Lib/test/test_operations.py
+9
-9
Lib/test/test_pickle.py
Lib/test/test_pickle.py
+1
-1
Lib/test/test_pkg.py
Lib/test/test_pkg.py
+4
-4
Lib/test/test_poll.py
Lib/test/test_poll.py
+1
-1
Lib/test/test_posixpath.py
Lib/test/test_posixpath.py
+11
-12
Lib/test/test_pow.py
Lib/test/test_pow.py
+24
-24
Lib/test/test_pty.py
Lib/test/test_pty.py
+0
-1
Lib/test/test_pwd.py
Lib/test/test_pwd.py
+1
-1
Lib/test/test_pyexpat.py
Lib/test/test_pyexpat.py
+5
-5
Lib/test/test_re.py
Lib/test/test_re.py
+1
-1
Lib/test/test_regex.py
Lib/test/test_regex.py
+3
-3
Lib/test/test_rgbimg.py
Lib/test/test_rgbimg.py
+18
-18
Lib/test/test_sax.py
Lib/test/test_sax.py
+16
-17
Lib/test/test_select.py
Lib/test/test_select.py
+24
-25
Lib/test/test_signal.py
Lib/test/test_signal.py
+31
-31
Lib/test/test_string.py
Lib/test/test_string.py
+1
-2
Lib/test/test_strop.py
Lib/test/test_strop.py
+1
-1
Lib/test/test_struct.py
Lib/test/test_struct.py
+1
-1
Lib/test/test_support.py
Lib/test/test_support.py
+47
-47
Lib/test/test_thread.py
Lib/test/test_thread.py
+70
-70
Lib/test/test_tokenize.py
Lib/test/test_tokenize.py
+0
-1
Lib/test/test_types.py
Lib/test/test_types.py
+13
-13
Lib/test/test_ucn.py
Lib/test/test_ucn.py
+13
-14
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+42
-43
Lib/test/test_unicodedata.py
Lib/test/test_unicodedata.py
+5
-5
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+0
-2
Lib/test/test_winreg.py
Lib/test/test_winreg.py
+0
-1
Lib/test/test_winsound.py
Lib/test/test_winsound.py
+0
-1
Lib/test/test_xmllib.py
Lib/test/test_xmllib.py
+3
-3
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+16
-17
Lib/test/test_zlib.py
Lib/test/test_zlib.py
+7
-8
No files found.
Lib/test/pystone.py
View file @
004d5e68
This diff is collapsed.
Click to expand it.
Lib/test/regex_tests.py
View file @
004d5e68
# Regex test suite and benchmark suite v1.5a2
# Due to the use of r"aw" strings, this file will
# Due to the use of r"aw" strings, this file will
# only work with Python 1.5 or higher.
# The 3 possible outcomes for each pattern
...
...
@@ -9,22 +8,22 @@
# Benchmark suite (needs expansion)
#
# The benchmark suite does not test correctness, just speed. The
# first element of each tuple is the regex pattern; the second is a
# first element of each tuple is the regex pattern; the second is a
# string to match it against. The benchmarking code will embed the
# second string inside several sizes of padding, to test how regex
# second string inside several sizes of padding, to test how regex
# matching performs on large strings.
benchmarks
=
[
(
'Python'
,
'Python'
),
# Simple text literal
(
'.*Python'
,
'Python'
),
# Bad text literal
(
'Python'
,
'Python'
),
# Simple text literal
(
'.*Python'
,
'Python'
),
# Bad text literal
(
'.*Python.*'
,
'Python'
),
# Worse text literal
(
'.*
\
\
(Python
\
\
)'
,
'Python'
),
# Bad text literal with grouping
(
'.*
\
\
(Python
\
\
)'
,
'Python'
),
# Bad text literal with grouping
(
'(Python
\
\
|Perl
\
\
|Tcl'
,
'Perl'
),
# Alternation
(
'
\
\
(Python
\
\
|Perl
\
\
|Tcl
\
\
)'
,
'Perl'
),
# Grouped alternation
(
'
\
\
(Python
\
\
)
\
\
1'
,
'PythonPython'
),
# Backreference
#
('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization
(
'
\
\
([a-z][a-z0-9]*,
\
\
)+'
,
'a5,b7,c9,'
)
# A few sets
(
'(Python
\
\
|Perl
\
\
|Tcl'
,
'Perl'
),
# Alternation
(
'
\
\
(Python
\
\
|Perl
\
\
|Tcl
\
\
)'
,
'Perl'
),
# Grouped alternation
(
'
\
\
(Python
\
\
)
\
\
1'
,
'PythonPython'
),
# Backreference
#
('\\([0a-z][a-z]*,\\)+', 'a5,b7,c9,'), # Disable the fastmap optimization
(
'
\
\
([a-z][a-z0-9]*,
\
\
)+'
,
'a5,b7,c9,'
)
# A few sets
]
# Test suite (for verifying correctness)
...
...
@@ -286,4 +285,3 @@ tests = [
('
a
\
>
', '
a
!
', SUCCEED, '
found
', '
a
'),
('
a
\
>
', '
a
', SUCCEED, '
found
', '
a
'),
]
Lib/test/regrtest.py
View file @
004d5e68
...
...
@@ -46,14 +46,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
"""Execute a test suite.
This also parses command-line options and modifies its behavior
accordingly.
accordingly.
tests -- a list of strings containing test names (optional)
testdir -- the directory in which to look for tests (optional)
Users other than the Python test suite will certainly want to
specify testdir; if it's omitted, the directory containing the
Python test suite is searched for.
Python test suite is searched for.
If the tests argument is omitted, the tests listed on the
command-line will be used. If that's empty, too, then all *.py
...
...
@@ -65,7 +65,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
command line.
"""
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'vgqxsrl'
,
[
'have-resources'
])
except
getopt
.
error
,
msg
:
...
...
Lib/test/test_MimeWriter.py
View file @
004d5e68
...
...
@@ -81,7 +81,7 @@ def main():
import
sys
# Toplevel headers
toplevel
=
MimeWriter
(
sys
.
stdout
)
toplevel
.
addheader
(
"From"
,
"bwarsaw@cnri.reston.va.us"
)
toplevel
.
addheader
(
"Date"
,
"Mon Feb 12 17:21:48 EST 1996"
)
...
...
@@ -89,7 +89,7 @@ def main():
toplevel
.
addheader
(
"MIME-Version"
,
"1.0"
)
# Toplevel body parts
f
=
toplevel
.
startmultipartbody
(
"knowbot"
,
"801spam999"
,
[(
"version"
,
"0.1"
)],
prefix
=
0
)
f
.
write
(
"This is a multi-part message in MIME format.
\
n
"
)
...
...
@@ -100,7 +100,7 @@ def main():
md
.
startmultipartbody
(
"knowbot-metadata"
,
"802spam999"
)
# Metadata part 1
md1
=
md
.
nextpart
()
md1
.
addheader
(
"KP-Metadata-Type"
,
"simple"
)
md1
.
addheader
(
"KP-Access"
,
"read-only"
)
...
...
Lib/test/test_al.py
View file @
004d5e68
...
...
@@ -21,4 +21,3 @@ def main():
getattr
(
al
,
attr
)
main
()
Lib/test/test_array.py
View file @
004d5e68
This diff is collapsed.
Click to expand it.
Lib/test/test_augassign.py
View file @
004d5e68
# Augmented assignment test.
x
=
2
...
...
@@ -55,29 +54,29 @@ print x
print
x
is
y
class
aug_test
:
def
__init__
(
self
,
value
):
self
.
val
=
value
def
__radd__
(
self
,
val
):
return
self
.
val
+
val
def
__add__
(
self
,
val
):
return
aug_test
(
self
.
val
+
val
)
def
__init__
(
self
,
value
):
self
.
val
=
value
def
__radd__
(
self
,
val
):
return
self
.
val
+
val
def
__add__
(
self
,
val
):
return
aug_test
(
self
.
val
+
val
)
class
aug_test2
(
aug_test
):
def
__iadd__
(
self
,
val
):
self
.
val
=
self
.
val
+
val
return
self
def
__iadd__
(
self
,
val
):
self
.
val
=
self
.
val
+
val
return
self
class
aug_test3
(
aug_test
):
def
__iadd__
(
self
,
val
):
return
aug_test3
(
self
.
val
+
val
)
def
__iadd__
(
self
,
val
):
return
aug_test3
(
self
.
val
+
val
)
x
=
aug_test
(
1
)
y
=
x
x
+=
10
print
isinstance
(
x
,
aug_test
)
print
y
is
not
x
print
y
is
not
x
print
x
.
val
x
=
aug_test2
(
2
)
...
...
@@ -97,93 +96,93 @@ print x.val
class
testall
:
def
__add__
(
self
,
val
):
print
"__add__ called"
def
__radd__
(
self
,
val
):
print
"__radd__ called"
def
__iadd__
(
self
,
val
):
print
"__iadd__ called"
return
self
def
__sub__
(
self
,
val
):
print
"__sub__ called"
def
__rsub__
(
self
,
val
):
print
"__rsub__ called"
def
__isub__
(
self
,
val
):
print
"__isub__ called"
return
self
def
__mul__
(
self
,
val
):
print
"__mul__ called"
def
__rmul__
(
self
,
val
):
print
"__rmul__ called"
def
__imul__
(
self
,
val
):
print
"__imul__ called"
return
self
def
__div__
(
self
,
val
):
print
"__div__ called"
def
__rdiv__
(
self
,
val
):
print
"__rdiv__ called"
def
__idiv__
(
self
,
val
):
print
"__idiv__ called"
return
self
def
__mod__
(
self
,
val
):
print
"__mod__ called"
def
__rmod__
(
self
,
val
):
print
"__rmod__ called"
def
__imod__
(
self
,
val
):
print
"__imod__ called"
return
self
def
__pow__
(
self
,
val
):
print
"__pow__ called"
def
__rpow__
(
self
,
val
):
print
"__rpow__ called"
def
__ipow__
(
self
,
val
):
print
"__ipow__ called"
return
self
def
__or__
(
self
,
val
):
print
"__or__ called"
def
__ror__
(
self
,
val
):
print
"__ror__ called"
def
__ior__
(
self
,
val
):
print
"__ior__ called"
return
self
def
__and__
(
self
,
val
):
print
"__and__ called"
def
__rand__
(
self
,
val
):
print
"__rand__ called"
def
__iand__
(
self
,
val
):
print
"__iand__ called"
return
self
def
__xor__
(
self
,
val
):
print
"__xor__ called"
def
__rxor__
(
self
,
val
):
print
"__rxor__ called"
def
__ixor__
(
self
,
val
):
print
"__ixor__ called"
return
self
def
__rshift__
(
self
,
val
):
print
"__rshift__ called"
def
__rrshift__
(
self
,
val
):
print
"__rrshift__ called"
def
__irshift__
(
self
,
val
):
print
"__irshift__ called"
return
self
def
__lshift__
(
self
,
val
):
print
"__lshift__ called"
def
__rlshift__
(
self
,
val
):
print
"__rlshift__ called"
def
__ilshift__
(
self
,
val
):
print
"__ilshift__ called"
return
self
def
__add__
(
self
,
val
):
print
"__add__ called"
def
__radd__
(
self
,
val
):
print
"__radd__ called"
def
__iadd__
(
self
,
val
):
print
"__iadd__ called"
return
self
def
__sub__
(
self
,
val
):
print
"__sub__ called"
def
__rsub__
(
self
,
val
):
print
"__rsub__ called"
def
__isub__
(
self
,
val
):
print
"__isub__ called"
return
self
def
__mul__
(
self
,
val
):
print
"__mul__ called"
def
__rmul__
(
self
,
val
):
print
"__rmul__ called"
def
__imul__
(
self
,
val
):
print
"__imul__ called"
return
self
def
__div__
(
self
,
val
):
print
"__div__ called"
def
__rdiv__
(
self
,
val
):
print
"__rdiv__ called"
def
__idiv__
(
self
,
val
):
print
"__idiv__ called"
return
self
def
__mod__
(
self
,
val
):
print
"__mod__ called"
def
__rmod__
(
self
,
val
):
print
"__rmod__ called"
def
__imod__
(
self
,
val
):
print
"__imod__ called"
return
self
def
__pow__
(
self
,
val
):
print
"__pow__ called"
def
__rpow__
(
self
,
val
):
print
"__rpow__ called"
def
__ipow__
(
self
,
val
):
print
"__ipow__ called"
return
self
def
__or__
(
self
,
val
):
print
"__or__ called"
def
__ror__
(
self
,
val
):
print
"__ror__ called"
def
__ior__
(
self
,
val
):
print
"__ior__ called"
return
self
def
__and__
(
self
,
val
):
print
"__and__ called"
def
__rand__
(
self
,
val
):
print
"__rand__ called"
def
__iand__
(
self
,
val
):
print
"__iand__ called"
return
self
def
__xor__
(
self
,
val
):
print
"__xor__ called"
def
__rxor__
(
self
,
val
):
print
"__rxor__ called"
def
__ixor__
(
self
,
val
):
print
"__ixor__ called"
return
self
def
__rshift__
(
self
,
val
):
print
"__rshift__ called"
def
__rrshift__
(
self
,
val
):
print
"__rrshift__ called"
def
__irshift__
(
self
,
val
):
print
"__irshift__ called"
return
self
def
__lshift__
(
self
,
val
):
print
"__lshift__ called"
def
__rlshift__
(
self
,
val
):
print
"__rlshift__ called"
def
__ilshift__
(
self
,
val
):
print
"__ilshift__ called"
return
self
x
=
testall
()
x
+
1
...
...
@@ -229,4 +228,3 @@ x >>= 1
x
<<
1
1
<<
x
x
<<=
1
Lib/test/test_b2.py
View file @
004d5e68
...
...
@@ -6,35 +6,35 @@ print 'oct'
if
oct
(
100
)
!=
'0144'
:
raise
TestFailed
,
'oct(100)'
if
oct
(
100L
)
!=
'0144L'
:
raise
TestFailed
,
'oct(100L)'
if
oct
(
-
100
)
not
in
(
'037777777634'
,
'01777777777777777777634'
):
raise
TestFailed
,
'oct(-100)'
raise
TestFailed
,
'oct(-100)'
if
oct
(
-
100L
)
!=
'-0144L'
:
raise
TestFailed
,
'oct(-100L)'
print
'open'
# NB the first 4 lines are also used to test input and raw_input, below
fp
=
open
(
TESTFN
,
'w'
)
try
:
fp
.
write
(
'1+1
\
n
'
)
fp
.
write
(
'1+1
\
n
'
)
fp
.
write
(
'The quick brown fox jumps over the lazy dog'
)
fp
.
write
(
'.
\
n
'
)
fp
.
write
(
'Dear John
\
n
'
)
fp
.
write
(
'XXX'
*
100
)
fp
.
write
(
'YYY'
*
100
)
fp
.
write
(
'1+1
\
n
'
)
fp
.
write
(
'1+1
\
n
'
)
fp
.
write
(
'The quick brown fox jumps over the lazy dog'
)
fp
.
write
(
'.
\
n
'
)
fp
.
write
(
'Dear John
\
n
'
)
fp
.
write
(
'XXX'
*
100
)
fp
.
write
(
'YYY'
*
100
)
finally
:
fp
.
close
()
fp
.
close
()
#
fp
=
open
(
TESTFN
,
'r'
)
try
:
if
fp
.
readline
(
4
)
<>
'1+1
\
n
'
:
raise
TestFailed
,
'readline(4) # exact'
if
fp
.
readline
(
4
)
<>
'1+1
\
n
'
:
raise
TestFailed
,
'readline(4) # exact'
if
fp
.
readline
()
<>
'The quick brown fox jumps over the lazy dog.
\
n
'
:
raise
TestFailed
,
'readline() # default'
if
fp
.
readline
(
4
)
<>
'Dear'
:
raise
TestFailed
,
'readline(4) # short'
if
fp
.
readline
(
100
)
<>
' John
\
n
'
:
raise
TestFailed
,
'readline(100)'
if
fp
.
read
(
300
)
<>
'XXX'
*
100
:
raise
TestFailed
,
'read(300)'
if
fp
.
read
(
1000
)
<>
'YYY'
*
100
:
raise
TestFailed
,
'read(1000) # truncate'
if
fp
.
readline
(
4
)
<>
'1+1
\
n
'
:
raise
TestFailed
,
'readline(4) # exact'
if
fp
.
readline
(
4
)
<>
'1+1
\
n
'
:
raise
TestFailed
,
'readline(4) # exact'
if
fp
.
readline
()
<>
'The quick brown fox jumps over the lazy dog.
\
n
'
:
raise
TestFailed
,
'readline() # default'
if
fp
.
readline
(
4
)
<>
'Dear'
:
raise
TestFailed
,
'readline(4) # short'
if
fp
.
readline
(
100
)
<>
' John
\
n
'
:
raise
TestFailed
,
'readline(100)'
if
fp
.
read
(
300
)
<>
'XXX'
*
100
:
raise
TestFailed
,
'read(300)'
if
fp
.
read
(
1000
)
<>
'YYY'
*
100
:
raise
TestFailed
,
'read(1000) # truncate'
finally
:
fp
.
close
()
fp
.
close
()
print
'ord'
if
ord
(
' '
)
<>
32
:
raise
TestFailed
,
'ord(
\
'
\
'
)'
...
...
@@ -89,10 +89,10 @@ if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)'
#if fcmp(pow(-2.,3), -8.): raise TestFailed, 'pow(-2.,3)'
#
for
x
in
2
,
2L
,
2.0
:
for
y
in
10
,
10L
,
10.0
:
for
z
in
1000
,
1000L
,
1000.0
:
if
fcmp
(
pow
(
x
,
y
,
z
),
24.0
):
raise
TestFailed
,
'pow(%s, %s, %s)'
%
(
x
,
y
,
z
)
for
y
in
10
,
10L
,
10.0
:
for
z
in
1000
,
1000L
,
1000.0
:
if
fcmp
(
pow
(
x
,
y
,
z
),
24.0
):
raise
TestFailed
,
'pow(%s, %s, %s)'
%
(
x
,
y
,
z
)
print
'range'
if
range
(
3
)
<>
[
0
,
1
,
2
]:
raise
TestFailed
,
'range(3)'
...
...
@@ -107,45 +107,45 @@ import sys
fp
=
open
(
TESTFN
,
'r'
)
savestdin
=
sys
.
stdin
try
:
sys
.
stdin
=
fp
if
input
()
<>
2
:
raise
TestFailed
,
'input()'
if
input
(
'testing
\
n
'
)
<>
2
:
raise
TestFailed
,
'input()'
if
raw_input
()
<>
'The quick brown fox jumps over the lazy dog.'
:
raise
TestFailed
,
'raw_input()'
if
raw_input
(
'testing
\
n
'
)
<>
'Dear John'
:
raise
TestFailed
,
'raw_input(
\
'
testing
\
\
n
\
'
)'
sys
.
stdin
=
fp
if
input
()
<>
2
:
raise
TestFailed
,
'input()'
if
input
(
'testing
\
n
'
)
<>
2
:
raise
TestFailed
,
'input()'
if
raw_input
()
<>
'The quick brown fox jumps over the lazy dog.'
:
raise
TestFailed
,
'raw_input()'
if
raw_input
(
'testing
\
n
'
)
<>
'Dear John'
:
raise
TestFailed
,
'raw_input(
\
'
testing
\
\
n
\
'
)'
finally
:
sys
.
stdin
=
savestdin
fp
.
close
()
sys
.
stdin
=
savestdin
fp
.
close
()
print
'reduce'
if
reduce
(
lambda
x
,
y
:
x
+
y
,
[
'a'
,
'b'
,
'c'
],
''
)
<>
'abc'
:
raise
TestFailed
,
'reduce(): implode a string'
raise
TestFailed
,
'reduce(): implode a string'
if
reduce
(
lambda
x
,
y
:
x
+
y
,
[[
'a'
,
'c'
],
[],
[
'd'
,
'w'
]],
[])
<>
[
'a'
,
'c'
,
'd'
,
'w'
]:
raise
TestFailed
,
'reduce(): append'
[[
'a'
,
'c'
],
[],
[
'd'
,
'w'
]],
[])
<>
[
'a'
,
'c'
,
'd'
,
'w'
]:
raise
TestFailed
,
'reduce(): append'
if
reduce
(
lambda
x
,
y
:
x
*
y
,
range
(
2
,
8
),
1
)
<>
5040
:
raise
TestFailed
,
'reduce(): compute 7!'
raise
TestFailed
,
'reduce(): compute 7!'
if
reduce
(
lambda
x
,
y
:
x
*
y
,
range
(
2
,
21
),
1L
)
<>
2432902008176640000L
:
raise
TestFailed
,
'reduce(): compute 20!, use long'
raise
TestFailed
,
'reduce(): compute 20!, use long'
class
Squares
:
def
__init__
(
self
,
max
):
self
.
max
=
max
self
.
sofar
=
[]
def
__len__
(
self
):
return
len
(
self
.
sofar
)
def
__getitem__
(
self
,
i
):
if
not
0
<=
i
<
self
.
max
:
raise
IndexError
n
=
len
(
self
.
sofar
)
while
n
<=
i
:
self
.
sofar
.
append
(
n
*
n
)
n
=
n
+
1
return
self
.
sofar
[
i
]
def
__init__
(
self
,
max
):
self
.
max
=
max
self
.
sofar
=
[]
def
__len__
(
self
):
return
len
(
self
.
sofar
)
def
__getitem__
(
self
,
i
):
if
not
0
<=
i
<
self
.
max
:
raise
IndexError
n
=
len
(
self
.
sofar
)
while
n
<=
i
:
self
.
sofar
.
append
(
n
*
n
)
n
=
n
+
1
return
self
.
sofar
[
i
]
if
reduce
(
lambda
x
,
y
:
x
+
y
,
Squares
(
10
))
!=
285
:
raise
TestFailed
,
'reduce(<+>, Squares(10))'
raise
TestFailed
,
'reduce(<+>, Squares(10))'
if
reduce
(
lambda
x
,
y
:
x
+
y
,
Squares
(
10
),
0
)
!=
285
:
raise
TestFailed
,
'reduce(<+>, Squares(10), 0)'
raise
TestFailed
,
'reduce(<+>, Squares(10), 0)'
if
reduce
(
lambda
x
,
y
:
x
+
y
,
Squares
(
0
),
0
)
!=
0
:
raise
TestFailed
,
'reduce(<+>, Squares(0), 0)'
raise
TestFailed
,
'reduce(<+>, Squares(0), 0)'
print
'reload'
...
...
@@ -171,35 +171,35 @@ if round(0.0) <> 0.0: raise TestFailed, 'round(0.0)'
if
round
(
1.0
)
<>
1.0
:
raise
TestFailed
,
'round(1.0)'
if
round
(
10.0
)
<>
10.0
:
raise
TestFailed
,
'round(10.0)'
if
round
(
1000000000.0
)
<>
1000000000.0
:
raise
TestFailed
,
'round(1000000000.0)'
raise
TestFailed
,
'round(1000000000.0)'
if
round
(
1e20
)
<>
1e20
:
raise
TestFailed
,
'round(1e20)'
if
round
(
-
1.0
)
<>
-
1.0
:
raise
TestFailed
,
'round(-1.0)'
if
round
(
-
10.0
)
<>
-
10.0
:
raise
TestFailed
,
'round(-10.0)'
if
round
(
-
1000000000.0
)
<>
-
1000000000.0
:
raise
TestFailed
,
'round(-1000000000.0)'
raise
TestFailed
,
'round(-1000000000.0)'
if
round
(
-
1e20
)
<>
-
1e20
:
raise
TestFailed
,
'round(-1e20)'
if
round
(
0.1
)
<>
0.0
:
raise
TestFailed
,
'round(0.0)'
if
round
(
1.1
)
<>
1.0
:
raise
TestFailed
,
'round(1.0)'
if
round
(
10.1
)
<>
10.0
:
raise
TestFailed
,
'round(10.0)'
if
round
(
1000000000.1
)
<>
1000000000.0
:
raise
TestFailed
,
'round(1000000000.0)'
raise
TestFailed
,
'round(1000000000.0)'
if
round
(
-
1.1
)
<>
-
1.0
:
raise
TestFailed
,
'round(-1.0)'
if
round
(
-
10.1
)
<>
-
10.0
:
raise
TestFailed
,
'round(-10.0)'
if
round
(
-
1000000000.1
)
<>
-
1000000000.0
:
raise
TestFailed
,
'round(-1000000000.0)'
raise
TestFailed
,
'round(-1000000000.0)'
if
round
(
0.9
)
<>
1.0
:
raise
TestFailed
,
'round(0.9)'
if
round
(
9.9
)
<>
10.0
:
raise
TestFailed
,
'round(9.9)'
if
round
(
999999999.9
)
<>
1000000000.0
:
raise
TestFailed
,
'round(999999999.9)'
raise
TestFailed
,
'round(999999999.9)'
if
round
(
-
0.9
)
<>
-
1.0
:
raise
TestFailed
,
'round(-0.9)'
if
round
(
-
9.9
)
<>
-
10.0
:
raise
TestFailed
,
'round(-9.9)'
if
round
(
-
999999999.9
)
<>
-
1000000000.0
:
raise
TestFailed
,
'round(-999999999.9)'
raise
TestFailed
,
'round(-999999999.9)'
print
'setattr'
import
sys
...
...
@@ -224,7 +224,7 @@ if tuple('spam') <> ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')"
print
'type'
if
type
(
''
)
<>
type
(
'123'
)
or
type
(
''
)
==
type
(()):
raise
TestFailed
,
'type()'
raise
TestFailed
,
'type()'
print
'vars'
a
=
b
=
None
...
...
@@ -240,20 +240,20 @@ a.sort()
b
.
sort
()
if
a
<>
b
:
raise
TestFailed
,
'vars(sys)'
def
f0
():
if
vars
()
!=
{}:
raise
TestFailed
,
'vars() in f0()'
if
vars
()
!=
{}:
raise
TestFailed
,
'vars() in f0()'
f0
()
def
f2
():
f0
()
a
=
1
b
=
2
if
vars
()
!=
{
'a'
:
a
,
'b'
:
b
}:
raise
TestFailed
,
'vars() in f2()'
f0
()
a
=
1
b
=
2
if
vars
()
!=
{
'a'
:
a
,
'b'
:
b
}:
raise
TestFailed
,
'vars() in f2()'
f2
()
print
'xrange'
if
tuple
(
xrange
(
10
))
<>
tuple
(
range
(
10
)):
raise
TestFailed
,
'xrange(10)'
if
tuple
(
xrange
(
5
,
10
))
<>
tuple
(
range
(
5
,
10
)):
raise
TestFailed
,
'xrange(5,10)'
if
tuple
(
xrange
(
0
,
10
,
2
))
<>
tuple
(
range
(
0
,
10
,
2
)):
raise
TestFailed
,
'xrange(0,10,2)'
raise
TestFailed
,
'xrange(0,10,2)'
print
'zip'
a
=
(
1
,
2
,
3
)
...
...
@@ -265,43 +265,43 @@ if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, tuple/list'
b
=
(
4
,
5
,
6
,
7
)
if
zip
(
a
,
b
)
<>
t
:
raise
TestFailed
,
'zip(a, b) - b is longer'
class
I
:
def
__getitem__
(
self
,
i
):
if
i
<
0
or
i
>
2
:
raise
IndexError
return
i
+
4
def
__getitem__
(
self
,
i
):
if
i
<
0
or
i
>
2
:
raise
IndexError
return
i
+
4
if
zip
(
a
,
I
())
<>
t
:
raise
TestFailed
,
'zip(a, b) - b is instance'
exc
=
0
try
:
zip
()
zip
()
except
TypeError
:
exc
=
1
exc
=
1
except
:
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip() - no args, expected TypeError, got %s'
%
e
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip() - no args, expected TypeError, got %s'
%
e
if
not
exc
:
raise
TestFailed
,
'zip() - no args, missing expected TypeError'
raise
TestFailed
,
'zip() - no args, missing expected TypeError'
exc
=
0
try
:
zip
(
None
)
zip
(
None
)
except
TypeError
:
exc
=
1
exc
=
1
except
:
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip(None) - expected TypeError, got %s'
%
e
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip(None) - expected TypeError, got %s'
%
e
if
not
exc
:
raise
TestFailed
,
'zip(None) - missing expected TypeError'
raise
TestFailed
,
'zip(None) - missing expected TypeError'
class
G
:
pass
pass
exc
=
0
try
:
zip
(
a
,
G
())
zip
(
a
,
G
())
except
AttributeError
:
exc
=
1
exc
=
1
except
:
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip(a, b) - b instance w/o __getitem__'
e
=
sys
.
exc_info
()[
0
]
raise
TestFailed
,
'zip(a, b) - b instance w/o __getitem__'
if
not
exc
:
raise
TestFailed
,
'zip(a, b) - missing expected AttributeError'
raise
TestFailed
,
'zip(a, b) - missing expected AttributeError'
# Epilogue -- unlink the temp file
...
...
Lib/test/test_binhex.py
View file @
004d5e68
...
...
@@ -20,7 +20,7 @@ def test():
start
=
'Jack is my hero'
f
.
write
(
start
)
f
.
close
()
binhex
.
binhex
(
fname1
,
fname2
)
if
verbose
:
print
'binhex'
...
...
Lib/test/test_bsddb.py
View file @
004d5e68
...
...
@@ -12,7 +12,7 @@ def test(openmethod, what):
if
verbose
:
print
'
\
n
Testing: '
,
what
fname
=
tempfile
.
mktemp
()
f
=
openmethod
(
fname
,
'c'
)
if
verbose
:
...
...
Lib/test/test_cfgparser.py
View file @
004d5e68
...
...
@@ -110,7 +110,7 @@ basic(r"""
[Foo Bar]
foo=bar
[Spacey Bar]
foo = bar
foo = bar
[Commented Bar]
foo: bar ; comment
"""
)
...
...
Lib/test/test_cgi.py
View file @
004d5e68
...
...
@@ -4,7 +4,7 @@ import sys
class
HackedSysModule
:
# The regression test will have real values in sys.argv, which
# will completely confuse the test of the cgi module
# will completely confuse the test of the cgi module
argv
=
[]
stdin
=
sys
.
stdin
...
...
@@ -53,7 +53,7 @@ def do_test(buf, method):
# A list of test cases. Each test case is a a two-tuple that contains
# a string with the query and a dictionary with the expected result.
parse_test_cases
=
[
(
""
,
ValueError
(
"bad query field: ''"
)),
(
"&"
,
ValueError
(
"bad query field: ''"
)),
...
...
@@ -90,7 +90,7 @@ parse_test_cases = [
'ss'
:
[
'env'
],
'view'
:
[
'bustomer'
],
}),
(
"group_id=5470&set=custom&_assigned_to=31392&_status=1&_category=100&SUBMIT=Browse"
,
{
'SUBMIT'
:
[
'Browse'
],
'_assigned_to'
:
[
'31392'
],
...
...
Lib/test/test_class.py
View file @
004d5e68
...
...
@@ -67,7 +67,7 @@ testmeths = [
class
AllTests
:
def
__coerce__
(
self
,
*
args
):
print
"__coerce__:"
,
args
return
(
self
,)
+
args
return
(
self
,)
+
args
def
__hash__
(
self
,
*
args
):
print
"__hash__:"
,
args
...
...
@@ -202,18 +202,17 @@ del testme
# Interfering tests
class
ExtraTests
:
def
__getattr__
(
self
,
*
args
):
print
"__getattr__:"
,
args
return
"SomeVal"
def
__getattr__
(
self
,
*
args
):
print
"__getattr__:"
,
args
return
"SomeVal"
def
__setattr__
(
self
,
*
args
):
print
"__setattr__:"
,
args
def
__setattr__
(
self
,
*
args
):
print
"__setattr__:"
,
args
def
__delattr__
(
self
,
*
args
):
print
"__delattr__:"
,
args
def
__delattr__
(
self
,
*
args
):
print
"__delattr__:"
,
args
testme
=
ExtraTests
()
testme
.
spam
testme
.
eggs
=
"spam, spam, spam and ham"
del
testme
.
cardinal
Lib/test/test_contains.py
View file @
004d5e68
...
...
@@ -2,18 +2,18 @@ from test_support import TestFailed
class
base_set
:
def
__init__
(
self
,
el
):
self
.
el
=
el
def
__init__
(
self
,
el
):
self
.
el
=
el
class
set
(
base_set
):
def
__contains__
(
self
,
el
):
return
self
.
el
==
el
def
__contains__
(
self
,
el
):
return
self
.
el
==
el
class
seq
(
base_set
):
def
__getitem__
(
self
,
n
):
return
[
self
.
el
][
n
]
def
__getitem__
(
self
,
n
):
return
[
self
.
el
][
n
]
def
check
(
ok
,
*
args
):
if
not
ok
:
...
...
@@ -29,16 +29,16 @@ check(1 in c, "1 not in seq(1)")
check
(
0
not
in
c
,
"0 in seq(1)"
)
try
:
1
in
a
check
(
0
,
"in base_set did not raise error"
)
1
in
a
check
(
0
,
"in base_set did not raise error"
)
except
AttributeError
:
pass
pass
try
:
1
not
in
a
check
(
0
,
"not in base_set did not raise error"
)
1
not
in
a
check
(
0
,
"not in base_set did not raise error"
)
except
AttributeError
:
pass
pass
# Test char in string
...
...
@@ -46,22 +46,22 @@ check('c' in 'abc', "'c' not in 'abc'")
check
(
'd'
not
in
'abc'
,
"'d' in 'abc'"
)
try
:
''
in
'abc'
check
(
0
,
"'' in 'abc' did not raise error"
)
''
in
'abc'
check
(
0
,
"'' in 'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
'ab'
in
'abc'
check
(
0
,
"'ab' in 'abc' did not raise error"
)
'ab'
in
'abc'
check
(
0
,
"'ab' in 'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
None
in
'abc'
check
(
0
,
"None in 'abc' did not raise error"
)
None
in
'abc'
check
(
0
,
"None in 'abc' did not raise error"
)
except
TypeError
:
pass
pass
# Test char in Unicode
...
...
@@ -69,22 +69,22 @@ check('c' in u'abc', "'c' not in u'abc'")
check
(
'd'
not
in
u'abc'
,
"'d' in u'abc'"
)
try
:
''
in
u'abc'
check
(
0
,
"'' in u'abc' did not raise error"
)
''
in
u'abc'
check
(
0
,
"'' in u'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
'ab'
in
u'abc'
check
(
0
,
"'ab' in u'abc' did not raise error"
)
'ab'
in
u'abc'
check
(
0
,
"'ab' in u'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
None
in
u'abc'
check
(
0
,
"None in u'abc' did not raise error"
)
None
in
u'abc'
check
(
0
,
"None in u'abc' did not raise error"
)
except
TypeError
:
pass
pass
# Test Unicode char in Unicode
...
...
@@ -92,16 +92,16 @@ check(u'c' in u'abc', "u'c' not in u'abc'")
check
(
u'd'
not
in
u'abc'
,
"u'd' in u'abc'"
)
try
:
u''
in
u'abc'
check
(
0
,
"u'' in u'abc' did not raise error"
)
u''
in
u'abc'
check
(
0
,
"u'' in u'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
u'ab'
in
u'abc'
check
(
0
,
"u'ab' in u'abc' did not raise error"
)
u'ab'
in
u'abc'
check
(
0
,
"u'ab' in u'abc' did not raise error"
)
except
TypeError
:
pass
pass
# Test Unicode char in string
...
...
@@ -109,60 +109,60 @@ check(u'c' in 'abc', "u'c' not in 'abc'")
check
(
u'd'
not
in
'abc'
,
"u'd' in 'abc'"
)
try
:
u''
in
'abc'
check
(
0
,
"u'' in 'abc' did not raise error"
)
u''
in
'abc'
check
(
0
,
"u'' in 'abc' did not raise error"
)
except
TypeError
:
pass
pass
try
:
u'ab'
in
'abc'
check
(
0
,
"u'ab' in 'abc' did not raise error"
)
u'ab'
in
'abc'
check
(
0
,
"u'ab' in 'abc' did not raise error"
)
except
TypeError
:
pass
pass
# A collection of tests on builtin sequence types
a
=
range
(
10
)
for
i
in
a
:
check
(
i
in
a
,
"%s not in %s"
%
(
`i`
,
`a`
))
check
(
i
in
a
,
"%s not in %s"
%
(
`i`
,
`a`
))
check
(
16
not
in
a
,
"16 not in %s"
%
`a`
)
check
(
a
not
in
a
,
"%s not in %s"
%
(
`a`
,
`a`
))
a
=
tuple
(
a
)
for
i
in
a
:
check
(
i
in
a
,
"%s not in %s"
%
(
`i`
,
`a`
))
check
(
i
in
a
,
"%s not in %s"
%
(
`i`
,
`a`
))
check
(
16
not
in
a
,
"16 not in %s"
%
`a`
)
check
(
a
not
in
a
,
"%s not in %s"
%
(
`a`
,
`a`
))
class
Deviant1
:
"""Behaves strangely when compared
"""Behaves strangely when compared
This class is designed to make sure that the contains code
works when the list is modified during the check.
"""
This class is designed to make sure that the contains code
works when the list is modified during the check.
"""
aList
=
range
(
15
)
def
__cmp__
(
self
,
other
):
if
other
==
12
:
self
.
aList
.
remove
(
12
)
self
.
aList
.
remove
(
13
)
self
.
aList
.
remove
(
14
)
return
1
aList
=
range
(
15
)
def
__cmp__
(
self
,
other
):
if
other
==
12
:
self
.
aList
.
remove
(
12
)
self
.
aList
.
remove
(
13
)
self
.
aList
.
remove
(
14
)
return
1
check
(
Deviant1
()
not
in
Deviant1
.
aList
,
"Deviant1 failed"
)
class
Deviant2
:
"""Behaves strangely when compared
"""Behaves strangely when compared
This class raises an exception during comparison. That in
turn causes the comparison to fail with a TypeError.
"""
This class raises an exception during comparison. That in
turn causes the comparison to fail with a TypeError.
"""
def
__cmp__
(
self
,
other
):
if
other
==
4
:
raise
RuntimeError
,
"gotcha"
def
__cmp__
(
self
,
other
):
if
other
==
4
:
raise
RuntimeError
,
"gotcha"
try
:
check
(
Deviant2
()
not
in
a
,
"oops"
)
check
(
Deviant2
()
not
in
a
,
"oops"
)
except
TypeError
:
pass
pass
Lib/test/test_cookie.py
View file @
004d5e68
# Simple test suite for Cookie.py
import
Cookie
...
...
@@ -8,8 +7,8 @@ import Cookie
cases
=
[
(
'chips=ahoy; vienna=finger'
,
{
'chips'
:
'ahoy'
,
'vienna'
:
'finger'
}),
(
'keebler="E=mc2; L=
\
\
"Loves
\
\
"; fudge=
\
\
012;";'
,
{
'keebler'
:
'E=mc2; L="Loves"; fudge=
\
012
;'
}),
]
{
'keebler'
:
'E=mc2; L="Loves"; fudge=
\
012
;'
}),
]
for
data
,
dict
in
cases
:
C
=
Cookie
.
SimpleCookie
()
;
C
.
load
(
data
)
...
...
@@ -37,4 +36,3 @@ C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
assert
C
[
'Customer'
].
value
==
'WILE_E_COYOTE'
assert
C
[
'Customer'
][
'version'
]
==
'1'
assert
C
[
'Customer'
][
'path'
]
==
'/acme'
Lib/test/test_crypt.py
View file @
004d5e68
...
...
@@ -3,7 +3,7 @@
Roger E. Masse
"""
from
test_support
import
verbose
from
test_support
import
verbose
import
crypt
c
=
crypt
.
crypt
(
'mypassword'
,
'ab'
)
...
...
Lib/test/test_dospath.py
View file @
004d5e68
...
...
@@ -5,16 +5,16 @@ import os
errors
=
0
def
tester
(
fn
,
wantResult
):
fn
=
string
.
replace
(
fn
,
"
\
\
"
,
"
\
\
\
\
"
)
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
fn
=
string
.
replace
(
fn
,
"
\
\
"
,
"
\
\
\
\
"
)
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
tester
(
'dospath.splitdrive("c:
\
\
foo
\
\
bar")'
,
(
'c:'
,
'
\
\
foo
\
\
bar'
))
tester
(
'dospath.splitdrive("c:/foo/bar")'
,
(
'c:'
,
'/foo/bar'
))
...
...
@@ -43,7 +43,6 @@ tester('dospath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
"/home/swen/spam"
)
if
errors
:
print
str
(
errors
)
+
" errors."
print
str
(
errors
)
+
" errors."
else
:
print
"No errors. Thank your lucky stars."
print
"No errors. Thank your lucky stars."
Lib/test/test_extcall.py
View file @
004d5e68
...
...
@@ -27,21 +27,21 @@ except TypeError, err:
print
"TypeError:"
,
err
else
:
print
"should raise TypeError: not enough arguments; expected 1, got 0"
try
:
g
(
*
())
except
TypeError
,
err
:
print
"TypeError:"
,
err
else
:
print
"should raise TypeError: not enough arguments; expected 1, got 0"
try
:
g
(
*
(),
**
{})
except
TypeError
,
err
:
print
"TypeError:"
,
err
else
:
print
"should raise TypeError: not enough arguments; expected 1, got 0"
g
(
1
)
g
(
1
,
2
)
g
(
1
,
2
,
3
)
...
...
@@ -63,7 +63,7 @@ except AttributeError, attr:
pass
else
:
print
"should raise AttributeError: __getitem__"
class
Nothing
:
def
__len__
(
self
):
return
5
...
...
@@ -92,14 +92,14 @@ kw = saboteur(a=1, **d)
assert
d
==
{}
# break the cycle
del
kw
[
'x'
]
try
:
g
(
1
,
2
,
3
,
**
{
'x'
:
4
,
'y'
:
5
})
except
TypeError
,
err
:
print
err
else
:
print
"should raise TypeError: keyword parameter redefined"
try
:
g
(
1
,
2
,
3
,
a
=
4
,
b
=
5
,
*
(
6
,
7
),
**
{
'a'
:
8
,
'b'
:
9
})
except
TypeError
,
err
:
...
...
Lib/test/test_fcntl.py
View file @
004d5e68
...
...
@@ -15,7 +15,7 @@ f = open(filename, 'w')
rv
=
fcntl
.
fcntl
(
f
.
fileno
(),
FCNTL
.
F_SETFL
,
os
.
O_NONBLOCK
)
if
verbose
:
print
'Status from fnctl with O_NONBLOCK: '
,
rv
if
sys
.
platform
in
(
'netbsd1'
,
'Darwin1.2'
,
'freebsd2'
,
'freebsd3'
,
'freebsd4'
,
'freebsd5'
,
'bsdos2'
,
'bsdos3'
,
'bsdos4'
,
...
...
@@ -27,7 +27,7 @@ else:
lockdata
=
struct
.
pack
(
'hhllhh'
,
FCNTL
.
F_WRLCK
,
0
,
0
,
0
,
0
,
0
)
if
verbose
:
print
'struct.pack: '
,
`lockdata`
rv
=
fcntl
.
fcntl
(
f
.
fileno
(),
FCNTL
.
F_SETLKW
,
lockdata
)
if
verbose
:
print
'String from fcntl with F_SETLKW: '
,
`rv`
...
...
Lib/test/test_gc.py
View file @
004d5e68
...
...
@@ -134,15 +134,15 @@ def test_del():
gc
.
enable
()
gc
.
set_threshold
(
1
)
class
A
:
def
__del__
(
self
):
dir
(
self
)
class
A
:
def
__del__
(
self
):
dir
(
self
)
a
=
A
()
del
a
gc
.
disable
()
apply
(
gc
.
set_threshold
,
thresholds
)
def
test_all
():
run_test
(
"lists"
,
test_list
)
...
...
@@ -161,7 +161,7 @@ def test():
print
"disabling automatic collection"
enabled
=
gc
.
isenabled
()
gc
.
disable
()
assert
not
gc
.
isenabled
()
assert
not
gc
.
isenabled
()
debug
=
gc
.
get_debug
()
gc
.
set_debug
(
debug
&
~
gc
.
DEBUG_LEAK
)
# this test is supposed to leak
...
...
Lib/test/test_gdbm.py
View file @
004d5e68
...
...
@@ -2,7 +2,7 @@
"""Test script for the gdbm module
Roger E. Masse
"""
import
gdbm
from
gdbm
import
error
from
test_support
import
verbose
,
TestFailed
...
...
@@ -15,7 +15,7 @@ g['12345678910'] = '019237410982340912840198242'
a
=
g
.
keys
()
if
verbose
:
print
'Test gdbm file keys: '
,
a
g
.
has_key
(
'a'
)
g
.
close
()
try
:
...
...
Lib/test/test_gettext.py
View file @
004d5e68
...
...
@@ -2,7 +2,7 @@ import os
import
base64
import
gettext
def
test_api_1
(
localedir
,
mofile
):
print
'test api 1'
...
...
@@ -56,7 +56,7 @@ gettext message catalog library.''')
print
_
(
'mullusk'
)
def
test_api_2
(
localedir
,
mofile
):
print
'test api 2'
...
...
@@ -104,7 +104,7 @@ gettext message catalog library.''')
return
gettext
.
dgettext
(
'gettext'
)
GNU_MO_DATA
=
'''
\
3hIElQAAAAAFAAAAHAAAAEQAAAAHAAAAbAAAAAAAAACIAAAAFQAAAIkAAAChAAAAnwAAAAcAAABB
AQAACwAAAEkBAAAbAQAAVQEAABYAAABxAgAAoQAAAIgCAAAFAAAAKgMAAAkAAAAwAwAAAQAAAAQA
...
...
@@ -123,7 +123,7 @@ bCBjZWJpdnF2YXQgbmEgdmFncmVzbnByIGdiIGd1ciBUQUgKdHJnZ3JrZyB6cmZmbnRyIHBuZ255
YnQgeXZvZW5lbC4AYmFjb24Ad2luayB3aW5rAA==
'''
LOCALEDIR
=
os
.
path
.
join
(
'xx'
,
'LC_MESSAGES'
)
MOFILE
=
os
.
path
.
join
(
LOCALEDIR
,
'gettext.mo'
)
...
...
@@ -147,7 +147,7 @@ finally:
pass
# For reference, here's the .po file used to created the .mo data above.
'''
...
...
Lib/test/test_gl.py
View file @
004d5e68
...
...
@@ -146,5 +146,5 @@ def main():
if
verbose
:
print
'winclose'
gl
.
winclose
(
w
)
main
()
Lib/test/test_grammar.py
View file @
004d5e68
...
...
@@ -25,37 +25,37 @@ if 0xff <> 255: raise TestFailed, 'hex int'
if
0377
<>
255
:
raise
TestFailed
,
'octal int'
if
2147483647
!=
017777777777
:
raise
TestFailed
,
'large positive int'
try
:
from
sys
import
maxint
from
sys
import
maxint
except
ImportError
:
maxint
=
2147483647
maxint
=
2147483647
if
maxint
==
2147483647
:
if
-
2147483647
-
1
!=
020000000000
:
raise
TestFailed
,
'max negative int'
# XXX -2147483648
if
037777777777
!=
-
1
:
raise
TestFailed
,
'oct -1'
if
0xffffffff
!=
-
1
:
raise
TestFailed
,
'hex -1'
for
s
in
'2147483648'
,
'040000000000'
,
'0x100000000'
:
try
:
x
=
eval
(
s
)
except
OverflowError
:
continue
##
raise TestFailed, \
print
\
'No OverflowError on huge integer literal '
+
`s`
if
-
2147483647
-
1
!=
020000000000
:
raise
TestFailed
,
'max negative int'
# XXX -2147483648
if
037777777777
!=
-
1
:
raise
TestFailed
,
'oct -1'
if
0xffffffff
!=
-
1
:
raise
TestFailed
,
'hex -1'
for
s
in
'2147483648'
,
'040000000000'
,
'0x100000000'
:
try
:
x
=
eval
(
s
)
except
OverflowError
:
continue
##
raise TestFailed, \
print
\
'No OverflowError on huge integer literal '
+
`s`
elif
eval
(
'maxint == 9223372036854775807'
):
if
eval
(
'-9223372036854775807-1 != 01000000000000000000000'
):
raise
TestFailed
,
'max negative int'
if
eval
(
'01777777777777777777777'
)
!=
-
1
:
raise
TestFailed
,
'oct -1'
if
eval
(
'0xffffffffffffffff'
)
!=
-
1
:
raise
TestFailed
,
'hex -1'
for
s
in
'9223372036854775808'
,
'02000000000000000000000'
,
\
'0x10000000000000000'
:
try
:
x
=
eval
(
s
)
except
OverflowError
:
continue
raise
TestFailed
,
\
'No OverflowError on huge integer literal '
+
`s`
if
eval
(
'-9223372036854775807-1 != 01000000000000000000000'
):
raise
TestFailed
,
'max negative int'
if
eval
(
'01777777777777777777777'
)
!=
-
1
:
raise
TestFailed
,
'oct -1'
if
eval
(
'0xffffffffffffffff'
)
!=
-
1
:
raise
TestFailed
,
'hex -1'
for
s
in
'9223372036854775808'
,
'02000000000000000000000'
,
\
'0x10000000000000000'
:
try
:
x
=
eval
(
s
)
except
OverflowError
:
continue
raise
TestFailed
,
\
'No OverflowError on huge integer literal '
+
`s`
else
:
print
'Weird maxint value'
,
maxint
print
'Weird maxint value'
,
maxint
print
'1.1.2.2 Long integers'
x
=
0L
...
...
@@ -84,7 +84,7 @@ x = 3.1e4
print
'1.1.3 String literals'
##def assert(s):
##
if not s: raise TestFailed, 'see traceback'
##
if not s: raise TestFailed, 'see traceback'
x
=
''
;
y
=
""
;
assert
(
len
(
x
)
==
0
and
x
==
y
)
x
=
'
\
'
'
;
y
=
"'"
;
assert
(
len
(
x
)
==
1
and
x
==
y
and
ord
(
x
)
==
39
)
...
...
@@ -142,11 +142,11 @@ print 'funcdef'
### parameters: '(' [varargslist] ')'
### varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' ('**'|'*' '*') NAME]
### | ('**'|'*' '*') NAME)
### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
### fpdef: NAME | '(' fplist ')'
### fplist: fpdef (',' fpdef)* [',']
### arglist: (argument ',')* (argument | *' test [',' '**' test] | '**' test)
### argument: [test '='] test
# Really [keyword '='] test
### argument: [test '='] test
# Really [keyword '='] test
def
f1
():
pass
f1
()
f1
(
*
())
...
...
@@ -270,7 +270,7 @@ print >> sys.stdout, 0 or 1
# test printing to an instance
class
Gulp
:
def
write
(
self
,
msg
):
pass
def
write
(
self
,
msg
):
pass
gulp
=
Gulp
()
print
>>
gulp
,
1
,
2
,
3
...
...
@@ -281,34 +281,34 @@ print >> gulp, 0 or 1
# test print >> None
def
driver
():
oldstdout
=
sys
.
stdout
sys
.
stdout
=
Gulp
()
try
:
tellme
(
Gulp
())
tellme
()
finally
:
sys
.
stdout
=
oldstdout
oldstdout
=
sys
.
stdout
sys
.
stdout
=
Gulp
()
try
:
tellme
(
Gulp
())
tellme
()
finally
:
sys
.
stdout
=
oldstdout
# we should see this once
def
tellme
(
file
=
sys
.
stdout
):
print
>>
file
,
'hello world'
print
>>
file
,
'hello world'
driver
()
# we should not see this at all
def
tellme
(
file
=
None
):
print
>>
file
,
'goodbye universe'
print
>>
file
,
'goodbye universe'
driver
()
# syntax errors
def
check_syntax
(
statement
):
try
:
compile
(
statement
,
'<string>'
,
'exec'
)
except
SyntaxError
:
pass
else
:
print
'Missing SyntaxError: "%s"'
%
statement
try
:
compile
(
statement
,
'<string>'
,
'exec'
)
except
SyntaxError
:
pass
else
:
print
'Missing SyntaxError: "%s"'
%
statement
check_syntax
(
'print ,'
)
check_syntax
(
'print >> x,'
)
...
...
@@ -350,26 +350,26 @@ from sys import path, argv
print
'global_stmt'
# 'global' NAME (',' NAME)*
def
f
():
global
a
global
a
,
b
global
one
,
two
,
three
,
four
,
five
,
six
,
seven
,
eight
,
nine
,
ten
global
a
global
a
,
b
global
one
,
two
,
three
,
four
,
five
,
six
,
seven
,
eight
,
nine
,
ten
print
'exec_stmt'
# 'exec' expr ['in' expr [',' expr]]
def
f
():
z
=
None
del
z
exec
'z=1+1
\
n
'
if
z
<>
2
:
raise
TestFailed
,
'exec
\
'
z=1+1
\
'
\
\
n'
del
z
exec
'z=1+1'
if
z
<>
2
:
raise
TestFailed
,
'exec
\
'
z=1+1
\
'
'
z
=
None
del
z
exec
u'z=1+1
\
n
'
if
z
<>
2
:
raise
TestFailed
,
'exec u
\
'
z=1+1
\
'
\
\
n'
del
z
exec
u'z=1+1'
if
z
<>
2
:
raise
TestFailed
,
'exec u
\
'
z=1+1
\
'
'
z
=
None
del
z
exec
'z=1+1
\
n
'
if
z
<>
2
:
raise
TestFailed
,
'exec
\
'
z=1+1
\
'
\
\
n'
del
z
exec
'z=1+1'
if
z
<>
2
:
raise
TestFailed
,
'exec
\
'
z=1+1
\
'
'
z
=
None
del
z
exec
u'z=1+1
\
n
'
if
z
<>
2
:
raise
TestFailed
,
'exec u
\
'
z=1+1
\
'
\
\
n'
del
z
exec
u'z=1+1'
if
z
<>
2
:
raise
TestFailed
,
'exec u
\
'
z=1+1
\
'
'
f
()
g
=
{}
exec
'z = 1'
in
g
...
...
@@ -408,17 +408,17 @@ for i in 1, 2, 3: pass
for
i
,
j
,
k
in
():
pass
else
:
pass
class
Squares
:
def
__init__
(
self
,
max
):
self
.
max
=
max
self
.
sofar
=
[]
def
__len__
(
self
):
return
len
(
self
.
sofar
)
def
__getitem__
(
self
,
i
):
if
not
0
<=
i
<
self
.
max
:
raise
IndexError
n
=
len
(
self
.
sofar
)
while
n
<=
i
:
self
.
sofar
.
append
(
n
*
n
)
n
=
n
+
1
return
self
.
sofar
[
i
]
def
__init__
(
self
,
max
):
self
.
max
=
max
self
.
sofar
=
[]
def
__len__
(
self
):
return
len
(
self
.
sofar
)
def
__getitem__
(
self
,
i
):
if
not
0
<=
i
<
self
.
max
:
raise
IndexError
n
=
len
(
self
.
sofar
)
while
n
<=
i
:
self
.
sofar
.
append
(
n
*
n
)
n
=
n
+
1
return
self
.
sofar
[
i
]
n
=
0
for
x
in
Squares
(
10
):
n
=
n
+
x
if
n
!=
285
:
raise
TestFailed
,
'for over growing sequence'
...
...
@@ -428,11 +428,11 @@ print 'try_stmt'
### | 'try' ':' suite 'finally' ':' suite
### except_clause: 'except' [expr [',' expr]]
try
:
1
/
0
1
/
0
except
ZeroDivisionError
:
pass
pass
else
:
pass
pass
try
:
1
/
0
except
EOFError
:
pass
except
TypeError
,
msg
:
pass
...
...
@@ -449,16 +449,16 @@ finally: pass
print
'suite'
# simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT
if
1
:
pass
if
1
:
pass
pass
if
1
:
#
#
#
pass
pass
#
pass
#
#
#
#
pass
pass
#
pass
#
print
'test'
### and_test ('or' and_test)*
...
...
@@ -598,9 +598,9 @@ class C1(B): pass
class
C2
(
B
):
pass
class
D
(
C1
,
C2
,
B
):
pass
class
C
:
def
meth1
(
self
):
pass
def
meth2
(
self
,
arg
):
pass
def
meth3
(
self
,
a1
,
a2
):
pass
def
meth1
(
self
):
pass
def
meth2
(
self
,
arg
):
pass
def
meth3
(
self
,
a1
,
a2
):
pass
# list comprehension tests
nums
=
[
1
,
2
,
3
,
4
,
5
]
...
...
@@ -622,7 +622,7 @@ try:
eval
(
"[x if y]"
)
print
"FAIL: should have raised a SyntaxError!"
except
SyntaxError
:
print
"good: got a SyntaxError as expected"
print
"good: got a SyntaxError as expected"
suppliers
=
[
(
1
,
"Boeing"
),
...
...
Lib/test/test_grp.py
View file @
004d5e68
...
...
@@ -2,7 +2,7 @@
"""Test script for the grp module
Roger E. Masse
"""
import
grp
from
test_support
import
verbose
...
...
Lib/test/test_gzip.py
View file @
004d5e68
import
sys
,
os
import
gzip
,
tempfile
...
...
@@ -38,7 +37,7 @@ while 1:
line_length
=
(
line_length
+
1
)
%
50
f
.
close
()
# Try .readlines()
# Try .readlines()
f
=
gzip
.
GzipFile
(
filename
,
'rb'
)
L
=
f
.
readlines
()
...
...
@@ -47,7 +46,7 @@ f.close()
f
=
gzip
.
GzipFile
(
filename
,
'rb'
)
while
1
:
L
=
f
.
readlines
(
150
)
if
L
==
[]:
break
if
L
==
[]:
break
f
.
close
()
...
...
Lib/test/test_hash.py
View file @
004d5e68
...
...
@@ -6,12 +6,12 @@ import test_support
def
same_hash
(
*
objlist
):
# hash each object given an raise TestFailed if
# the hash values are not all the same
hashed
=
map
(
hash
,
objlist
)
for
h
in
hashed
[
1
:]:
if
h
!=
hashed
[
0
]:
raise
TestFailed
,
"hashed values differ: %s"
%
`objlist`
# hash each object given an raise TestFailed if
# the hash values are not all the same
hashed
=
map
(
hash
,
objlist
)
for
h
in
hashed
[
1
:]:
if
h
!=
hashed
[
0
]:
raise
TestFailed
,
"hashed values differ: %s"
%
`objlist`
...
...
@@ -21,6 +21,3 @@ same_hash(int(1), long(1), float(1), complex(1))
same_hash
(
long
(
1.23e300
),
float
(
1.23e300
))
same_hash
(
float
(
0.5
),
complex
(
0.5
,
0.0
))
Lib/test/test_imageop.py
View file @
004d5e68
...
...
@@ -18,7 +18,7 @@ def main(use_rgbimg=1):
image
,
width
,
height
=
getrgbimage
(
'test.rgb'
)
else
:
image
,
width
,
height
=
getimage
(
'test.rgb'
)
# Return the selected part of image, which should by width by height
# in size and consist of pixels of psize bytes.
if
verbose
:
...
...
@@ -28,7 +28,7 @@ def main(use_rgbimg=1):
# Return image scaled to size newwidth by newheight. No interpolation
# is done, scaling is done by simple-minded pixel duplication or removal.
# Therefore, computer-generated images or dithered images will
# not look nice after scaling.
# not look nice after scaling.
if
verbose
:
print
'scale'
scaleimage
=
imageop
.
scale
(
image
,
4
,
width
,
height
,
1
,
1
)
...
...
@@ -36,7 +36,7 @@ def main(use_rgbimg=1):
# Run a vertical low-pass filter over an image. It does so by computing
# each destination pixel as the average of two vertically-aligned source
# pixels. The main use of this routine is to forestall excessive flicker
# if the image two vertically-aligned source pixels, hence the name.
# if the image two vertically-aligned source pixels, hence the name.
if
verbose
:
print
'tovideo'
videoimage
=
imageop
.
tovideo
(
image
,
4
,
width
,
height
)
...
...
@@ -50,7 +50,7 @@ def main(use_rgbimg=1):
if
verbose
:
print
'rgb82rgb'
image
=
imageop
.
rgb82rgb
(
greyimage
,
width
,
height
)
# Convert an rgb image to an 8 bit greyscale image
if
verbose
:
print
'rgb2grey'
...
...
@@ -60,13 +60,13 @@ def main(use_rgbimg=1):
if
verbose
:
print
'grey2rgb'
image
=
imageop
.
grey2rgb
(
greyimage
,
width
,
height
)
# Convert a 8-bit deep greyscale image to a 1-bit deep image by
# thresholding all the pixels. The resulting image is tightly packed
# and is probably only useful as an argument to mono2grey.
# and is probably only useful as an argument to mono2grey.
if
verbose
:
print
'grey2mono'
monoimage
=
imageop
.
grey2mono
(
greyimage
,
width
,
height
,
0
)
monoimage
=
imageop
.
grey2mono
(
greyimage
,
width
,
height
,
0
)
# monoimage, width, height = getimage('monotest.rgb')
# Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
...
...
@@ -85,30 +85,30 @@ def main(use_rgbimg=1):
monoimage
=
imageop
.
dither2mono
(
greyimage
,
width
,
height
)
# Convert an 8-bit greyscale image to a 4-bit greyscale image without
# dithering.
# dithering.
if
verbose
:
print
'grey2grey4'
grey4image
=
imageop
.
grey2grey4
(
greyimage
,
width
,
height
)
grey4image
=
imageop
.
grey2grey4
(
greyimage
,
width
,
height
)
# Convert an 8-bit greyscale image to a 2-bit greyscale image without
# dithering.
# dithering.
if
verbose
:
print
'grey2grey2'
grey2image
=
imageop
.
grey2grey2
(
greyimage
,
width
,
height
)
grey2image
=
imageop
.
grey2grey2
(
greyimage
,
width
,
height
)
# Convert an 8-bit greyscale image to a 2-bit greyscale image with
# dithering. As for dither2mono, the dithering algorithm is currently
# very simple.
# very simple.
if
verbose
:
print
'dither2grey2'
grey2image
=
imageop
.
dither2grey2
(
greyimage
,
width
,
height
)
grey2image
=
imageop
.
dither2grey2
(
greyimage
,
width
,
height
)
# Convert a 4-bit greyscale image to an 8-bit greyscale image.
# Convert a 4-bit greyscale image to an 8-bit greyscale image.
if
verbose
:
print
'grey42grey'
greyimage
=
imageop
.
grey42grey
(
grey4image
,
width
,
height
)
greyimage
=
imageop
.
grey42grey
(
grey4image
,
width
,
height
)
# Convert a 2-bit greyscale image to an 8-bit greyscale image.
# Convert a 2-bit greyscale image to an 8-bit greyscale image.
if
verbose
:
print
'grey22grey'
image
=
imageop
.
grey22grey
(
grey2image
,
width
,
height
)
...
...
@@ -132,14 +132,14 @@ def getrgbimage(name):
image
=
rgbimg
.
longimagedata
(
name
)
return
(
image
,
sizes
[
0
],
sizes
[
1
])
def
getimage
(
name
):
"""return a tuple consisting of
image (in 'imgfile' format) width and height
"""
import
imgfile
try
:
sizes
=
imgfile
.
getsizes
(
name
)
except
imgfile
.
error
:
...
...
Lib/test/test_imgfile.py
View file @
004d5e68
...
...
@@ -8,7 +8,7 @@ from test_support import verbose, unlink, findfile
import
imgfile
,
uu
,
os
def
main
():
uu
.
decode
(
findfile
(
'testrgb.uue'
),
'test.rgb'
)
...
...
@@ -16,7 +16,7 @@ def main():
# Test a 3 byte color image
testimage
(
'test.rgb'
)
# Test a 1 byte greyscale image
testimage
(
'greytest.rgb'
)
...
...
@@ -57,18 +57,18 @@ def testimage(name):
# and returns it as a python string. The string has either 1 byte
# greyscale pixels or 4 byte RGBA pixels. The bottom left pixel
# is the first in the string. This format is suitable to pass
# to gl.lrectwrite, for instance.
# to gl.lrectwrite, for instance.
image
=
imgfile
.
read
(
name
)
# This function writes the RGB or greyscale data in data to
# image file file. x and y give the size of the image, z is
# 1 for 1 byte greyscale images or 3 for RGB images (which
# are stored as 4 byte values of which only the lower three
# bytes are used). These are the formats returned by gl.lrectread.
# bytes are used). These are the formats returned by gl.lrectread.
if
verbose
:
print
'Writing output file'
imgfile
.
write
(
outputfile
,
image
,
sizes
[
0
],
sizes
[
1
],
sizes
[
2
])
imgfile
.
write
(
outputfile
,
image
,
sizes
[
0
],
sizes
[
1
],
sizes
[
2
])
if
verbose
:
print
'Opening scaled test image: %s, sizes: %s'
%
(
name
,
str
(
sizes
))
...
...
@@ -91,18 +91,18 @@ def testimage(name):
# This function sets a global flag which defines whether the
# scan lines of the image are read or written from bottom to
# top (flag is zero, compatible with SGI GL) or from top to
# bottom(flag is one, compatible with X). The default is zero.
# bottom(flag is one, compatible with X). The default is zero.
if
verbose
:
print
'Switching to X compatibility'
imgfile
.
ttob
(
1
)
imgfile
.
ttob
(
1
)
if
verbose
:
print
'Filtering with "triangle"'
simage
=
imgfile
.
readscaled
(
name
,
sizes
[
0
]
/
2
,
sizes
[
1
]
/
2
,
'triangle'
,
3.0
)
if
verbose
:
print
'Switching back to SGI compatibility'
imgfile
.
ttob
(
0
)
imgfile
.
ttob
(
0
)
if
verbose
:
print
'Filtering with "quadratic"'
simage
=
imgfile
.
readscaled
(
name
,
sizes
[
0
]
/
2
,
sizes
[
1
]
/
2
,
'quadratic'
)
if
verbose
:
print
'Filtering with "gaussian"'
...
...
@@ -110,7 +110,7 @@ def testimage(name):
if
verbose
:
print
'Writing output file'
imgfile
.
write
(
outputfile
,
simage
,
sizes
[
0
]
/
2
,
sizes
[
1
]
/
2
,
sizes
[
2
])
imgfile
.
write
(
outputfile
,
simage
,
sizes
[
0
]
/
2
,
sizes
[
1
]
/
2
,
sizes
[
2
])
os
.
unlink
(
outputfile
)
...
...
Lib/test/test_largefile.py
View file @
004d5e68
...
...
@@ -56,7 +56,7 @@ def expect(got_this, expect_this):
# we have to check >4GB) files
if
test_support
.
verbose
:
print
'create large file via seek (may be sparse file) ...'
print
'create large file via seek (may be sparse file) ...'
f
=
open
(
name
,
'w'
)
f
.
seek
(
size
)
f
.
write
(
'a'
)
...
...
@@ -117,16 +117,16 @@ f.close()
# XXX has truncate ever worked on Windows? specifically on WinNT I get:
# "IOError: [Errno 13] Permission denied"
##try:
##
newsize = size - 10
##
f.seek(newsize)
##
f.truncate()
##
expect(f.tell(), newsize)
##
newsize = newsize - 1
##
f.seek(0)
##
f.truncate(newsize)
##
expect(f.tell(), newsize)
##
newsize = size - 10
##
f.seek(newsize)
##
f.truncate()
##
expect(f.tell(), newsize)
##
newsize = newsize - 1
##
f.seek(0)
##
f.truncate(newsize)
##
expect(f.tell(), newsize)
##except AttributeError:
##
pass
##
pass
os
.
unlink
(
name
)
print
>>
sys
.
stderr
,
name
,
"exists:"
,
os
.
path
.
exists
(
name
)
Lib/test/test_long.py
View file @
004d5e68
...
...
@@ -257,4 +257,3 @@ test_division()
test_bitop_identities
()
test_format
()
test_misc
()
Lib/test/test_longexp.py
View file @
004d5e68
REPS
=
65580
l
=
eval
(
"["
+
"2,"
*
REPS
+
"]"
)
print
len
(
l
)
l
=
eval
(
"["
+
"2,"
*
REPS
+
"]"
)
print
len
(
l
)
Lib/test/test_math.py
View file @
004d5e68
...
...
@@ -9,9 +9,9 @@ print 'math module, testing with eps', seps
import
math
def
testit
(
name
,
value
,
expected
):
if
abs
(
value
-
expected
)
>
eps
:
raise
TestFailed
,
'%s returned %f, expected %f'
%
\
(
name
,
value
,
expected
)
if
abs
(
value
-
expected
)
>
eps
:
raise
TestFailed
,
'%s returned %f, expected %f'
%
\
(
name
,
value
,
expected
)
print
'constants'
testit
(
'pi'
,
math
.
pi
,
3.1415926
)
...
...
@@ -85,9 +85,9 @@ testit('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
print
'frexp'
def
testfrexp
(
name
,
(
mant
,
exp
),
(
emant
,
eexp
)):
if
abs
(
mant
-
emant
)
>
eps
or
exp
<>
eexp
:
raise
TestFailed
,
'%s returned %s, expected %s'
%
\
(
name
,
`mant, exp`
,
`emant,eexp`
)
if
abs
(
mant
-
emant
)
>
eps
or
exp
<>
eexp
:
raise
TestFailed
,
'%s returned %s, expected %s'
%
\
(
name
,
`mant, exp`
,
`emant,eexp`
)
testfrexp
(
'frexp(-1)'
,
math
.
frexp
(
-
1
),
(
-
0.5
,
1
))
testfrexp
(
'frexp(0)'
,
math
.
frexp
(
0
),
(
0
,
0
))
...
...
@@ -116,9 +116,9 @@ testit('log10(10)', math.log10(10), 1)
print
'modf'
def
testmodf
(
name
,
(
v1
,
v2
),
(
e1
,
e2
)):
if
abs
(
v1
-
e1
)
>
eps
or
abs
(
v2
-
e2
):
raise
TestFailed
,
'%s returned %s, expected %s'
%
\
(
name
,
`v1,v2`
,
`e1,e2`
)
if
abs
(
v1
-
e1
)
>
eps
or
abs
(
v2
-
e2
):
raise
TestFailed
,
'%s returned %s, expected %s'
%
\
(
name
,
`v1,v2`
,
`e1,e2`
)
testmodf
(
'modf(1.5)'
,
math
.
modf
(
1.5
),
(
0.5
,
1.0
))
testmodf
(
'modf(-1.5)'
,
math
.
modf
(
-
1.5
),
(
-
0.5
,
-
1.0
))
...
...
Lib/test/test_md5.py
View file @
004d5e68
...
...
@@ -4,15 +4,15 @@ import string
from
md5
import
md5
def
hexstr
(
s
):
h
=
string
.
hexdigits
r
=
''
for
c
in
s
:
i
=
ord
(
c
)
r
=
r
+
h
[(
i
>>
4
)
&
0xF
]
+
h
[
i
&
0xF
]
return
r
h
=
string
.
hexdigits
r
=
''
for
c
in
s
:
i
=
ord
(
c
)
r
=
r
+
h
[(
i
>>
4
)
&
0xF
]
+
h
[
i
&
0xF
]
return
r
def
md5test
(
s
):
return
'MD5 ("'
+
s
+
'") = '
+
hexstr
(
md5
(
s
).
digest
())
return
'MD5 ("'
+
s
+
'") = '
+
hexstr
(
md5
(
s
).
digest
())
print
'MD5 test suite:'
print
md5test
(
''
)
...
...
@@ -27,4 +27,4 @@ print md5test('12345678901234567890123456789012345678901234567890123456789012345
m
=
md5
(
'testing the hexdigest method'
)
h
=
m
.
hexdigest
()
if
hexstr
(
m
.
digest
())
<>
h
:
print
'hexdigest() failed'
print
'hexdigest() failed'
Lib/test/test_minidom.py
View file @
004d5e68
...
...
@@ -16,9 +16,9 @@ tstfile = os.path.join(os.path.dirname(base), "test.xml")
del
base
def
confirm
(
test
,
testname
=
"Test"
):
if
test
:
if
test
:
print
"Passed "
+
testname
else
:
else
:
print
"Failed "
+
testname
raise
Exception
...
...
@@ -41,7 +41,7 @@ def testInsertBefore():
docel
=
dom
.
documentElement
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
# docel.childNodes[1])
#docel.insertBefore( dom.createProcessingInstruction("a", "b"),
# docel.childNodes[0])
...
...
@@ -133,7 +133,7 @@ def testRemoveAttrNS():
dom
=
Document
()
child
=
dom
.
appendChild
(
dom
.
createElementNS
(
"http://www.python.org"
,
"python:abc"
))
child
.
setAttributeNS
(
"http://www.w3.org"
,
"xmlns:python"
,
child
.
setAttributeNS
(
"http://www.w3.org"
,
"xmlns:python"
,
"http://www.python.org"
)
child
.
setAttributeNS
(
"http://www.python.org"
,
"python:abcattr"
,
"foo"
)
confirm
(
len
(
child
.
attributes
)
==
2
)
...
...
@@ -141,7 +141,7 @@ def testRemoveAttrNS():
confirm
(
len
(
child
.
attributes
)
==
1
)
dom
.
unlink
()
def
testRemoveAttributeNode
():
dom
=
Document
()
child
=
dom
.
appendChild
(
dom
.
createElement
(
"foo"
))
...
...
@@ -313,11 +313,11 @@ def testSiblings():
root
=
doc
.
documentElement
(
pi
,
text
,
elm
)
=
root
.
childNodes
confirm
(
pi
.
nextSibling
is
text
and
pi
.
previousSibling
is
None
and
text
.
nextSibling
is
elm
and
text
.
previousSibling
is
pi
and
elm
.
nextSibling
is
None
and
confirm
(
pi
.
nextSibling
is
text
and
pi
.
previousSibling
is
None
and
text
.
nextSibling
is
elm
and
text
.
previousSibling
is
pi
and
elm
.
nextSibling
is
None
and
elm
.
previousSibling
is
text
,
"testSiblings"
)
doc
.
unlink
()
...
...
@@ -347,7 +347,7 @@ def testSAX2DOM():
sax2dom
.
startElement
(
"subelm"
,
{})
sax2dom
.
characters
(
"text"
)
sax2dom
.
endElement
(
"subelm"
)
sax2dom
.
characters
(
"text"
)
sax2dom
.
characters
(
"text"
)
sax2dom
.
endElement
(
"doc"
)
sax2dom
.
endDocument
()
...
...
@@ -370,11 +370,11 @@ def testSAX2DOM():
elm1
.
parentNode
is
root
and
text2
.
parentNode
is
root
and
text3
.
parentNode
is
elm1
,
"testSAX2DOM - parents"
)
doc
.
unlink
()
# --- MAIN PROGRAM
names
=
globals
().
keys
()
names
.
sort
()
...
...
Lib/test/test_mmap.py
View file @
004d5e68
import
mmap
import
string
,
os
,
re
,
sys
...
...
@@ -6,10 +5,10 @@ PAGESIZE = mmap.PAGESIZE
def
test_both
():
"Test mmap module on Unix systems and Windows"
# Create an mmap'ed file
f
=
open
(
'foo'
,
'w+'
)
# Write 2 pages worth of data to the file
f
.
write
(
'
\
0
'
*
PAGESIZE
)
f
.
write
(
'foo'
)
...
...
@@ -17,11 +16,11 @@ def test_both():
m
=
mmap
.
mmap
(
f
.
fileno
(),
2
*
PAGESIZE
)
f
.
close
()
# Simple sanity checks
print
' Position of foo:'
,
string
.
find
(
m
,
'foo'
)
/
float
(
PAGESIZE
),
'pages'
assert
string
.
find
(
m
,
'foo'
)
==
PAGESIZE
print
' Length of file:'
,
len
(
m
)
/
float
(
PAGESIZE
),
'pages'
assert
len
(
m
)
==
2
*
PAGESIZE
...
...
@@ -29,12 +28,12 @@ def test_both():
assert
m
[
0
]
==
'
\
0
'
print
' Contents of first 3 bytes:'
,
repr
(
m
[
0
:
3
])
assert
m
[
0
:
3
]
==
'
\
0
\
0
\
0
'
# Modify the file's content
print
"
\
n
Modifying file's content..."
m
[
0
]
=
'3'
m
[
PAGESIZE
+
3
:
PAGESIZE
+
3
+
3
]
=
'bar'
# Check that the modification worked
print
' Contents of byte 0:'
,
repr
(
m
[
0
])
assert
m
[
0
]
==
'3'
...
...
@@ -42,7 +41,7 @@ def test_both():
assert
m
[
0
:
3
]
==
'3
\
0
\
0
'
print
' Contents of second page:'
,
repr
(
m
[
PAGESIZE
-
1
:
PAGESIZE
+
7
])
assert
m
[
PAGESIZE
-
1
:
PAGESIZE
+
7
]
==
'
\
0
foobar
\
0
'
m
.
flush
()
# Test doing a regular expression match in an mmap'ed file
...
...
@@ -51,11 +50,11 @@ def test_both():
print
' ERROR: regex match on mmap failed!'
else
:
start
,
end
=
match
.
span
(
0
)
length
=
end
-
start
length
=
end
-
start
print
' Regex match on mmap (page start, length of match):'
,
print
start
/
float
(
PAGESIZE
),
length
assert
start
==
PAGESIZE
assert
end
==
PAGESIZE
+
6
...
...
@@ -113,7 +112,7 @@ def test_both():
pass
else
:
assert
0
,
'Could seek beyond the new size'
m
.
close
()
os
.
unlink
(
"foo"
)
print
' Test passed'
...
...
Lib/test/test_ntpath.py
View file @
004d5e68
...
...
@@ -5,16 +5,16 @@ import os
errors
=
0
def
tester
(
fn
,
wantResult
):
fn
=
string
.
replace
(
fn
,
"
\
\
"
,
"
\
\
\
\
"
)
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
fn
=
string
.
replace
(
fn
,
"
\
\
"
,
"
\
\
\
\
"
)
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
tester
(
'ntpath.splitdrive("c:
\
\
foo
\
\
bar")'
,
(
'c:'
,
'
\
\
foo
\
\
bar'
))
tester
(
'ntpath.splitunc("
\
\
\
\
conky
\
\
mountpoint
\
\
foo
\
\
bar")'
,
(
'
\
\
\
\
conky
\
\
mountpoint'
,
'
\
\
foo
\
\
bar'
))
...
...
@@ -45,7 +45,6 @@ tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
"/home/swen/spam"
)
if
errors
:
print
str
(
errors
)
+
" errors."
print
str
(
errors
)
+
" errors."
else
:
print
"No errors. Thank your lucky stars."
print
"No errors. Thank your lucky stars."
Lib/test/test_opcodes.py
View file @
004d5e68
...
...
@@ -9,18 +9,18 @@ print 'XXX Not yet fully implemented'
print
'2.1 try inside for loop'
n
=
0
for
i
in
range
(
10
):
n
=
n
+
i
try
:
1
/
0
except
NameError
:
pass
except
ZeroDivisionError
:
pass
except
TypeError
:
pass
try
:
pass
except
:
pass
try
:
pass
finally
:
pass
n
=
n
+
i
n
=
n
+
i
try
:
1
/
0
except
NameError
:
pass
except
ZeroDivisionError
:
pass
except
TypeError
:
pass
try
:
pass
except
:
pass
try
:
pass
finally
:
pass
n
=
n
+
i
if
n
<>
90
:
raise
TestFailed
,
'try inside for'
raise
TestFailed
,
'try inside for'
print
'2.2 raise class exceptions'
...
...
@@ -50,12 +50,12 @@ b = BClass()
try
:
raise
AClass
,
b
except
BClass
,
v
:
if
v
!=
b
:
raise
TestFailed
if
v
!=
b
:
raise
TestFailed
else
:
raise
TestFailed
try
:
raise
b
except
AClass
,
v
:
if
v
!=
b
:
raise
TestFailed
if
v
!=
b
:
raise
TestFailed
# not enough arguments
try
:
raise
BClass
,
a
...
...
Lib/test/test_openpty.py
View file @
004d5e68
...
...
@@ -19,4 +19,3 @@ if not os.isatty(slave):
os
.
write
(
slave
,
'Ping!'
)
print
os
.
read
(
master
,
1024
)
Lib/test/test_operations.py
View file @
004d5e68
...
...
@@ -10,15 +10,15 @@ print '3.1 Dictionary lookups succeed even if __cmp__() raises an exception'
# SourceForge bug #112558:
# http://sourceforge.net/bugs/?func=detailbug&bug_id=112558&group_id=5470
class
BadDictKey
:
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
def
__cmp__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
print
"raising error"
raise
RuntimeError
,
"gotcha"
return
other
class
BadDictKey
:
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
def
__cmp__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
print
"raising error"
raise
RuntimeError
,
"gotcha"
return
other
d
=
{}
x1
=
BadDictKey
()
...
...
Lib/test/test_pickle.py
View file @
004d5e68
...
...
@@ -137,7 +137,7 @@ def dotest(pickle):
pass
else
:
print
"accepted insecure string: %s"
%
repr
(
buf
)
import
pickle
dotest
(
pickle
)
Lib/test/test_pkg.py
View file @
004d5e68
...
...
@@ -78,7 +78,7 @@ def runtest(hier, code):
tests
=
[
(
"t1"
,
[(
"t1"
,
None
),
(
"t1 __init__.py"
,
""
)],
"import t1"
),
(
"t2"
,
[
(
"t2"
,
None
),
(
"t2 __init__.py"
,
"'doc for t2'; print __name__, 'loading'"
),
...
...
@@ -108,7 +108,7 @@ print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__
from t2 import *
print dir()
"""
),
(
"t3"
,
[
(
"t3"
,
None
),
(
"t3 __init__.py"
,
"print __name__, 'loading'"
),
...
...
@@ -124,7 +124,7 @@ reload(t3)
reload(t3.sub)
reload(t3.sub.subsub)
"""
),
(
"t4"
,
[
(
"t4.py"
,
"print 'THIS SHOULD NOT BE PRINTED (t4.py)'"
),
(
"t4"
,
None
),
...
...
@@ -172,7 +172,7 @@ from t6 import *
print fixdir(dir(t6))
print dir()
"""
),
(
"t7"
,
[
(
"t7.py"
,
"print 'Importing t7.py'"
),
(
"t7"
,
None
),
...
...
Lib/test/test_poll.py
View file @
004d5e68
# Test case for the os.poll() function
import
sys
,
os
,
select
,
random
from
test_support
import
verbose
,
TestSkipped
,
TESTFN
...
...
Lib/test/test_posixpath.py
View file @
004d5e68
...
...
@@ -4,15 +4,15 @@ import string
errors
=
0
def
tester
(
fn
,
wantResult
):
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
gotResult
=
eval
(
fn
)
if
wantResult
!=
gotResult
:
print
"error!"
print
"evaluated: "
+
str
(
fn
)
print
"should be: "
+
str
(
wantResult
)
print
" returned: "
+
str
(
gotResult
)
print
""
global
errors
errors
=
errors
+
1
tester
(
'posixpath.splitdrive("/foo/bar")'
,
(
''
,
'/foo/bar'
))
...
...
@@ -36,7 +36,6 @@ tester('posixpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
"/home/swen/spam"
)
if
errors
:
print
str
(
errors
)
+
" errors."
print
str
(
errors
)
+
" errors."
else
:
print
"No errors. Thank your lucky stars."
print
"No errors. Thank your lucky stars."
Lib/test/test_pow.py
View file @
004d5e68
...
...
@@ -2,10 +2,10 @@ import sys
import
test_support
def
powtest
(
type
):
if
type
!=
float
:
if
type
!=
float
:
print
" Testing 2-argument pow() function..."
for
i
in
range
(
-
1000
,
1000
):
if
pow
(
type
(
i
),
0
)
!=
1
:
if
pow
(
type
(
i
),
0
)
!=
1
:
raise
ValueError
,
'pow('
+
str
(
i
)
+
',0) != 1'
if
pow
(
type
(
i
),
1
)
!=
type
(
i
):
raise
ValueError
,
'pow('
+
str
(
i
)
+
',1) != '
+
str
(
i
)
...
...
@@ -17,7 +17,7 @@ def powtest(type):
for
i
in
range
(
-
100
,
100
):
if
pow
(
type
(
i
),
3
)
!=
i
*
i
*
i
:
raise
ValueError
,
'pow('
+
str
(
i
)
+
',3) != '
+
str
(
i
*
i
*
i
)
pow2
=
1
for
i
in
range
(
0
,
31
):
if
pow
(
2
,
i
)
!=
pow2
:
...
...
@@ -62,13 +62,13 @@ def powtest(type):
elif
type
==
long
:
jl
,
jh
=
0
,
15
for
i
in
range
(
il
,
ih
+
1
):
for
j
in
range
(
jl
,
jh
+
1
):
for
k
in
range
(
kl
,
kh
+
1
):
if
k
!=
0
:
if
compare
(
pow
(
type
(
i
),
j
,
k
),
pow
(
type
(
i
),
j
)
%
type
(
k
)):
raise
ValueError
,
"pow("
+
str
(
i
)
+
","
+
str
(
j
)
+
\
","
+
str
(
k
)
+
") != pow("
+
str
(
i
)
+
","
+
\
str
(
j
)
+
") % "
+
str
(
k
)
for
j
in
range
(
jl
,
jh
+
1
):
for
k
in
range
(
kl
,
kh
+
1
):
if
k
!=
0
:
if
compare
(
pow
(
type
(
i
),
j
,
k
),
pow
(
type
(
i
),
j
)
%
type
(
k
)):
raise
ValueError
,
"pow("
+
str
(
i
)
+
","
+
str
(
j
)
+
\
","
+
str
(
k
)
+
") != pow("
+
str
(
i
)
+
","
+
\
str
(
j
)
+
") % "
+
str
(
k
)
print
'Testing integer mode...'
...
...
@@ -104,17 +104,17 @@ print pow(5.0,2) % -8, pow(5.0,2,-8)
print
for
i
in
range
(
-
10
,
11
):
for
j
in
range
(
0
,
6
):
for
k
in
range
(
-
7
,
11
):
if
j
>=
0
and
k
!=
0
:
o
=
pow
(
i
,
j
)
%
k
n
=
pow
(
i
,
j
,
k
)
if
o
!=
n
:
print
'Integer mismatch:'
,
i
,
j
,
k
if
j
>=
0
and
k
<>
0
:
o
=
pow
(
long
(
i
),
j
)
%
k
n
=
pow
(
long
(
i
),
j
,
k
)
if
o
!=
n
:
print
'Long mismatch:'
,
i
,
j
,
k
if
i
>=
0
and
k
<>
0
:
o
=
pow
(
float
(
i
),
j
)
%
k
n
=
pow
(
float
(
i
),
j
,
k
)
if
o
!=
n
:
print
'Float mismatch:'
,
i
,
j
,
k
for
j
in
range
(
0
,
6
):
for
k
in
range
(
-
7
,
11
):
if
j
>=
0
and
k
!=
0
:
o
=
pow
(
i
,
j
)
%
k
n
=
pow
(
i
,
j
,
k
)
if
o
!=
n
:
print
'Integer mismatch:'
,
i
,
j
,
k
if
j
>=
0
and
k
<>
0
:
o
=
pow
(
long
(
i
),
j
)
%
k
n
=
pow
(
long
(
i
),
j
,
k
)
if
o
!=
n
:
print
'Long mismatch:'
,
i
,
j
,
k
if
i
>=
0
and
k
<>
0
:
o
=
pow
(
float
(
i
),
j
)
%
k
n
=
pow
(
float
(
i
),
j
,
k
)
if
o
!=
n
:
print
'Float mismatch:'
,
i
,
j
,
k
Lib/test/test_pty.py
View file @
004d5e68
...
...
@@ -88,4 +88,3 @@ else:
os
.
close
(
master_fd
)
# pty.fork() passed.
Lib/test/test_pwd.py
View file @
004d5e68
...
...
@@ -51,7 +51,7 @@ while bynames.has_key(fakename):
# should never happen... if so, just forget it
break
fakename
=
string
.
join
(
map
(
None
,
chars
),
''
)
try
:
pwd
.
getpwnam
(
fakename
)
except
KeyError
:
...
...
Lib/test/test_pyexpat.py
View file @
004d5e68
...
...
@@ -2,13 +2,13 @@
# XXX TypeErrors on calling handlers, or on bad return values from a
# handler, are obscure and unhelpful.
from
xml.parsers
import
expat
class
Outputter
:
def
StartElementHandler
(
self
,
name
,
attrs
):
print
'Start element:
\
n
\
t
'
,
repr
(
name
),
attrs
def
EndElementHandler
(
self
,
name
):
print
'End element:
\
n
\
t
'
,
repr
(
name
)
...
...
@@ -43,11 +43,11 @@ class Outputter:
def
UnparsedEntityDeclHandler
(
self
,
*
args
):
entityName
,
base
,
systemId
,
publicId
,
notationName
=
args
print
'Unparsed entity decl:
\
n
\
t
'
,
args
def
NotStandaloneHandler
(
self
,
userData
):
print
'Not standalone'
return
1
def
ExternalEntityRefHandler
(
self
,
*
args
):
context
,
base
,
sysId
,
pubId
=
args
print
'External entity ref:'
,
args
...
...
Lib/test/test_re.py
View file @
004d5e68
...
...
@@ -351,7 +351,7 @@ for t in tests:
# string), so we'll ignore patterns that feature it.
if
pattern
[:
2
]
!=
'
\
\
B'
and
pattern
[
-
2
:]
!=
'
\
\
B'
\
and
result
!=
None
:
and
result
!=
None
:
obj
=
re
.
compile
(
pattern
)
result
=
obj
.
search
(
s
,
result
.
start
(
0
),
result
.
end
(
0
)
+
1
)
if
result
==
None
:
...
...
Lib/test/test_regex.py
View file @
004d5e68
...
...
@@ -69,7 +69,7 @@ for t in tests:
if len(t)==5:
pattern, s, outcome, repl, expected = t
elif len(t)==3:
pattern, s, outcome = t
pattern, s, outcome = t
else:
raise ValueError, ('
Test
tuples
should
have
3
or
5
fields
',t)
...
...
@@ -77,8 +77,8 @@ for t in tests:
obj=regex.compile(pattern)
except regex.error:
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
else:
# Regex syntax errors aren'
t
yet
reported
,
so
for
else:
# Regex syntax errors aren'
t
yet
reported
,
so
for
# the official test suite they'll be quietly ignored.
pass
#print '=== Syntax error:', t
...
...
Lib/test/test_rgbimg.py
View file @
004d5e68
...
...
@@ -5,24 +5,24 @@ import rgbimg, os, uu
from
test_support
import
verbose
,
unlink
,
findfile
class
error
(
Exception
):
pass
pass
print
'RGBimg test suite:'
def
testimg
(
rgb_file
,
raw_file
):
rgb_file
=
findfile
(
rgb_file
)
raw_file
=
findfile
(
raw_file
)
width
,
height
=
rgbimg
.
sizeofimage
(
rgb_file
)
rgb
=
rgbimg
.
longimagedata
(
rgb_file
)
if
len
(
rgb
)
!=
width
*
height
*
4
:
raise
error
,
'bad image length'
raw
=
open
(
raw_file
,
'rb'
).
read
()
if
rgb
!=
raw
:
raise
error
,
\
'images don
\
'
t match for '
+
rgb_file
+
' and '
+
raw_file
for
depth
in
[
1
,
3
,
4
]:
rgbimg
.
longstoimage
(
rgb
,
width
,
height
,
depth
,
'@.rgb'
)
os
.
unlink
(
'@.rgb'
)
rgb_file
=
findfile
(
rgb_file
)
raw_file
=
findfile
(
raw_file
)
width
,
height
=
rgbimg
.
sizeofimage
(
rgb_file
)
rgb
=
rgbimg
.
longimagedata
(
rgb_file
)
if
len
(
rgb
)
!=
width
*
height
*
4
:
raise
error
,
'bad image length'
raw
=
open
(
raw_file
,
'rb'
).
read
()
if
rgb
!=
raw
:
raise
error
,
\
'images don
\
'
t match for '
+
rgb_file
+
' and '
+
raw_file
for
depth
in
[
1
,
3
,
4
]:
rgbimg
.
longstoimage
(
rgb
,
width
,
height
,
depth
,
'@.rgb'
)
os
.
unlink
(
'@.rgb'
)
table
=
[
(
'testrgb.uue'
,
'test.rgb'
),
...
...
@@ -41,23 +41,23 @@ if verbose:
ttob
=
rgbimg
.
ttob
(
0
)
if
ttob
!=
0
:
raise
error
,
'ttob should start out as zero'
raise
error
,
'ttob should start out as zero'
testimg
(
'test.rgb'
,
'test.rawimg'
)
ttob
=
rgbimg
.
ttob
(
1
)
if
ttob
!=
0
:
raise
error
,
'ttob should be zero'
raise
error
,
'ttob should be zero'
testimg
(
'test.rgb'
,
'test.rawimg.rev'
)
ttob
=
rgbimg
.
ttob
(
0
)
if
ttob
!=
1
:
raise
error
,
'ttob should be one'
raise
error
,
'ttob should be one'
ttob
=
rgbimg
.
ttob
(
0
)
if
ttob
!=
0
:
raise
error
,
'ttob should be zero'
raise
error
,
'ttob should be zero'
for
source
,
target
in
table
:
unlink
(
findfile
(
target
))
Lib/test/test_sax.py
View file @
004d5e68
# regression test for SAX 2.0
# $Id$
...
...
@@ -75,7 +74,7 @@ def test_xmlgen_basic():
def
test_xmlgen_content
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startElement
(
"doc"
,
{})
gen
.
characters
(
"huhei"
)
...
...
@@ -87,7 +86,7 @@ def test_xmlgen_content():
def
test_xmlgen_pi
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
processingInstruction
(
"test"
,
"data"
)
gen
.
startElement
(
"doc"
,
{})
...
...
@@ -99,7 +98,7 @@ def test_xmlgen_pi():
def
test_xmlgen_content_escape
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startElement
(
"doc"
,
{})
gen
.
characters
(
"<huhei&"
)
...
...
@@ -111,7 +110,7 @@ def test_xmlgen_content_escape():
def
test_xmlgen_ignorable
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startElement
(
"doc"
,
{})
gen
.
ignorableWhitespace
(
" "
)
...
...
@@ -125,7 +124,7 @@ ns_uri = "http://www.python.org/xml-ns/saxtest/"
def
test_xmlgen_ns
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startPrefixMapping
(
"ns1"
,
ns_uri
)
gen
.
startElementNS
((
ns_uri
,
"doc"
),
"ns1:doc"
,
{})
...
...
@@ -147,7 +146,7 @@ def test_filter_basic():
gen
=
XMLGenerator
(
result
)
filter
=
XMLFilterBase
()
filter
.
setContentHandler
(
gen
)
filter
.
startDocument
()
filter
.
startElement
(
"doc"
,
{})
filter
.
characters
(
"content"
)
...
...
@@ -170,7 +169,7 @@ class TestDTDHandler:
def
__init__
(
self
):
self
.
_notations
=
[]
self
.
_entities
=
[]
def
notationDecl
(
self
,
name
,
publicId
,
systemId
):
self
.
_notations
.
append
((
name
,
publicId
,
systemId
))
...
...
@@ -214,7 +213,7 @@ def test_expat_entityresolver():
parser
.
close
()
return
result
.
getvalue
()
==
start
+
"<doc><entity></entity></doc>"
# ===== Attributes support
class
AttrGatherer
(
ContentHandler
):
...
...
@@ -224,7 +223,7 @@ class AttrGatherer(ContentHandler):
def
startElementNS
(
self
,
name
,
qname
,
attrs
):
self
.
_attrs
=
attrs
def
test_expat_attrs_empty
():
parser
=
create_parser
()
gather
=
AttrGatherer
()
...
...
@@ -264,7 +263,7 @@ def test_expat_nsattrs_wattr():
parser
.
close
()
attrs
=
gather
.
_attrs
return
attrs
.
getLength
()
==
1
and
\
attrs
.
getNames
()
==
[(
ns_uri
,
"attr"
)]
and
\
attrs
.
getQNames
()
==
[]
and
\
...
...
@@ -376,13 +375,13 @@ def verify_empty_attrs(attrs):
gqnk
=
0
except
KeyError
:
gqnk
=
1
try
:
attrs
[
"attr"
]
gik
=
0
except
KeyError
:
gik
=
1
return
attrs
.
getLength
()
==
0
and
\
attrs
.
getNames
()
==
[]
and
\
attrs
.
getQNames
()
==
[]
and
\
...
...
@@ -444,13 +443,13 @@ def verify_empty_nsattrs(attrs):
gqnk
=
0
except
KeyError
:
gqnk
=
1
try
:
attrs
[(
ns_uri
,
"attr"
)]
gik
=
0
except
KeyError
:
gik
=
1
return
attrs
.
getLength
()
==
0
and
\
attrs
.
getNames
()
==
[]
and
\
attrs
.
getQNames
()
==
[]
and
\
...
...
@@ -469,7 +468,7 @@ def test_nsattrs_empty():
def
test_nsattrs_wattr
():
attrs
=
AttributesNSImpl
({(
ns_uri
,
"attr"
)
:
"val"
},
{(
ns_uri
,
"attr"
)
:
"ns:attr"
})
return
attrs
.
getLength
()
==
1
and
\
attrs
.
getNames
()
==
[(
ns_uri
,
"attr"
)]
and
\
attrs
.
getQNames
()
==
[
"ns:attr"
]
and
\
...
...
@@ -485,7 +484,7 @@ def test_nsattrs_wattr():
attrs
.
getNameByQName
(
"ns:attr"
)
==
(
ns_uri
,
"attr"
)
and
\
attrs
[(
ns_uri
,
"attr"
)]
==
"val"
and
\
attrs
.
getQNameByName
((
ns_uri
,
"attr"
))
==
"ns:attr"
# ===== Main program
...
...
Lib/test/test_select.py
View file @
004d5e68
...
...
@@ -17,7 +17,7 @@ class Nope:
class
Almost
:
def
fileno
(
self
):
return
'fileno'
try
:
rfd
,
wfd
,
xfd
=
select
.
select
([
Nope
()],
[],
[])
except
TypeError
:
...
...
@@ -34,30 +34,29 @@ else:
def
test
():
import
sys
if
sys
.
platform
[:
3
]
in
(
'win'
,
'mac'
,
'os2'
):
if
verbose
:
print
"Can't test select easily on"
,
sys
.
platform
return
cmd
=
'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
p
=
os
.
popen
(
cmd
,
'r'
)
for
tout
in
(
0
,
1
,
2
,
4
,
8
,
16
)
+
(
None
,)
*
10
:
import
sys
if
sys
.
platform
[:
3
]
in
(
'win'
,
'mac'
,
'os2'
):
if
verbose
:
print
"Can't test select easily on"
,
sys
.
platform
return
cmd
=
'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
p
=
os
.
popen
(
cmd
,
'r'
)
for
tout
in
(
0
,
1
,
2
,
4
,
8
,
16
)
+
(
None
,)
*
10
:
if
verbose
:
print
'timeout ='
,
tout
rfd
,
wfd
,
xfd
=
select
.
select
([
p
],
[],
[],
tout
)
if
(
rfd
,
wfd
,
xfd
)
==
([],
[],
[]):
continue
if
(
rfd
,
wfd
,
xfd
)
==
([
p
],
[],
[]):
line
=
p
.
readline
()
if
verbose
:
print
`line`
if
not
line
:
if
verbose
:
print
'timeout ='
,
tout
rfd
,
wfd
,
xfd
=
select
.
select
([
p
],
[],
[],
tout
)
if
(
rfd
,
wfd
,
xfd
)
==
([],
[],
[]):
continue
if
(
rfd
,
wfd
,
xfd
)
==
([
p
],
[],
[]):
line
=
p
.
readline
()
if
verbose
:
print
`line`
if
not
line
:
if
verbose
:
print
'EOF'
break
continue
print
'Unexpected return values from select():'
,
rfd
,
wfd
,
xfd
p
.
close
()
print
'EOF'
break
continue
print
'Unexpected return values from select():'
,
rfd
,
wfd
,
xfd
p
.
close
()
test
()
Lib/test/test_signal.py
View file @
004d5e68
...
...
@@ -8,36 +8,36 @@ if sys.platform[:3] in ('win', 'os2'):
raise
TestSkipped
,
"Can't test signal on %s"
%
sys
.
platform
[:
3
]
if
verbose
:
x
=
'-x'
x
=
'-x'
else
:
x
=
'+x'
x
=
'+x'
pid
=
os
.
getpid
()
# Shell script that will send us asynchronous signals
script
=
"""
(
set %(x)s
sleep 2
kill -5 %(pid)d
sleep 2
kill -2 %(pid)d
sleep 2
kill -3 %(pid)d
set %(x)s
sleep 2
kill -5 %(pid)d
sleep 2
kill -2 %(pid)d
sleep 2
kill -3 %(pid)d
) &
"""
%
vars
()
def
handlerA
(
*
args
):
if
verbose
:
print
"handlerA"
,
args
if
verbose
:
print
"handlerA"
,
args
HandlerBCalled
=
"HandlerBCalled"
# Exception
HandlerBCalled
=
"HandlerBCalled"
# Exception
def
handlerB
(
*
args
):
if
verbose
:
print
"handlerB"
,
args
raise
HandlerBCalled
,
args
if
verbose
:
print
"handlerB"
,
args
raise
HandlerBCalled
,
args
signal
.
alarm
(
20
)
# Entire test lasts at most 20 sec.
signal
.
alarm
(
20
)
# Entire test lasts at most 20 sec.
signal
.
signal
(
5
,
handlerA
)
signal
.
signal
(
2
,
handlerB
)
signal
.
signal
(
3
,
signal
.
SIG_IGN
)
...
...
@@ -48,19 +48,19 @@ os.system(script)
print
"starting pause() loop..."
try
:
while
1
:
if
verbose
:
print
"call pause()..."
try
:
signal
.
pause
()
if
verbose
:
print
"pause() returned"
except
HandlerBCalled
:
if
verbose
:
print
"HandlerBCalled exception caught"
else
:
pass
while
1
:
if
verbose
:
print
"call pause()..."
try
:
signal
.
pause
()
if
verbose
:
print
"pause() returned"
except
HandlerBCalled
:
if
verbose
:
print
"HandlerBCalled exception caught"
else
:
pass
except
KeyboardInterrupt
:
if
verbose
:
print
"KeyboardInterrupt (assume the alarm() went off)"
if
verbose
:
print
"KeyboardInterrupt (assume the alarm() went off)"
Lib/test/test_string.py
View file @
004d5e68
...
...
@@ -20,7 +20,7 @@ def test(name, input, output, *args):
f
=
getattr
(
string
,
name
)
value
=
apply
(
f
,
(
input
,)
+
args
)
except
:
value
=
sys
.
exc_type
value
=
sys
.
exc_type
if
value
!=
output
:
if
verbose
:
print
'no'
...
...
@@ -35,4 +35,3 @@ string_tests.run_method_tests(test)
string
.
whitespace
string
.
lowercase
string
.
uppercase
Lib/test/test_strop.py
View file @
004d5e68
...
...
@@ -8,7 +8,7 @@ def test(name, input, output, *args):
try
:
value
=
apply
(
f
,
(
input
,)
+
args
)
except
:
value
=
sys
.
exc_type
value
=
sys
.
exc_type
if
value
!=
output
:
if
verbose
:
print
'no'
...
...
Lib/test/test_struct.py
View file @
004d5e68
...
...
@@ -94,7 +94,7 @@ tests = [
]
def
badpack
(
fmt
,
arg
,
got
,
exp
):
return
return
def
badunpack
(
fmt
,
arg
,
got
,
exp
):
return
"unpack(%s, %s) -> (%s,) # expected (%s,)"
%
(
...
...
Lib/test/test_support.py
View file @
004d5e68
...
...
@@ -2,72 +2,72 @@
class
Error
(
Exception
):
"""Base class for regression test exceptions."""
"""Base class for regression test exceptions."""
class
TestFailed
(
Error
):
"""Test failed."""
"""Test failed."""
class
TestSkipped
(
Error
):
"""Test skipped.
"""Test skipped.
This can be raised to indicate that a test was deliberatly
skipped, but not because a feature wasn't available. For
example, if some resource can't be used, such as the network
appears to be unavailable, this should be raised instead of
TestFailed.
This can be raised to indicate that a test was deliberatly
skipped, but not because a feature wasn't available. For
example, if some resource can't be used, such as the network
appears to be unavailable, this should be raised instead of
TestFailed.
"""
"""
verbose
=
1
# Flag set to 0 by regrtest.py
verbose
=
1
# Flag set to 0 by regrtest.py
use_large_resources
=
1
# Flag set to 0 by regrtest.py
def
unload
(
name
):
import
sys
try
:
del
sys
.
modules
[
name
]
except
KeyError
:
pass
import
sys
try
:
del
sys
.
modules
[
name
]
except
KeyError
:
pass
def
forget
(
modname
):
unload
(
modname
)
import
sys
,
os
for
dirname
in
sys
.
path
:
try
:
os
.
unlink
(
os
.
path
.
join
(
dirname
,
modname
+
'.pyc'
))
except
os
.
error
:
pass
unload
(
modname
)
import
sys
,
os
for
dirname
in
sys
.
path
:
try
:
os
.
unlink
(
os
.
path
.
join
(
dirname
,
modname
+
'.pyc'
))
except
os
.
error
:
pass
FUZZ
=
1e-6
def
fcmp
(
x
,
y
):
# fuzzy comparison function
if
type
(
x
)
==
type
(
0.0
)
or
type
(
y
)
==
type
(
0.0
):
try
:
x
,
y
=
coerce
(
x
,
y
)
fuzz
=
(
abs
(
x
)
+
abs
(
y
))
*
FUZZ
if
abs
(
x
-
y
)
<=
fuzz
:
return
0
except
:
pass
elif
type
(
x
)
==
type
(
y
)
and
type
(
x
)
in
(
type
(()),
type
([])):
for
i
in
range
(
min
(
len
(
x
),
len
(
y
))):
outcome
=
fcmp
(
x
[
i
],
y
[
i
])
if
outcome
<>
0
:
return
outcome
return
cmp
(
len
(
x
),
len
(
y
))
return
cmp
(
x
,
y
)
if
type
(
x
)
==
type
(
0.0
)
or
type
(
y
)
==
type
(
0.0
):
try
:
x
,
y
=
coerce
(
x
,
y
)
fuzz
=
(
abs
(
x
)
+
abs
(
y
))
*
FUZZ
if
abs
(
x
-
y
)
<=
fuzz
:
return
0
except
:
pass
elif
type
(
x
)
==
type
(
y
)
and
type
(
x
)
in
(
type
(()),
type
([])):
for
i
in
range
(
min
(
len
(
x
),
len
(
y
))):
outcome
=
fcmp
(
x
[
i
],
y
[
i
])
if
outcome
<>
0
:
return
outcome
return
cmp
(
len
(
x
),
len
(
y
))
return
cmp
(
x
,
y
)
TESTFN
=
'@test'
# Filename used for testing
from
os
import
unlink
def
findfile
(
file
,
here
=
__file__
):
import
os
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
path
=
sys
.
path
path
=
[
os
.
path
.
dirname
(
here
)]
+
path
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
import
os
if
os
.
path
.
isabs
(
file
):
return
file
import
sys
path
=
sys
.
path
path
=
[
os
.
path
.
dirname
(
here
)]
+
path
for
dn
in
path
:
fn
=
os
.
path
.
join
(
dn
,
file
)
if
os
.
path
.
exists
(
fn
):
return
fn
return
file
Lib/test/test_thread.py
View file @
004d5e68
...
...
@@ -16,98 +16,98 @@ done.acquire()
numtasks
=
10
def
task
(
ident
):
global
running
rmutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
rmutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
if
verbose
:
print
'task'
,
ident
,
'done'
mutex
.
acquire
()
running
=
running
-
1
if
running
==
0
:
done
.
release
()
mutex
.
release
()
global
running
rmutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
rmutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
if
verbose
:
print
'task'
,
ident
,
'done'
mutex
.
acquire
()
running
=
running
-
1
if
running
==
0
:
done
.
release
()
mutex
.
release
()
next_ident
=
0
def
newtask
():
global
next_ident
,
running
mutex
.
acquire
()
next_ident
=
next_ident
+
1
if
verbose
:
print
'creating task'
,
next_ident
thread
.
start_new_thread
(
task
,
(
next_ident
,))
running
=
running
+
1
mutex
.
release
()
global
next_ident
,
running
mutex
.
acquire
()
next_ident
=
next_ident
+
1
if
verbose
:
print
'creating task'
,
next_ident
thread
.
start_new_thread
(
task
,
(
next_ident
,))
running
=
running
+
1
mutex
.
release
()
for
i
in
range
(
numtasks
):
newtask
()
newtask
()
print
'waiting for all tasks to complete'
done
.
acquire
()
print
'all tasks done'
class
barrier
:
def
__init__
(
self
,
n
):
self
.
n
=
n
self
.
waiting
=
0
self
.
checkin
=
thread
.
allocate_lock
()
self
.
checkout
=
thread
.
allocate_lock
()
self
.
checkout
.
acquire
()
def
__init__
(
self
,
n
):
self
.
n
=
n
self
.
waiting
=
0
self
.
checkin
=
thread
.
allocate_lock
()
self
.
checkout
=
thread
.
allocate_lock
()
self
.
checkout
.
acquire
()
def
enter
(
self
):
checkin
,
checkout
=
self
.
checkin
,
self
.
checkout
def
enter
(
self
):
checkin
,
checkout
=
self
.
checkin
,
self
.
checkout
checkin
.
acquire
()
self
.
waiting
=
self
.
waiting
+
1
if
self
.
waiting
==
self
.
n
:
self
.
waiting
=
self
.
n
-
1
checkout
.
release
()
return
checkin
.
release
()
checkin
.
acquire
()
self
.
waiting
=
self
.
waiting
+
1
if
self
.
waiting
==
self
.
n
:
self
.
waiting
=
self
.
n
-
1
checkout
.
release
()
return
checkin
.
release
()
checkout
.
acquire
()
self
.
waiting
=
self
.
waiting
-
1
if
self
.
waiting
==
0
:
checkin
.
release
()
return
checkout
.
release
()
checkout
.
acquire
()
self
.
waiting
=
self
.
waiting
-
1
if
self
.
waiting
==
0
:
checkin
.
release
()
return
checkout
.
release
()
numtrips
=
3
def
task2
(
ident
):
global
running
for
i
in
range
(
numtrips
):
if
ident
==
0
:
# give it a good chance to enter the next
# barrier before the others are all out
# of the current one
delay
=
0.001
else
:
rmutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
rmutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
if
verbose
:
print
'task'
,
ident
,
'entering barrier'
,
i
bar
.
enter
()
if
verbose
:
print
'task'
,
ident
,
'leaving barrier'
,
i
mutex
.
acquire
()
running
=
running
-
1
if
running
==
0
:
done
.
release
()
mutex
.
release
()
global
running
for
i
in
range
(
numtrips
):
if
ident
==
0
:
# give it a good chance to enter the next
# barrier before the others are all out
# of the current one
delay
=
0.001
else
:
rmutex
.
acquire
()
delay
=
random
.
random
()
*
numtasks
rmutex
.
release
()
if
verbose
:
print
'task'
,
ident
,
'will run for'
,
round
(
delay
,
1
),
'sec'
time
.
sleep
(
delay
)
if
verbose
:
print
'task'
,
ident
,
'entering barrier'
,
i
bar
.
enter
()
if
verbose
:
print
'task'
,
ident
,
'leaving barrier'
,
i
mutex
.
acquire
()
running
=
running
-
1
if
running
==
0
:
done
.
release
()
mutex
.
release
()
print
'
\
n
*** Barrier Test ***'
if
done
.
acquire
(
0
):
raise
ValueError
,
"'done' should have remained acquired"
raise
ValueError
,
"'done' should have remained acquired"
bar
=
barrier
(
numtasks
)
running
=
numtasks
for
i
in
range
(
numtasks
):
thread
.
start_new_thread
(
task2
,
(
i
,))
thread
.
start_new_thread
(
task2
,
(
i
,))
done
.
acquire
()
print
'all tasks done'
Lib/test/test_tokenize.py
View file @
004d5e68
...
...
@@ -7,4 +7,3 @@ file = open(findfile('tokenize_tests.py'))
tokenize
.
tokenize
(
file
.
readline
)
if
verbose
:
print
'finished'
Lib/test/test_types.py
View file @
004d5e68
...
...
@@ -53,7 +53,7 @@ print '6.4 Numeric types (mostly conversions)'
if
0
<>
0L
or
0
<>
0.0
or
0L
<>
0.0
:
raise
TestFailed
,
'mixed comparisons'
if
1
<>
1L
or
1
<>
1.0
or
1L
<>
1.0
:
raise
TestFailed
,
'mixed comparisons'
if
-
1
<>
-
1L
or
-
1
<>
-
1.0
or
-
1L
<>
-
1.0
:
raise
TestFailed
,
'int/long/float value not equal'
raise
TestFailed
,
'int/long/float value not equal'
if
int
(
1.9
)
==
1
==
int
(
1.1
)
and
int
(
-
1.1
)
==
-
1
==
int
(
-
1.9
):
pass
else
:
raise
TestFailed
,
'int() does not round properly'
if
long
(
1.9
)
==
1L
==
long
(
1.1
)
and
long
(
-
1.1
)
==
-
1L
==
long
(
-
1.9
):
pass
...
...
@@ -70,7 +70,7 @@ if not -24 < -12: raise TestFailed, 'int op'
# Test for a particular bug in integer multiply
xsize
,
ysize
,
zsize
=
238
,
356
,
4
if
not
(
xsize
*
ysize
*
zsize
==
zsize
*
xsize
*
ysize
==
338912
):
raise
TestFailed
,
'int mul commutativity'
raise
TestFailed
,
'int mul commutativity'
print
'6.4.2 Long integers'
if
12L
+
24L
<>
36L
:
raise
TestFailed
,
'long op'
if
12L
+
(
-
24L
)
<>
-
12L
:
raise
TestFailed
,
'long op'
...
...
@@ -139,15 +139,15 @@ else: raise TestFailed, 'in/not in list'
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[:
-
1
]
=
a
if
a
!=
[
1
,
2
,
3
,
4
,
5
,
5
]:
raise
TestFailed
,
"list self-slice-assign (head)"
raise
TestFailed
,
"list self-slice-assign (head)"
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[
1
:]
=
a
if
a
!=
[
1
,
1
,
2
,
3
,
4
,
5
]:
raise
TestFailed
,
"list self-slice-assign (tail)"
raise
TestFailed
,
"list self-slice-assign (tail)"
a
=
[
1
,
2
,
3
,
4
,
5
]
a
[
1
:
-
1
]
=
a
if
a
!=
[
1
,
1
,
2
,
3
,
4
,
5
,
5
]:
raise
TestFailed
,
"list self-slice-assign (center)"
raise
TestFailed
,
"list self-slice-assign (center)"
print
'6.5.3a Additional list operations'
...
...
@@ -212,10 +212,10 @@ z.sort(myComparison)
# Test extreme cases with long ints
a
=
[
0
,
1
,
2
,
3
,
4
]
if
a
[
-
pow
(
2
,
128L
):
3
]
!=
[
0
,
1
,
2
]:
raise
TestFailed
,
"list slicing with too-small long integer"
if
a
[
3
:
pow
(
2
,
145L
)
]
!=
[
3
,
4
]:
raise
TestFailed
,
"list slicing with too-large long integer"
if
a
[
-
pow
(
2
,
128L
):
3
]
!=
[
0
,
1
,
2
]:
raise
TestFailed
,
"list slicing with too-small long integer"
if
a
[
3
:
pow
(
2
,
145L
)
]
!=
[
3
,
4
]:
raise
TestFailed
,
"list slicing with too-large long integer"
print
'6.6 Mappings == Dictionaries'
d
=
{}
...
...
@@ -256,12 +256,12 @@ if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg'
# dict.setdefault()
d
=
{}
if
d
.
setdefault
(
'key0'
)
<>
None
:
raise
TestFailed
,
'missing {} setdefault, no 2nd arg'
raise
TestFailed
,
'missing {} setdefault, no 2nd arg'
if
d
.
setdefault
(
'key0'
)
<>
None
:
raise
TestFailed
,
'present {} setdefault, no 2nd arg'
raise
TestFailed
,
'present {} setdefault, no 2nd arg'
d
.
setdefault
(
'key'
,
[]).
append
(
3
)
if
d
[
'key'
][
0
]
<>
3
:
raise
TestFailed
,
'missing {} setdefault, w/ 2nd arg'
raise
TestFailed
,
'missing {} setdefault, w/ 2nd arg'
d
.
setdefault
(
'key'
,
[]).
append
(
4
)
if
len
(
d
[
'key'
])
<>
2
:
raise
TestFailed
,
'present {} setdefault, w/ 2nd arg'
raise
TestFailed
,
'present {} setdefault, w/ 2nd arg'
Lib/test/test_ucn.py
View file @
004d5e68
...
...
@@ -52,31 +52,30 @@ k_cchMaxUnicodeName = 83
s = "
\
N
{
" + "
1
" * (k_cchMaxUnicodeName + 2) + "
}
"
try:
unicode(s, 'unicode-escape', 'strict')
unicode(s, 'unicode-escape', 'strict')
except UnicodeError:
pass
pass
else:
raise AssertionError, "
failed
to
raise
an
exception
when
presented
"
\
"
with
a
UCN
>
k_cchMaxUnicodeName
"
raise AssertionError, "
failed
to
raise
an
exception
when
presented
"
\
"
with
a
UCN
>
k_cchMaxUnicodeName
"
try:
unicode("
\
N
{
blah
}
", 'unicode-escape', 'strict')
unicode("
\
N
{
blah
}
", 'unicode-escape', 'strict')
except UnicodeError:
pass
pass
else:
raise AssertionError, "
failed
to
raise
an
exception
when
given
a
bogus
character
name
"
raise AssertionError, "
failed
to
raise
an
exception
when
given
a
bogus
character
name
"
try:
unicode("
\
N
{
SPACE
", 'unicode-escape', 'strict')
unicode("
\
N
{
SPACE
", 'unicode-escape', 'strict')
except UnicodeError:
pass
pass
else:
raise AssertionError, "
failed
to
raise
an
exception
for
a
missing
closing
brace
.
"
raise AssertionError, "
failed
to
raise
an
exception
for
a
missing
closing
brace
.
"
try:
unicode("
\
NSPACE
", 'unicode-escape', 'strict')
unicode("
\
NSPACE
", 'unicode-escape', 'strict')
except UnicodeError:
pass
pass
else:
raise AssertionError, "
failed
to
raise
an
exception
for
a
missing
opening
brace
.
"
raise AssertionError, "
failed
to
raise
an
exception
for
a
missing
opening
brace
.
"
print "
done
.
"
Lib/test/test_unicode.py
View file @
004d5e68
...
...
@@ -179,41 +179,41 @@ if 0:
# Non surrogate above surrogate value, fixup required
def
test_lecmp
(
s
,
s2
):
assert
s
<
s2
,
"comparison failed on %s < %s"
%
(
s
,
s2
)
assert
s
<
s2
,
"comparison failed on %s < %s"
%
(
s
,
s2
)
def
test_fixup
(
s
):
s2
=
u'
\
ud800
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udc01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udd01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
ude01
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud800
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
ud900
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
uda00
\
udfff
'
test_lecmp
(
s
,
s2
)
s2
=
u'
\
udb00
\
udfff
'
test_lecmp
(
s
,
s2
)
test_fixup
(
u'
\
ue000
'
)
test_fixup
(
u'
\
uff61
'
)
...
...
@@ -321,13 +321,13 @@ assert u"%c" % (u"a",) == u'a'
assert
u"%c"
%
(
"a"
,)
==
u'a'
assert
u"%c"
%
(
34
,)
==
u'"'
assert
u"%c"
%
(
36
,)
==
u'$'
value
=
u"%r, %r"
%
(
u"abc"
,
"abc"
)
value
=
u"%r, %r"
%
(
u"abc"
,
"abc"
)
if
value
!=
u"u'abc', 'abc'"
:
print
'*** formatting failed for "%s"'
%
'u"%r, %r" % (u"abc", "abc")'
assert
u"%(x)s, %(y)s"
%
{
'x'
:
u"abc"
,
'y'
:
"def"
}
==
u'abc, def'
try
:
value
=
u"%(x)s, %()s"
%
{
'x'
:
u"abc"
,
u''
.
encode
(
'utf-8'
):
"def"
}
value
=
u"%(x)s, %()s"
%
{
'x'
:
u"abc"
,
u''
.
encode
(
'utf-8'
):
"def"
}
except
KeyError
:
print
'*** formatting failed for "%s"'
%
"u'abc, def'"
else
:
...
...
@@ -453,7 +453,7 @@ for encoding in (
'cp037'
,
'cp1026'
,
'cp437'
,
'cp500'
,
'cp737'
,
'cp775'
,
'cp850'
,
'cp852'
,
'cp855'
,
'cp860'
,
'cp861'
,
'cp862'
,
'cp863'
,
'cp865'
,
'cp866'
,
'cp863'
,
'cp865'
,
'cp866'
,
'iso8859_10'
,
'iso8859_13'
,
'iso8859_14'
,
'iso8859_15'
,
'iso8859_2'
,
'iso8859_3'
,
'iso8859_4'
,
'iso8859_5'
,
'iso8859_6'
,
'iso8859_7'
,
'iso8859_9'
,
'koi8_r'
,
'latin_1'
,
...
...
@@ -465,10 +465,10 @@ for encoding in (
'mac_greek'
,
'mac_iceland'
,
'mac_roman'
,
'mac_turkish'
,
'cp1006'
,
'cp875'
,
'iso8859_8'
,
### These have undefined mappings:
#'cp424',
):
try
:
assert
unicode
(
s
,
encoding
).
encode
(
encoding
)
==
s
...
...
@@ -483,21 +483,21 @@ for encoding in (
'cp037'
,
'cp1026'
,
'cp437'
,
'cp500'
,
'cp737'
,
'cp775'
,
'cp850'
,
'cp852'
,
'cp855'
,
'cp860'
,
'cp861'
,
'cp862'
,
'cp863'
,
'cp865'
,
'cp866'
,
'cp863'
,
'cp865'
,
'cp866'
,
'iso8859_10'
,
'iso8859_13'
,
'iso8859_14'
,
'iso8859_15'
,
'iso8859_2'
,
'iso8859_3'
,
'iso8859_4'
,
'iso8859_5'
,
'iso8859_6'
,
'iso8859_7'
,
'iso8859_9'
,
'koi8_r'
,
'latin_1'
,
'mac_cyrillic'
,
'mac_latin2'
,
### These have undefined mappings:
#'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
#'cp1256', 'cp1257', 'cp1258',
#'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
#'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
### These fail the round-trip:
#'cp1006', 'cp875', 'iso8859_8',
):
try
:
assert
unicode
(
s
,
encoding
).
encode
(
encoding
)
==
s
...
...
@@ -515,4 +515,3 @@ assert (u"abc" "def") == u"abcdef"
assert
(
u"abc"
u"def"
"ghi"
)
==
u"abcdefghi"
assert
(
"abc"
"def"
u"ghi"
)
==
u"abcdefghi"
print
'done.'
Lib/test/test_unicodedata.py
View file @
004d5e68
...
...
@@ -15,7 +15,7 @@ def test_methods():
for
i
in
range
(
65536
):
char
=
unichr
(
i
)
data
=
[
# Predicates (single char)
char
.
isalnum
()
and
u'1'
or
u'0'
,
char
.
isalpha
()
and
u'1'
or
u'0'
,
...
...
@@ -26,7 +26,7 @@ def test_methods():
char
.
isspace
()
and
u'1'
or
u'0'
,
char
.
istitle
()
and
u'1'
or
u'0'
,
char
.
isupper
()
and
u'1'
or
u'0'
,
# Predicates (multiple chars)
(
char
+
u'abc'
).
isalnum
()
and
u'1'
or
u'0'
,
(
char
+
u'abc'
).
isalpha
()
and
u'1'
or
u'0'
,
...
...
@@ -42,13 +42,13 @@ def test_methods():
char
.
lower
(),
char
.
upper
(),
char
.
title
(),
# Mappings (multiple chars)
(
char
+
u'abc'
).
lower
(),
(
char
+
u'ABC'
).
upper
(),
(
char
+
u'abc'
).
title
(),
(
char
+
u'ABC'
).
title
(),
]
h
.
update
(
u''
.
join
(
data
).
encode
(
encoding
))
return
h
.
hexdigest
()
...
...
@@ -68,7 +68,7 @@ def test_unicodedata():
unicodedata
.
decomposition
(
char
),
str
(
unicodedata
.
mirrored
(
char
)),
str
(
unicodedata
.
combining
(
char
)),
]
]
h
.
update
(
''
.
join
(
data
))
return
h
.
hexdigest
()
...
...
Lib/test/test_urllib.py
View file @
004d5e68
...
...
@@ -28,5 +28,3 @@ out2_2 = "abc?def"
assert
urllib
.
quote
(
in2
)
==
out2_1
,
"urllib.quote problem"
assert
urllib
.
quote
(
in2
,
'?'
)
==
out2_2
,
"urllib.quote problem"
Lib/test/test_winreg.py
View file @
004d5e68
...
...
@@ -144,4 +144,3 @@ if remote_name is not None:
else
:
print
"Remote registry calls can be tested using"
,
print
"'test_winreg.py --remote
\
\
\
\
machine_name'"
Lib/test/test_winsound.py
View file @
004d5e68
...
...
@@ -4,4 +4,3 @@ import winsound
for
i
in
range
(
100
,
2000
,
100
):
winsound
.
Beep
(
i
,
75
)
print
"Hopefully you heard some sounds increasing in frequency!"
Lib/test/test_xmllib.py
View file @
004d5e68
...
...
@@ -16,10 +16,10 @@ testdoc = """\
import
xmllib
if
verbose
:
parser
=
xmllib
.
TestXMLParser
()
parser
=
xmllib
.
TestXMLParser
()
else
:
parser
=
xmllib
.
XMLParser
()
parser
=
xmllib
.
XMLParser
()
for
c
in
testdoc
:
parser
.
feed
(
c
)
parser
.
feed
(
c
)
parser
.
close
()
Lib/test/test_zipfile.py
View file @
004d5e68
...
...
@@ -4,23 +4,22 @@ srcname = "junk9630.tmp"
zipname
=
"junk9708.tmp"
try
:
fp
=
open
(
srcname
,
"w"
)
# Make a source file with some lines
for
i
in
range
(
0
,
1000
):
fp
.
write
(
"Test of zipfile line %d.
\
n
"
%
i
)
fp
.
close
()
fp
=
open
(
srcname
,
"w"
)
# Make a source file with some lines
for
i
in
range
(
0
,
1000
):
fp
.
write
(
"Test of zipfile line %d.
\
n
"
%
i
)
fp
.
close
()
zip
=
zipfile
.
ZipFile
(
zipname
,
"w"
)
# Create the ZIP archive
zip
.
write
(
srcname
,
srcname
)
zip
.
write
(
srcname
,
"another.name"
)
zip
.
close
()
zip
=
zipfile
.
ZipFile
(
zipname
,
"w"
)
# Create the ZIP archive
zip
.
write
(
srcname
,
srcname
)
zip
.
write
(
srcname
,
"another.name"
)
zip
.
close
()
zip
=
zipfile
.
ZipFile
(
zipname
,
"r"
)
# Read the ZIP archive
zip
.
read
(
"another.name"
)
zip
.
read
(
srcname
)
zip
.
close
()
zip
=
zipfile
.
ZipFile
(
zipname
,
"r"
)
# Read the ZIP archive
zip
.
read
(
"another.name"
)
zip
.
read
(
srcname
)
zip
.
close
()
finally
:
if
os
.
path
.
isfile
(
srcname
):
# Remove temporary files
os
.
unlink
(
srcname
)
if
os
.
path
.
isfile
(
zipname
):
os
.
unlink
(
zipname
)
if
os
.
path
.
isfile
(
srcname
):
# Remove temporary files
os
.
unlink
(
srcname
)
if
os
.
path
.
isfile
(
zipname
):
os
.
unlink
(
zipname
)
Lib/test/test_zlib.py
View file @
004d5e68
...
...
@@ -96,7 +96,7 @@ def ignore():
"""
"""
LAERTES
LAERTES
O, fear me not.
I stay too long: but here my father comes.
...
...
@@ -106,7 +106,7 @@ LAERTES
A double blessing is a double grace,
Occasion smiles upon a second leave.
LORD POLONIUS
LORD POLONIUS
Yet here, Laertes! aboard, aboard, for shame!
The wind sits in the shoulder of your sail,
...
...
@@ -136,26 +136,25 @@ LORD POLONIUS
Thou canst not then be false to any man.
Farewell: my blessing season this in thee!
LAERTES
LAERTES
Most humbly do I take my leave, my lord.
LORD POLONIUS
LORD POLONIUS
The time invites you; go; your servants tend.
LAERTES
LAERTES
Farewell, Ophelia; and remember well
What I have said to you.
OPHELIA
OPHELIA
'Tis in my memory lock'd,
And you yourself shall keep the key of it.
LAERTES
LAERTES
Farewell.
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment