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
61ba930b
Commit
61ba930b
authored
Nov 10, 1994
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more complete tests of built-in functions
parent
d74a93bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
2 deletions
+95
-2
Lib/test/test_b1.py
Lib/test/test_b1.py
+44
-0
Lib/test/test_b2.py
Lib/test/test_b2.py
+42
-2
Lib/test/testall.out
Lib/test/testall.out
+9
-0
No files found.
Lib/test/test_b1.py
View file @
61ba930b
...
...
@@ -31,6 +31,21 @@ apply(f1, (1,))
apply
(
f2
,
(
1
,
2
))
apply
(
f3
,
(
1
,
2
,
3
))
print
'callable'
if
not
callable
(
len
):
raise
TestFailed
,
'callable(len)'
def
f
():
pass
if
not
callable
(
f
):
raise
TestFailed
,
'callable(f)'
class
C
:
def
meth
(
self
):
pass
if
not
callable
(
C
):
raise
TestFailed
,
'callable(C)'
x
=
C
()
if
not
callable
(
x
.
meth
):
raise
TestFailed
,
'callable(x.meth)'
if
callable
(
x
):
raise
TestFailed
,
'callable(x)'
class
D
(
C
):
def
__call__
(
self
):
pass
y
=
D
()
if
not
callable
(
y
):
raise
TestFailed
,
'callable(y)'
print
'chr'
if
chr
(
32
)
<>
' '
:
raise
TestFailed
,
'chr(32)'
if
chr
(
65
)
<>
'A'
:
raise
TestFailed
,
'chr(65)'
...
...
@@ -46,6 +61,14 @@ if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
if
coerce
(
1
,
1L
)
<>
(
1L
,
1L
):
raise
TestFailed
,
'coerce(1, 1L)'
if
fcmp
(
coerce
(
1L
,
1.1
),
(
1.0
,
1.1
)):
raise
TestFailed
,
'coerce(1L, 1.1)'
print
'compile'
compile
(
'print 1
\
n
'
,
''
,
'exec'
)
print
'delattr'
import
sys
sys
.
spam
=
1
delattr
(
sys
,
'spam'
)
print
'dir'
x
=
1
if
'x'
not
in
dir
():
raise
TestFailed
,
'dir()'
...
...
@@ -123,12 +146,33 @@ print 'getattr'
import
sys
if
getattr
(
sys
,
'stdout'
)
is
not
sys
.
stdout
:
raise
TestFailed
,
'getattr'
print
'hasattr'
import
sys
if
not
hasattr
(
sys
,
'stdout'
):
raise
TestFailed
,
'hasattr'
print
'hash'
hash
(
None
)
if
not
hash
(
1
)
==
hash
(
1L
)
==
hash
(
1.0
):
raise
TestFailed
,
'numeric hash()'
hash
(
'spam'
)
hash
((
0
,
1
,
2
,
3
))
def
f
():
pass
print
'hex'
if
hex
(
16
)
!=
'0x10'
:
raise
TestFailed
,
'hex(16)'
if
hex
(
16L
)
!=
'0x10L'
:
raise
TestFailed
,
'hex(16L)'
if
hex
(
-
16
)
!=
'-0x10'
:
raise
TestFailed
,
'hex(-16)'
if
hex
(
-
16L
)
!=
'-0x10L'
:
raise
TestFailed
,
'hex(-16L)'
print
'id'
id
(
None
)
id
(
1
)
id
(
1L
)
id
(
1.0
)
id
(
'spam'
)
id
((
0
,
1
,
2
,
3
))
id
([
0
,
1
,
2
,
3
])
id
({
'spam'
:
1
,
'eggs'
:
2
,
'ham'
:
3
})
# Test input() later, together with raw_input
print
'int'
...
...
Lib/test/test_b2.py
View file @
61ba930b
...
...
@@ -86,6 +86,12 @@ if fcmp(pow(2.,30), 1024.*1024.*1024.): raise TestFailed, 'pow(2.,30)'
#if fcmp(pow(-2.,1), -2.): raise TestFailed, 'pow(-2.,1)'
#if fcmp(pow(-2.,2), 4.): raise TestFailed, 'pow(-2.,2)'
#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
)
print
'range'
if
range
(
3
)
<>
[
0
,
1
,
2
]:
raise
TestFailed
,
'range(3)'
...
...
@@ -142,8 +148,14 @@ if reduce(lambda x, y: x+y, Squares(0), 0) != 0:
print
'reload'
#import strop
#reload(strop)
import
string
reload
(
string
)
import
sys
try
:
reload
(
sys
)
except
ImportError
:
pass
else
:
raise
TestFailed
,
'reload(sys) should fail'
print
'repr'
if
repr
(
''
)
<>
'
\
'
\
'
'
:
raise
TestFailed
,
'repr(
\
'
\
'
)'
...
...
@@ -190,8 +202,8 @@ if round(-999999999.9) <> -1000000000.0:
print
'setattr'
import
sys
setattr
(
sys
,
'
foobar
'
,
1
)
if
sys
.
foobar
!=
1
:
raise
TestFailed
,
'setattr(sys,
\
'
foobar
\
'
, 1)'
setattr
(
sys
,
'
spam
'
,
1
)
if
sys
.
spam
!=
1
:
raise
TestFailed
,
'setattr(sys,
\
'
spam
\
'
, 1)'
print
'str'
if
str
(
''
)
<>
''
:
raise
TestFailed
,
'str(
\
'
\
'
)'
...
...
@@ -201,10 +213,38 @@ if str(()) <> '()': raise TestFailed, 'str(())'
if
str
([])
<>
'[]'
:
raise
TestFailed
,
'str([])'
if
str
({})
<>
'{}'
:
raise
TestFailed
,
'str({})'
print
'tuple'
if
tuple
(())
<>
():
raise
TestFailed
,
'tuple(())'
if
tuple
((
0
,
1
,
2
,
3
))
<>
(
0
,
1
,
2
,
3
):
raise
TestFailed
,
'tuple((0, 1, 2, 3))'
if
tuple
([])
<>
():
raise
TestFailed
,
'tuple([])'
if
tuple
([
0
,
1
,
2
,
3
])
<>
(
0
,
1
,
2
,
3
):
raise
TestFailed
,
'tuple([0, 1, 2, 3])'
if
tuple
(
''
)
<>
():
raise
TestFailed
,
'tuple('')'
if
tuple
(
'spam'
)
<>
(
's'
,
'p'
,
'a'
,
'm'
):
raise
TestFailed
,
"tuple('spam')"
print
'type'
if
type
(
''
)
<>
type
(
'123'
)
or
type
(
''
)
==
type
(()):
raise
TestFailed
,
'type()'
print
'vars'
a
=
b
=
None
a
=
vars
().
keys
()
b
=
dir
()
a
.
sort
()
b
.
sort
()
if
a
<>
b
:
raise
TestFailed
,
'vars()'
import
sys
a
=
vars
(
sys
).
keys
()
b
=
dir
(
sys
)
a
.
sort
()
b
.
sort
()
if
a
<>
b
:
raise
TestFailed
,
'vars(sys)'
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)'
# Epilogue -- unlink the temp file
...
...
Lib/test/testall.out
View file @
61ba930b
...
...
@@ -56,9 +56,12 @@ test_builtin
test_b1
abs
apply
callable
chr
cmp
coerce
compile
delattr
dir
divmod
eval
...
...
@@ -66,7 +69,10 @@ execfile
filter
float
getattr
hasattr
hash
hex
id
int
len
long
...
...
@@ -88,7 +94,10 @@ repr
round
setattr
str
tuple
type
vars
xrange
test_exceptions
5. Built-in exceptions
AttributeError
...
...
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