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
a8268e94
Commit
a8268e94
authored
Oct 16, 2000
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the usual
parent
1a2ca86a
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
488 additions
and
259 deletions
+488
-259
Lib/dos-8x3/stringio.py
Lib/dos-8x3/stringio.py
+2
-0
Lib/dos-8x3/test_cop.py
Lib/dos-8x3/test_cop.py
+35
-0
Lib/dos-8x3/test_fcn.py
Lib/dos-8x3/test_fcn.py
+1
-1
Lib/dos-8x3/test_gra.py
Lib/dos-8x3/test_gra.py
+9
-1
Lib/dos-8x3/test_mat.py
Lib/dos-8x3/test_mat.py
+31
-0
Lib/dos-8x3/test_min.py
Lib/dos-8x3/test_min.py
+185
-119
Lib/dos-8x3/test_str.py
Lib/dos-8x3/test_str.py
+36
-133
Lib/dos-8x3/test_unp.py
Lib/dos-8x3/test_unp.py
+12
-0
Lib/dos-8x3/test_url.py
Lib/dos-8x3/test_url.py
+32
-0
Lib/dos-8x3/test_win.py
Lib/dos-8x3/test_win.py
+145
-5
No files found.
Lib/dos-8x3/stringio.py
View file @
a8268e94
...
...
@@ -129,6 +129,8 @@ class StringIO:
self
.
buflist
=
[]
self
.
buflist
=
[
self
.
buf
[:
self
.
pos
],
s
,
self
.
buf
[
newpos
:]]
self
.
buf
=
''
if
newpos
>
self
.
len
:
self
.
len
=
newpos
else
:
self
.
buflist
.
append
(
s
)
self
.
len
=
newpos
...
...
Lib/dos-8x3/test_cop.py
0 → 100644
View file @
a8268e94
import
copy_reg
class
C
:
pass
try
:
copy_reg
.
pickle
(
C
,
None
,
None
)
except
TypeError
,
e
:
print
"Caught expected TypeError:"
print
e
else
:
print
"Failed to catch expected TypeError when registering a class type."
print
try
:
copy_reg
.
pickle
(
type
(
1
),
"not a callable"
)
except
TypeError
,
e
:
print
"Caught expected TypeError:"
print
e
else
:
print
"Failed to catch TypeError "
\
"when registering a non-callable reduction function."
print
try
:
copy_reg
.
pickle
(
type
(
1
),
int
,
"not a callable"
)
except
TypeError
,
e
:
print
"Caught expected TypeError:"
print
e
else
:
print
"Failed to catch TypeError "
\
"when registering a non-callable constructor."
Lib/dos-8x3/test_fcn.py
View file @
a8268e94
...
...
@@ -16,7 +16,7 @@ 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'
,
if
sys
.
platform
in
(
'netbsd1'
,
'Darwin1.2'
,
'freebsd2'
,
'freebsd3'
,
'freebsd4'
,
'freebsd5'
,
'bsdos2'
,
'bsdos3'
,
'bsdos4'
,
'openbsd'
,
'openbsd2'
):
...
...
Lib/dos-8x3/test_gra.py
View file @
a8268e94
...
...
@@ -268,10 +268,18 @@ print >> sys.stdout
print
>>
sys
.
stdout
,
0
or
1
,
0
or
1
,
print
>>
sys
.
stdout
,
0
or
1
# test print
>> Non
e
# test print
ing to an instanc
e
class
Gulp
:
def
write
(
self
,
msg
):
pass
gulp
=
Gulp
()
print
>>
gulp
,
1
,
2
,
3
print
>>
gulp
,
1
,
2
,
3
,
print
>>
gulp
print
>>
gulp
,
0
or
1
,
0
or
1
,
print
>>
gulp
,
0
or
1
# test print >> None
def
driver
():
oldstdout
=
sys
.
stdout
sys
.
stdout
=
Gulp
()
...
...
Lib/dos-8x3/test_mat.py
View file @
a8268e94
...
...
@@ -152,3 +152,34 @@ testit('tan(-pi/4)', math.tan(-math.pi/4), -1)
print
'tanh'
testit
(
'tanh(0)'
,
math
.
tanh
(
0
),
0
)
testit
(
'tanh(1)+tanh(-1)'
,
math
.
tanh
(
1
)
+
math
.
tanh
(
-
1
),
0
)
print
'exceptions'
# oooooh, *this* is a x-platform gamble! good luck
try
:
x
=
math
.
exp
(
-
1000000000
)
except
:
# mathmodule.c is failing to weed out underflows from libm, or
# we've got an fp format with huge dynamic range
raise
TestFailed
(
"underflowing exp() should not have rasied an exception"
)
if
x
!=
0
:
raise
TestFailed
(
"underflowing exp() should have returned 0"
)
# If this fails, probably using a strict IEEE-754 conforming libm, and x
# is +Inf afterwards. But Python wants overflows detected by default.
try
:
x
=
math
.
exp
(
1000000000
)
except
OverflowError
:
pass
else
:
raise
TestFailed
(
"overflowing exp() didn't trigger OverflowError"
)
# If this fails, it could be a puzzle. One odd possibility is that
# mathmodule.c's CHECK() macro is getting confused while comparing
# Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
# as a result (and so raising OverflowError instead).
try
:
x
=
math
.
sqrt
(
-
1.0
)
except
ValueError
:
pass
else
:
raise
TestFailed
(
"sqrt(-1) didn't raise ValueError"
)
Lib/dos-8x3/test_min.py
View file @
a8268e94
This diff is collapsed.
Click to expand it.
Lib/dos-8x3/test_str.py
View file @
a8268e94
#! /usr/bin/env python
# Sanity checker for time.strftime
import
time
,
calendar
,
sys
,
string
,
os
,
re
from
test_support
import
verbose
def
main
():
global
verbose
now
=
time
.
time
()
strftest
(
now
)
verbose
=
0
# Try a bunch of dates and times, chosen to vary through time of
# day and daylight saving time
for
j
in
range
(
-
5
,
5
):
for
i
in
range
(
25
):
strftest
(
now
+
(
i
+
j
*
100
)
*
23
*
3603
)
def
strftest
(
now
):
if
verbose
:
print
"strftime test for"
,
time
.
ctime
(
now
)
nowsecs
=
str
(
long
(
now
))[:
-
1
]
gmt
=
time
.
gmtime
(
now
)
now
=
time
.
localtime
(
now
)
if
now
[
3
]
<
12
:
ampm
=
'(AM|am)'
else
:
ampm
=
'(PM|pm)'
jan1
=
time
.
localtime
(
time
.
mktime
((
now
[
0
],
1
,
1
)
+
(
0
,)
*
6
))
# Tests StringIO and cStringIO
def
do_test
(
module
):
s
=
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
'
\
n
'
)
*
5
f
=
module
.
StringIO
(
s
)
print
f
.
read
(
10
)
print
f
.
readline
()
print
len
(
f
.
readlines
(
60
))
f
=
module
.
StringIO
()
f
.
write
(
'abcdef'
)
f
.
seek
(
3
)
f
.
write
(
'uvwxyz'
)
f
.
write
(
'!'
)
print
`f.getvalue()`
f
.
close
()
f
=
module
.
StringIO
()
f
.
write
(
s
)
f
.
seek
(
10
)
f
.
truncate
()
print
`f.getvalue()`
f
.
seek
(
0
)
f
.
truncate
(
5
)
print
`f.getvalue()`
f
.
close
()
try
:
if
now
[
8
]:
tz
=
time
.
tzname
[
1
]
else
:
tz
=
time
.
tzname
[
0
]
except
AttributeError
:
tz
=
''
if
now
[
3
]
>
12
:
clock12
=
now
[
3
]
-
12
elif
now
[
3
]
>
0
:
clock12
=
now
[
3
]
else
:
clock12
=
12
expectations
=
(
(
'%a'
,
calendar
.
day_abbr
[
now
[
6
]],
'abbreviated weekday name'
),
(
'%A'
,
calendar
.
day_name
[
now
[
6
]],
'full weekday name'
),
(
'%b'
,
calendar
.
month_abbr
[
now
[
1
]],
'abbreviated month name'
),
(
'%B'
,
calendar
.
month_name
[
now
[
1
]],
'full month name'
),
# %c see below
(
'%d'
,
'%02d'
%
now
[
2
],
'day of month as number (00-31)'
),
(
'%H'
,
'%02d'
%
now
[
3
],
'hour (00-23)'
),
(
'%I'
,
'%02d'
%
clock12
,
'hour (01-12)'
),
(
'%j'
,
'%03d'
%
now
[
7
],
'julian day (001-366)'
),
(
'%m'
,
'%02d'
%
now
[
1
],
'month as number (01-12)'
),
(
'%M'
,
'%02d'
%
now
[
4
],
'minute, (00-59)'
),
(
'%p'
,
ampm
,
'AM or PM as appropriate'
),
(
'%S'
,
'%02d'
%
now
[
5
],
'seconds of current time (00-60)'
),
(
'%U'
,
'%02d'
%
((
now
[
7
]
+
jan1
[
6
])
/
7
),
'week number of the year (Sun 1st)'
),
(
'%w'
,
'0?%d'
%
((
1
+
now
[
6
])
%
7
),
'weekday as a number (Sun 1st)'
),
(
'%W'
,
'%02d'
%
((
now
[
7
]
+
(
jan1
[
6
]
-
1
)
%
7
)
/
7
),
'week number of the year (Mon 1st)'
),
# %x see below
(
'%X'
,
'%02d:%02d:%02d'
%
(
now
[
3
],
now
[
4
],
now
[
5
]),
'%H:%M:%S'
),
(
'%y'
,
'%02d'
%
(
now
[
0
]
%
100
),
'year without century'
),
(
'%Y'
,
'%d'
%
now
[
0
],
'year with century'
),
# %Z see below
(
'%%'
,
'%'
,
'single percent sign'
),
)
nonstandard_expectations
=
(
# These are standard but don't have predictable output
(
'%c'
,
fixasctime
(
time
.
asctime
(
now
)),
'near-asctime() format'
),
(
'%x'
,
'%02d/%02d/%02d'
%
(
now
[
1
],
now
[
2
],
(
now
[
0
]
%
100
)),
'%m/%d/%y %H:%M:%S'
),
(
'%Z'
,
'%s'
%
tz
,
'time zone name'
),
# These are some platform specific extensions
(
'%D'
,
'%02d/%02d/%02d'
%
(
now
[
1
],
now
[
2
],
(
now
[
0
]
%
100
)),
'mm/dd/yy'
),
(
'%e'
,
'%2d'
%
now
[
2
],
'day of month as number, blank padded ( 0-31)'
),
(
'%h'
,
calendar
.
month_abbr
[
now
[
1
]],
'abbreviated month name'
),
(
'%k'
,
'%2d'
%
now
[
3
],
'hour, blank padded ( 0-23)'
),
(
'%n'
,
'
\
n
'
,
'newline character'
),
(
'%r'
,
'%02d:%02d:%02d %s'
%
(
clock12
,
now
[
4
],
now
[
5
],
ampm
),
'%I:%M:%S %p'
),
(
'%R'
,
'%02d:%02d'
%
(
now
[
3
],
now
[
4
]),
'%H:%M'
),
(
'%s'
,
nowsecs
,
'seconds since the Epoch in UCT'
),
(
'%t'
,
'
\
t
'
,
'tab character'
),
(
'%T'
,
'%02d:%02d:%02d'
%
(
now
[
3
],
now
[
4
],
now
[
5
]),
'%H:%M:%S'
),
(
'%3y'
,
'%03d'
%
(
now
[
0
]
%
100
),
'year without century rendered using fieldwidth'
),
)
if
verbose
:
print
"Strftime test, platform: %s, Python version: %s"
%
\
(
sys
.
platform
,
string
.
split
(
sys
.
version
)[
0
])
for
e
in
expectations
:
try
:
result
=
time
.
strftime
(
e
[
0
],
now
)
except
ValueError
,
error
:
print
"Standard '%s' format gave error:"
%
e
[
0
],
error
continue
if
re
.
match
(
e
[
1
],
result
):
continue
if
not
result
or
result
[
0
]
==
'%'
:
print
"Does not support standard '%s' format (%s)"
%
(
e
[
0
],
e
[
2
])
else
:
print
"Conflict for %s (%s):"
%
(
e
[
0
],
e
[
2
])
print
" Expected %s, but got %s"
%
(
e
[
1
],
result
)
for
e
in
nonstandard_expectations
:
try
:
result
=
time
.
strftime
(
e
[
0
],
now
)
except
ValueError
,
result
:
if
verbose
:
print
"Error for nonstandard '%s' format (%s): %s"
%
\
(
e
[
0
],
e
[
2
],
str
(
result
))
continue
if
re
.
match
(
e
[
1
],
result
):
if
verbose
:
print
"Supports nonstandard '%s' format (%s)"
%
(
e
[
0
],
e
[
2
])
elif
not
result
or
result
[
0
]
==
'%'
:
if
verbose
:
print
"Does not appear to support '%s' format (%s)"
%
(
e
[
0
],
e
[
2
])
else
:
if
verbose
:
print
"Conflict for nonstandard '%s' format (%s):"
%
(
e
[
0
],
e
[
2
])
print
" Expected %s, but got %s"
%
(
e
[
1
],
result
)
def
fixasctime
(
s
):
if
s
[
8
]
==
' '
:
s
=
s
[:
8
]
+
'0'
+
s
[
9
:]
return
s
main
()
f
.
write
(
"frobnitz"
)
except
ValueError
,
e
:
print
"Caught expected ValueError writing to closed StringIO:"
print
e
else
:
print
"Failed to catch ValueError writing to closed StringIO."
# Don't bother testing cStringIO without
import
StringIO
,
cStringIO
do_test
(
StringIO
)
do_test
(
cStringIO
)
Lib/dos-8x3/test_unp.py
View file @
a8268e94
...
...
@@ -47,6 +47,18 @@ a, b, c = Seq()
if
a
<>
0
or
b
<>
1
or
c
<>
2
:
raise
TestFailed
# single element unpacking, with extra syntax
if
verbose
:
print
'unpack single tuple/list'
st
=
(
99
,)
sl
=
[
100
]
a
,
=
st
if
a
<>
99
:
raise
TestFailed
b
,
=
sl
if
b
<>
100
:
raise
TestFailed
# now for some failures
# unpacking non-sequence
...
...
Lib/dos-8x3/test_url.py
View file @
a8268e94
# Minimal test of the quote function
import
urllib
chars
=
'abcdefghijklmnopqrstuvwxyz'
\
'
\
337
\
340
\
341
\
342
\
343
\
344
\
345
\
346
\
347
\
350
\
351
\
352
\
353
\
354
\
355
\
356
'
\
'
\
357
\
360
\
361
\
362
\
363
\
364
\
365
\
366
\
370
\
371
\
372
\
373
\
374
\
375
\
376
\
377
'
\
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
\
'
\
300
\
301
\
302
\
303
\
304
\
305
\
306
\
307
\
310
\
311
\
312
\
313
\
314
\
315
\
316
\
317
'
\
'
\
320
\
321
\
322
\
323
\
324
\
325
\
326
\
330
\
331
\
332
\
333
\
334
\
335
\
336
'
expected
=
'abcdefghijklmnopqrstuvwxyz%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f8%f9%fa%fb%fc%fd%fe%ffABCDEFGHIJKLMNOPQRSTUVWXYZ%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d8%d9%da%db%dc%dd%de'
test
=
urllib
.
quote
(
chars
)
assert
test
==
expected
,
"urllib.quote problem"
test2
=
urllib
.
unquote
(
expected
)
assert
test2
==
chars
in1
=
"abc/def"
out1_1
=
"abc/def"
out1_2
=
"abc%2fdef"
assert
urllib
.
quote
(
in1
)
==
out1_1
,
"urllib.quote problem"
assert
urllib
.
quote
(
in1
,
''
)
==
out1_2
,
"urllib.quote problem"
in2
=
"abc?def"
out2_1
=
"abc%3fdef"
out2_2
=
"abc?def"
assert
urllib
.
quote
(
in2
)
==
out2_1
,
"urllib.quote problem"
assert
urllib
.
quote
(
in2
,
'?'
)
==
out2_2
,
"urllib.quote problem"
Lib/dos-8x3/test_win.py
View file @
a8268e94
# Ridiculously simple test of the winsound module for Windows.
# Test the windows specific win32reg module.
# Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
import
winsound
for
i
in
range
(
100
,
2000
,
100
):
winsound
.
Beep
(
i
,
75
)
print
"Hopefully you heard some sounds increasing in frequency!"
from
_winreg
import
*
import
os
,
sys
test_key_name
=
"SOFTWARE
\
\
Python Registry Test Key - Delete Me"
test_data
=
[
(
"Int Value"
,
45
,
REG_DWORD
),
(
"String Val"
,
"A string value"
,
REG_SZ
,),
(
u"Unicode Val"
,
u"A Unicode value"
,
REG_SZ
,),
(
"StringExpand"
,
"The path is %path%"
,
REG_EXPAND_SZ
),
(
"UnicodeExpand"
,
u"The path is %path%"
,
REG_EXPAND_SZ
),
(
"Multi-string"
,
[
"Lots"
,
"of"
,
"string"
,
"values"
],
REG_MULTI_SZ
),
(
"Multi-unicode"
,
[
u"Lots"
,
u"of"
,
u"unicode"
,
u"values"
],
REG_MULTI_SZ
),
(
"Multi-mixed"
,
[
u"Unicode"
,
u"and"
,
"string"
,
"values"
],
REG_MULTI_SZ
),
(
"Raw Data"
,
(
"binary"
+
chr
(
0
)
+
"data"
),
REG_BINARY
),
]
def
WriteTestData
(
root_key
):
# Set the default value for this key.
SetValue
(
root_key
,
test_key_name
,
REG_SZ
,
"Default value"
)
key
=
CreateKey
(
root_key
,
test_key_name
)
# Create a sub-key
sub_key
=
CreateKey
(
key
,
"sub_key"
)
# Give the sub-key some named values
for
value_name
,
value_data
,
value_type
in
test_data
:
SetValueEx
(
sub_key
,
value_name
,
0
,
value_type
,
value_data
)
# Check we wrote as many items as we thought.
nkeys
,
nvalues
,
since_mod
=
QueryInfoKey
(
key
)
assert
nkeys
==
1
,
"Not the correct number of sub keys"
assert
nvalues
==
1
,
"Not the correct number of values"
nkeys
,
nvalues
,
since_mod
=
QueryInfoKey
(
sub_key
)
assert
nkeys
==
0
,
"Not the correct number of sub keys"
assert
nvalues
==
len
(
test_data
),
"Not the correct number of values"
# Close this key this way...
# (but before we do, copy the key as an integer - this allows
# us to test that the key really gets closed).
int_sub_key
=
int
(
sub_key
)
CloseKey
(
sub_key
)
try
:
QueryInfoKey
(
int_sub_key
)
raise
RuntimeError
,
"It appears the CloseKey() function does not close the actual key!"
except
EnvironmentError
:
pass
# ... and close that key that way :-)
int_key
=
int
(
key
)
key
.
Close
()
try
:
QueryInfoKey
(
int_key
)
raise
RuntimeError
,
"It appears the key.Close() function does not close the actual key!"
except
EnvironmentError
:
pass
def
ReadTestData
(
root_key
):
# Check we can get default value for this key.
val
=
QueryValue
(
root_key
,
test_key_name
)
assert
val
==
"Default value"
,
"Registry didn't give back the correct value"
key
=
OpenKey
(
root_key
,
test_key_name
)
# Read the sub-keys
sub_key
=
OpenKey
(
key
,
"sub_key"
)
# Check I can enumerate over the values.
index
=
0
while
1
:
try
:
data
=
EnumValue
(
sub_key
,
index
)
except
EnvironmentError
:
break
assert
data
in
test_data
,
"Didn't read back the correct test data"
index
=
index
+
1
assert
index
==
len
(
test_data
),
"Didn't read the correct number of items"
# Check I can directly access each item
for
value_name
,
value_data
,
value_type
in
test_data
:
read_val
,
read_typ
=
QueryValueEx
(
sub_key
,
value_name
)
assert
read_val
==
value_data
and
read_typ
==
value_type
,
\
"Could not directly read the value"
sub_key
.
Close
()
# Enumerate our main key.
read_val
=
EnumKey
(
key
,
0
)
assert
read_val
==
"sub_key"
,
"Read subkey value wrong"
try
:
EnumKey
(
key
,
1
)
assert
0
,
"Was able to get a second key when I only have one!"
except
EnvironmentError
:
pass
key
.
Close
()
def
DeleteTestData
(
root_key
):
key
=
OpenKey
(
root_key
,
test_key_name
,
0
,
KEY_ALL_ACCESS
)
sub_key
=
OpenKey
(
key
,
"sub_key"
,
0
,
KEY_ALL_ACCESS
)
# It is not necessary to delete the values before deleting
# the key (although subkeys must not exist). We delete them
# manually just to prove we can :-)
for
value_name
,
value_data
,
value_type
in
test_data
:
DeleteValue
(
sub_key
,
value_name
)
nkeys
,
nvalues
,
since_mod
=
QueryInfoKey
(
sub_key
)
assert
nkeys
==
0
and
nvalues
==
0
,
"subkey not empty before delete"
sub_key
.
Close
()
DeleteKey
(
key
,
"sub_key"
)
try
:
# Shouldnt be able to delete it twice!
DeleteKey
(
key
,
"sub_key"
)
assert
0
,
"Deleting the key twice succeeded"
except
EnvironmentError
:
pass
key
.
Close
()
DeleteKey
(
root_key
,
test_key_name
)
# Opening should now fail!
try
:
key
=
OpenKey
(
root_key
,
test_key_name
)
assert
0
,
"Could open the non-existent key"
except
WindowsError
:
# Use this error name this time
pass
def
TestAll
(
root_key
):
WriteTestData
(
root_key
)
ReadTestData
(
root_key
)
DeleteTestData
(
root_key
)
# Test on my local machine.
TestAll
(
HKEY_CURRENT_USER
)
print
"Local registry tests worked"
try
:
remote_name
=
sys
.
argv
[
sys
.
argv
.
index
(
"--remote"
)
+
1
]
except
(
IndexError
,
ValueError
):
remote_name
=
None
if
remote_name
is
not
None
:
try
:
remote_key
=
ConnectRegistry
(
remote_name
,
HKEY_CURRENT_USER
)
except
EnvironmentError
,
exc
:
print
"Could not connect to the remote machine -"
,
exc
.
strerror
remote_key
=
None
if
remote_key
is
not
None
:
TestAll
(
remote_key
)
print
"Remote registry tests worked"
else
:
print
"Remote registry calls can be tested using"
,
print
"'test_winreg.py --remote
\
\
\
\
machine_name'"
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