mirror of https://github.com/python/cpython
The usual.
This commit is contained in:
parent
6dd87830d0
commit
de554ece41
|
@ -3,7 +3,7 @@
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
import array
|
import array
|
||||||
from test_support import verbose
|
from test_support import verbose, TESTFN, unlink
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
@ -12,10 +12,11 @@ def main():
|
||||||
for type in (['b', 'h', 'i', 'l', 'f', 'd']):
|
for type in (['b', 'h', 'i', 'l', 'f', 'd']):
|
||||||
testtype(type, 1)
|
testtype(type, 1)
|
||||||
|
|
||||||
|
unlink(TESTFN)
|
||||||
|
|
||||||
|
|
||||||
def testtype(type, example):
|
def testtype(type, example):
|
||||||
|
|
||||||
|
|
||||||
a = array.array(type)
|
a = array.array(type)
|
||||||
a.append(example)
|
a.append(example)
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -27,10 +28,14 @@ def testtype(type, example):
|
||||||
a.byteswap()
|
a.byteswap()
|
||||||
|
|
||||||
if a.typecode == 'c':
|
if a.typecode == 'c':
|
||||||
f = open('/etc/passwd', 'r')
|
f = open(TESTFN, "w")
|
||||||
|
f.write("The quick brown fox jumps over the lazy dog.\n")
|
||||||
|
f.close()
|
||||||
|
f = open(TESTFN, 'r')
|
||||||
a.fromfile(f, 10)
|
a.fromfile(f, 10)
|
||||||
|
f.close()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'char array with 10 bytes of /etc/passwd appended: ', a
|
print 'char array with 10 bytes of TESTFN appended: ', a
|
||||||
a.fromlist(['a', 'b', 'c'])
|
a.fromlist(['a', 'b', 'c'])
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'char array with list appended: ', a
|
print 'char array with list appended: ', a
|
||||||
|
@ -38,8 +43,9 @@ def testtype(type, example):
|
||||||
a.insert(0, example)
|
a.insert(0, example)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'array of %s after inserting another:' % a.typecode, a
|
print 'array of %s after inserting another:' % a.typecode, a
|
||||||
f = open('/dev/null', 'w')
|
f = open(TESTFN, 'w')
|
||||||
a.tofile(f)
|
a.tofile(f)
|
||||||
|
f.close()
|
||||||
a.tolist()
|
a.tolist()
|
||||||
a.tostring()
|
a.tostring()
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -48,5 +54,6 @@ def testtype(type, example):
|
||||||
print 'array of %s converted to a string: ' \
|
print 'array of %s converted to a string: ' \
|
||||||
% a.typecode, a.tostring()
|
% a.typecode, a.tostring()
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
|
||||||
'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
|
'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
|
||||||
'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
|
'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
|
||||||
'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
|
'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
|
||||||
'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTSOCK',
|
'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK',
|
||||||
'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
|
'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
|
||||||
'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
|
'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
|
||||||
'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
|
'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
|
||||||
|
@ -39,6 +39,11 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
|
||||||
# test seems to work on SGI, Sparc & intel Solaris, and linux.
|
# test seems to work on SGI, Sparc & intel Solaris, and linux.
|
||||||
#
|
#
|
||||||
for error in errors:
|
for error in errors:
|
||||||
|
try:
|
||||||
a = getattr(errno, error)
|
a = getattr(errno, error)
|
||||||
|
except AttributeError:
|
||||||
|
if verbose:
|
||||||
|
print '%s: not found' % error
|
||||||
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print '%s: %d' % (error, a)
|
print '%s: %d' % (error, a)
|
||||||
|
|
|
@ -83,8 +83,8 @@ x = 3.1e4
|
||||||
|
|
||||||
print '1.1.3 String literals'
|
print '1.1.3 String literals'
|
||||||
|
|
||||||
def assert(s):
|
##def assert(s):
|
||||||
if not s: raise TestFailed, 'see traceback'
|
## if not s: raise TestFailed, 'see traceback'
|
||||||
|
|
||||||
x = ''; y = ""; assert(len(x) == 0 and x == y)
|
x = ''; y = ""; assert(len(x) == 0 and x == y)
|
||||||
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""Test script for the imageop module. This has the side
|
"""Test script for the imageop module. This has the side
|
||||||
effect of partially testing the imgfile module as well.
|
effect of partially testing the imgfile module as well.
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
from test_support import verbose
|
|
||||||
|
|
||||||
import imageop
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
|
import imageop, uu
|
||||||
|
|
||||||
def main(use_rgbimg=1):
|
def main(use_rgbimg=1):
|
||||||
|
|
||||||
|
# Create binary test files
|
||||||
|
uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb')
|
||||||
|
|
||||||
if use_rgbimg:
|
if use_rgbimg:
|
||||||
image, width, height = getrgbimage('test.rgb')
|
image, width, height = getrgbimage('test.rgb')
|
||||||
else:
|
else:
|
||||||
|
@ -108,6 +113,9 @@ def main(use_rgbimg=1):
|
||||||
print 'grey22grey'
|
print 'grey22grey'
|
||||||
image = imageop.grey22grey (grey2image, width, height)
|
image = imageop.grey22grey (grey2image, width, height)
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
unlink('test.rgb')
|
||||||
|
|
||||||
def getrgbimage(name):
|
def getrgbimage(name):
|
||||||
"""return a tuple consisting of image (in 'imgfile' format but
|
"""return a tuple consisting of image (in 'imgfile' format but
|
||||||
using rgbimg instead) width and height"""
|
using rgbimg instead) width and height"""
|
||||||
|
@ -160,6 +168,6 @@ def get_qualified_path(name):
|
||||||
name = string.joinfields(parts, os.sep)
|
name = string.joinfields(parts, os.sep)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
# rgbimg (unlike imgfile) is portable to platforms other than SGI. So we prefer to use it.
|
# rgbimg (unlike imgfile) is portable to platforms other than SGI.
|
||||||
|
# So we prefer to use it.
|
||||||
main(use_rgbimg=1)
|
main(use_rgbimg=1)
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,35 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""Simple test script for imgfile.c
|
"""Simple test script for imgfile.c
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
from test_support import verbose
|
|
||||||
|
|
||||||
import imgfile
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
|
import imgfile, uu, os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
uu.decode(findfile('testrgb.uue'), 'test.rgb')
|
||||||
|
uu.decode(findfile('greyrgb.uue'), 'greytest.rgb')
|
||||||
|
|
||||||
# Test a 3 byte color image
|
# Test a 3 byte color image
|
||||||
testimage('test.rgb')
|
testimage('test.rgb')
|
||||||
|
|
||||||
# Test a 1 byte greyscale image
|
# Test a 1 byte greyscale image
|
||||||
testimage('greytest.rgb')
|
testimage('greytest.rgb')
|
||||||
|
|
||||||
|
unlink('test.rgb')
|
||||||
|
unlink('greytest.rgb')
|
||||||
|
|
||||||
|
def findfile(file):
|
||||||
|
if os.path.isabs(file): return file
|
||||||
|
import sys
|
||||||
|
for dn in sys.path:
|
||||||
|
fn = os.path.join(dn, file)
|
||||||
|
if os.path.exists(fn): return fn
|
||||||
|
return file
|
||||||
|
|
||||||
def testimage(name):
|
def testimage(name):
|
||||||
"""Run through the imgfile's battery of possible methods
|
"""Run through the imgfile's battery of possible methods
|
||||||
|
|
|
@ -1,5 +1,77 @@
|
||||||
# Python test set -- part 3, built-in operations.
|
import operator
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def test(name, input, output, *args):
|
||||||
|
print 'testing:', name
|
||||||
|
f = getattr(operator, name)
|
||||||
|
params = (input,) + args
|
||||||
|
try:
|
||||||
|
val = apply(f, params)
|
||||||
|
except:
|
||||||
|
val = sys.exc_type
|
||||||
|
if val <> output:
|
||||||
|
print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
|
||||||
|
|
||||||
|
test('abs', -1, 1)
|
||||||
|
test('add', 3, 7, 4)
|
||||||
|
test('and_', 0xf, 0xa, 0xa)
|
||||||
|
test('concat', 'py', 'python', 'thon')
|
||||||
|
|
||||||
|
test('countOf', [1, 2, 1, 3, 1, 4], 1, 3)
|
||||||
|
|
||||||
|
a = [4, 3, 2, 1]
|
||||||
|
test('delitem', a, None, 1)
|
||||||
|
if a <> [4, 2, 1]:
|
||||||
|
print 'delitem() failed'
|
||||||
|
|
||||||
|
a = range(10)
|
||||||
|
test('delslice', a, None, 2, 8)
|
||||||
|
if a <> [0, 1, 8, 9]:
|
||||||
|
print 'delslice() failed'
|
||||||
|
|
||||||
|
a = range(10)
|
||||||
|
test('div', 5, 2, 2)
|
||||||
|
test('getitem', a, 2, 2)
|
||||||
|
test('getslice', a, [4, 5], 4, 6)
|
||||||
|
test('indexOf', [4, 3, 2, 1], 1, 3)
|
||||||
|
test('inv', 4, -5)
|
||||||
|
test('isCallable', 4, 0)
|
||||||
|
test('isCallable', operator.isCallable, 1)
|
||||||
|
test('isMappingType', operator.isMappingType, 0)
|
||||||
|
test('isMappingType', operator.__dict__, 1)
|
||||||
|
test('isNumberType', 8.3, 1)
|
||||||
|
test('isNumberType', dir(), 0)
|
||||||
|
test('isSequenceType', dir(), 1)
|
||||||
|
test('isSequenceType', 'yeahbuddy', 1)
|
||||||
|
test('isSequenceType', 3, 0)
|
||||||
|
test('lshift', 5, 10, 1)
|
||||||
|
test('mod', 5, 1, 2)
|
||||||
|
test('mul', 5, 10, 2)
|
||||||
|
test('neg', 5, -5)
|
||||||
|
test('or_', 0xa, 0xf, 0x5)
|
||||||
|
test('pos', -5, -5)
|
||||||
|
|
||||||
|
a = range(3)
|
||||||
|
test('repeat', a, a+a, 2)
|
||||||
|
test('rshift', 5, 2, 1)
|
||||||
|
|
||||||
|
test('sequenceIncludes', range(4), 1, 2)
|
||||||
|
test('sequenceIncludes', range(4), 0, 5)
|
||||||
|
|
||||||
|
test('setitem', a, None, 0, 2)
|
||||||
|
if a <> [2, 1, 2]:
|
||||||
|
print 'setitem() failed'
|
||||||
|
|
||||||
|
a = range(4)
|
||||||
|
test('setslice', a, None, 1, 3, [2, 1])
|
||||||
|
if a <> [0, 2, 1, 3]:
|
||||||
|
print 'setslice() failed:', a
|
||||||
|
|
||||||
|
test('sub', 5, 2, 3)
|
||||||
|
test('truth', 5, 1)
|
||||||
|
test('truth', [], 0)
|
||||||
|
test('xor', 0xb, 0x7, 0xc)
|
||||||
|
|
||||||
|
|
||||||
print '3. Operations'
|
# some negative tests
|
||||||
print 'XXX Not yet implemented'
|
test('indexOf', [4, 3, 2, 1], ValueError, 9)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Testing rgbimg module
|
# Testing rgbimg module
|
||||||
|
|
||||||
import rgbimg, os
|
import rgbimg, os, uu
|
||||||
|
|
||||||
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
error = 'test_rgbimg.error'
|
error = 'test_rgbimg.error'
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ def testimg(rgb_file, raw_file):
|
||||||
rgb = rgbimg.longimagedata(rgb_file)
|
rgb = rgbimg.longimagedata(rgb_file)
|
||||||
if len(rgb) != width * height * 4:
|
if len(rgb) != width * height * 4:
|
||||||
raise error, 'bad image length'
|
raise error, 'bad image length'
|
||||||
raw = open(raw_file, 'r').read()
|
raw = open(raw_file, 'rb').read()
|
||||||
if rgb != raw:
|
if rgb != raw:
|
||||||
raise error, \
|
raise error, \
|
||||||
'images don\'t match for '+rgb_file+' and '+raw_file
|
'images don\'t match for '+rgb_file+' and '+raw_file
|
||||||
|
@ -29,6 +31,21 @@ def testimg(rgb_file, raw_file):
|
||||||
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
||||||
os.unlink('@.rgb')
|
os.unlink('@.rgb')
|
||||||
|
|
||||||
|
table = [
|
||||||
|
('testrgb.uue', 'test.rgb'),
|
||||||
|
('testimg.uue', 'test.rawimg'),
|
||||||
|
('testimgr.uue', 'test.rawimg.rev'),
|
||||||
|
]
|
||||||
|
for source, target in table:
|
||||||
|
source = findfile(source)
|
||||||
|
target = findfile(target)
|
||||||
|
if verbose:
|
||||||
|
print "uudecoding", source, "->", target, "..."
|
||||||
|
uu.decode(source, target)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print "testing..."
|
||||||
|
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should start out as zero'
|
raise error, 'ttob should start out as zero'
|
||||||
|
@ -48,3 +65,6 @@ if ttob != 1:
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should be zero'
|
raise error, 'ttob should be zero'
|
||||||
|
|
||||||
|
for source, target in table:
|
||||||
|
unlink(findfile(target))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Testing select module
|
# Testing select module
|
||||||
|
from test_support import verbose
|
||||||
import select
|
import select
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -33,9 +34,15 @@ else:
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
import sys
|
||||||
|
if sys.platform in ('win', 'mac'):
|
||||||
|
if verbose:
|
||||||
|
print "Can't test select easily"
|
||||||
|
return
|
||||||
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
|
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')
|
p = os.popen(cmd, 'r')
|
||||||
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
|
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
|
||||||
|
if verbose:
|
||||||
print 'timeout =', tout
|
print 'timeout =', tout
|
||||||
rfd, wfd, xfd = select.select([p], [], [], tout)
|
rfd, wfd, xfd = select.select([p], [], [], tout)
|
||||||
## print rfd, wfd, xfd
|
## print rfd, wfd, xfd
|
||||||
|
@ -43,8 +50,10 @@ def test():
|
||||||
continue
|
continue
|
||||||
if (rfd, wfd, xfd) == ([p], [], []):
|
if (rfd, wfd, xfd) == ([p], [], []):
|
||||||
line = p.readline()
|
line = p.readline()
|
||||||
|
if verbose:
|
||||||
print `line`
|
print `line`
|
||||||
if not line:
|
if not line:
|
||||||
|
if verbose:
|
||||||
print 'EOF'
|
print 'EOF'
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
from test_support import verbose
|
from test_support import verbose
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.platform[:3] == 'win':
|
||||||
|
raise ImportError, "Can't test signal on Windows"
|
||||||
|
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -1,72 +1,128 @@
|
||||||
from test_support import verbose
|
#! /usr/bin/env python
|
||||||
import strop, sys
|
|
||||||
|
|
||||||
def test(name, input, output, *args):
|
# Sanity checker for time.strftime
|
||||||
|
|
||||||
|
import time, calendar, sys, string, os
|
||||||
|
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:
|
if verbose:
|
||||||
print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
|
print "strftime test for", time.ctime(now)
|
||||||
f = getattr(strop, name)
|
nowsecs = int(now)
|
||||||
|
gmt = time.gmtime(now)
|
||||||
|
now = time.localtime(now)
|
||||||
|
|
||||||
|
if now[3] < 12: ampm='AM'
|
||||||
|
else: ampm='PM'
|
||||||
|
|
||||||
|
jan1 = time.localtime(time.mktime((now[0], 1, 1) + (0,)*6))
|
||||||
|
|
||||||
|
if now[8]: tz = time.tzname[1]
|
||||||
|
else: tz = time.tzname[0]
|
||||||
|
|
||||||
|
if now[3] > 12: clock12 = now[3] - 12
|
||||||
|
elif now[3] > 0: clock12 = now[3]
|
||||||
|
else: clock12 = 12
|
||||||
|
|
||||||
|
expectations = (
|
||||||
|
('%A', calendar.day_name[now[6]], 'full weekday name'),
|
||||||
|
('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
|
||||||
|
('%B', calendar.month_name[now[1]], 'full month name'),
|
||||||
|
('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
|
||||||
|
('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
|
||||||
|
('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
|
||||||
|
('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
|
||||||
|
('%d', '%02d' % now[2], 'day of month as number (00-31)'),
|
||||||
|
('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-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[4], 'minute, (00-59)'),
|
||||||
|
('%m', '%02d' % now[1], 'month as number (01-12)'),
|
||||||
|
('%p', ampm, 'AM or PM as appropriate'),
|
||||||
|
('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
|
||||||
|
('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm),
|
||||||
|
'%I:%M:%S %p'),
|
||||||
|
('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
|
||||||
|
('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
|
||||||
|
('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
|
||||||
|
('%U', '%02d' % ((now[7] + jan1[6])/7),
|
||||||
|
'week number of the year (Sun 1st)'),
|
||||||
|
('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)/7),
|
||||||
|
'week number of the year (Mon 1st)'),
|
||||||
|
('%w', '%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
|
||||||
|
('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
|
||||||
|
'%m/%d/%y %H:%M:%S'),
|
||||||
|
('%Y', '%d' % now[0], 'year with century'),
|
||||||
|
('%y', '%02d' % (now[0]%100), 'year without century'),
|
||||||
|
('%Z', tz, 'time zone name'),
|
||||||
|
('%%', '%', 'single percent sign'),
|
||||||
|
)
|
||||||
|
|
||||||
|
nonstandard_expectations = (
|
||||||
|
('%C', '%02d' % (now[0]/100), 'century'),
|
||||||
|
# This is for IRIX; on Solaris, %C yields date(1) format.
|
||||||
|
# Tough.
|
||||||
|
('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
|
||||||
|
('%s', '%d' % nowsecs, 'seconds since the Epoch in UCT'),
|
||||||
|
('%3y', '%03d' % (now[0]%100),
|
||||||
|
'year without century rendered using fieldwidth'),
|
||||||
|
('%n', '\n', 'newline character'),
|
||||||
|
('%t', '\t', 'tab character'),
|
||||||
|
)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print "Strftime test, platform: %s, Python version: %s" % \
|
||||||
|
(sys.platform, string.split(sys.version)[0])
|
||||||
|
|
||||||
|
for e in expectations:
|
||||||
try:
|
try:
|
||||||
value = apply(f, (input,) + args)
|
result = time.strftime(e[0], now)
|
||||||
except:
|
except ValueError, error:
|
||||||
value = sys.exc_type
|
print "Standard '%s' format gave error:" % e[0], error
|
||||||
if value != output:
|
continue
|
||||||
|
if result == e[1]: continue
|
||||||
|
if 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:
|
if verbose:
|
||||||
print 'no'
|
print "Error for nonstandard '%s' format (%s): %s" % \
|
||||||
print f, `input`, `output`, `value`
|
(e[0], e[2], str(error))
|
||||||
|
continue
|
||||||
|
if result == e[1]:
|
||||||
|
if verbose:
|
||||||
|
print "Supports nonstandard '%s' format (%s)" % (e[0], e[2])
|
||||||
|
elif result[0] == '%':
|
||||||
|
if verbose:
|
||||||
|
print "Does not appear to support '%s' format (%s)" % (e[0],
|
||||||
|
e[2])
|
||||||
else:
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'yes'
|
print "Conflict for nonstandard '%s' format (%s):" % (e[0],
|
||||||
|
e[2])
|
||||||
|
print " Expected %s, but got %s" % (e[1], result)
|
||||||
|
|
||||||
test('atoi', " 1 ", 1)
|
def fixasctime(s):
|
||||||
test('atoi', " 1x", ValueError)
|
if s[8] == ' ':
|
||||||
test('atoi', " x1 ", ValueError)
|
s = s[:8] + '0' + s[9:]
|
||||||
test('atol', " 1 ", 1L)
|
return s
|
||||||
test('atol', " 1x ", ValueError)
|
|
||||||
test('atol', " x1 ", ValueError)
|
|
||||||
test('atof', " 1 ", 1.0)
|
|
||||||
test('atof', " 1x ", ValueError)
|
|
||||||
test('atof', " x1 ", ValueError)
|
|
||||||
|
|
||||||
test('capitalize', ' hello ', ' hello ')
|
main()
|
||||||
test('capitalize', 'hello ', 'Hello ')
|
|
||||||
test('find', 'abcdefghiabc', 0, 'abc')
|
|
||||||
test('find', 'abcdefghiabc', 9, 'abc', 1)
|
|
||||||
test('find', 'abcdefghiabc', -1, 'def', 4)
|
|
||||||
test('rfind', 'abcdefghiabc', 9, 'abc')
|
|
||||||
test('lower', 'HeLLo', 'hello')
|
|
||||||
test('upper', 'HeLLo', 'HELLO')
|
|
||||||
|
|
||||||
transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
|
|
||||||
|
|
||||||
test('maketrans', 'abc', transtable, 'xyz')
|
|
||||||
test('maketrans', 'abc', ValueError, 'xyzq')
|
|
||||||
|
|
||||||
test('split', 'this is the split function',
|
|
||||||
['this', 'is', 'the', 'split', 'function'])
|
|
||||||
test('split', 'a|b|c|d', ['a', 'b', 'c', 'd'], '|')
|
|
||||||
test('split', 'a|b|c|d', ['a', 'b', 'c|d'], '|', 2)
|
|
||||||
|
|
||||||
# join now works with any sequence type
|
|
||||||
class Sequence:
|
|
||||||
def __init__(self): self.seq = 'wxyz'
|
|
||||||
def __len__(self): return len(self.seq)
|
|
||||||
def __getitem__(self, i): return self.seq[i]
|
|
||||||
|
|
||||||
test('join', ['a', 'b', 'c', 'd'], 'a b c d')
|
|
||||||
test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
|
|
||||||
test('join', Sequence(), 'w x y z')
|
|
||||||
|
|
||||||
# try a few long ones
|
|
||||||
print strop.join(['x' * 100] * 100, ':')
|
|
||||||
print strop.join(('x' * 100,) * 100, ':')
|
|
||||||
|
|
||||||
test('strip', ' hello ', 'hello')
|
|
||||||
test('lstrip', ' hello ', 'hello ')
|
|
||||||
test('rstrip', ' hello ', ' hello')
|
|
||||||
|
|
||||||
test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
|
|
||||||
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')
|
|
||||||
|
|
||||||
strop.whitespace
|
|
||||||
strop.lowercase
|
|
||||||
strop.uppercase
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
import array
|
import array
|
||||||
from test_support import verbose
|
from test_support import verbose, TESTFN, unlink
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
@ -12,10 +12,11 @@ def main():
|
||||||
for type in (['b', 'h', 'i', 'l', 'f', 'd']):
|
for type in (['b', 'h', 'i', 'l', 'f', 'd']):
|
||||||
testtype(type, 1)
|
testtype(type, 1)
|
||||||
|
|
||||||
|
unlink(TESTFN)
|
||||||
|
|
||||||
|
|
||||||
def testtype(type, example):
|
def testtype(type, example):
|
||||||
|
|
||||||
|
|
||||||
a = array.array(type)
|
a = array.array(type)
|
||||||
a.append(example)
|
a.append(example)
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -27,10 +28,14 @@ def testtype(type, example):
|
||||||
a.byteswap()
|
a.byteswap()
|
||||||
|
|
||||||
if a.typecode == 'c':
|
if a.typecode == 'c':
|
||||||
f = open('/etc/passwd', 'r')
|
f = open(TESTFN, "w")
|
||||||
|
f.write("The quick brown fox jumps over the lazy dog.\n")
|
||||||
|
f.close()
|
||||||
|
f = open(TESTFN, 'r')
|
||||||
a.fromfile(f, 10)
|
a.fromfile(f, 10)
|
||||||
|
f.close()
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'char array with 10 bytes of /etc/passwd appended: ', a
|
print 'char array with 10 bytes of TESTFN appended: ', a
|
||||||
a.fromlist(['a', 'b', 'c'])
|
a.fromlist(['a', 'b', 'c'])
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'char array with list appended: ', a
|
print 'char array with list appended: ', a
|
||||||
|
@ -38,8 +43,9 @@ def testtype(type, example):
|
||||||
a.insert(0, example)
|
a.insert(0, example)
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'array of %s after inserting another:' % a.typecode, a
|
print 'array of %s after inserting another:' % a.typecode, a
|
||||||
f = open('/dev/null', 'w')
|
f = open(TESTFN, 'w')
|
||||||
a.tofile(f)
|
a.tofile(f)
|
||||||
|
f.close()
|
||||||
a.tolist()
|
a.tolist()
|
||||||
a.tostring()
|
a.tostring()
|
||||||
if verbose:
|
if verbose:
|
||||||
|
@ -48,5 +54,6 @@ def testtype(type, example):
|
||||||
print 'array of %s converted to a string: ' \
|
print 'array of %s converted to a string: ' \
|
||||||
% a.typecode, a.tostring()
|
% a.typecode, a.tostring()
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
|
||||||
'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
|
'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK',
|
||||||
'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
|
'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT',
|
||||||
'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
|
'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK',
|
||||||
'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTSOCK',
|
'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK',
|
||||||
'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
|
'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP',
|
||||||
'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
|
'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE',
|
||||||
'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
|
'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE',
|
||||||
|
@ -39,6 +39,11 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
|
||||||
# test seems to work on SGI, Sparc & intel Solaris, and linux.
|
# test seems to work on SGI, Sparc & intel Solaris, and linux.
|
||||||
#
|
#
|
||||||
for error in errors:
|
for error in errors:
|
||||||
|
try:
|
||||||
a = getattr(errno, error)
|
a = getattr(errno, error)
|
||||||
|
except AttributeError:
|
||||||
|
if verbose:
|
||||||
|
print '%s: not found' % error
|
||||||
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print '%s: %d' % (error, a)
|
print '%s: %d' % (error, a)
|
||||||
|
|
|
@ -83,8 +83,8 @@ x = 3.1e4
|
||||||
|
|
||||||
print '1.1.3 String literals'
|
print '1.1.3 String literals'
|
||||||
|
|
||||||
def assert(s):
|
##def assert(s):
|
||||||
if not s: raise TestFailed, 'see traceback'
|
## if not s: raise TestFailed, 'see traceback'
|
||||||
|
|
||||||
x = ''; y = ""; assert(len(x) == 0 and x == y)
|
x = ''; y = ""; assert(len(x) == 0 and x == y)
|
||||||
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""Test script for the imageop module. This has the side
|
"""Test script for the imageop module. This has the side
|
||||||
effect of partially testing the imgfile module as well.
|
effect of partially testing the imgfile module as well.
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
from test_support import verbose
|
|
||||||
|
|
||||||
import imageop
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
|
import imageop, uu
|
||||||
|
|
||||||
def main(use_rgbimg=1):
|
def main(use_rgbimg=1):
|
||||||
|
|
||||||
|
# Create binary test files
|
||||||
|
uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb')
|
||||||
|
|
||||||
if use_rgbimg:
|
if use_rgbimg:
|
||||||
image, width, height = getrgbimage('test.rgb')
|
image, width, height = getrgbimage('test.rgb')
|
||||||
else:
|
else:
|
||||||
|
@ -108,6 +113,9 @@ def main(use_rgbimg=1):
|
||||||
print 'grey22grey'
|
print 'grey22grey'
|
||||||
image = imageop.grey22grey (grey2image, width, height)
|
image = imageop.grey22grey (grey2image, width, height)
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
unlink('test.rgb')
|
||||||
|
|
||||||
def getrgbimage(name):
|
def getrgbimage(name):
|
||||||
"""return a tuple consisting of image (in 'imgfile' format but
|
"""return a tuple consisting of image (in 'imgfile' format but
|
||||||
using rgbimg instead) width and height"""
|
using rgbimg instead) width and height"""
|
||||||
|
@ -160,6 +168,6 @@ def get_qualified_path(name):
|
||||||
name = string.joinfields(parts, os.sep)
|
name = string.joinfields(parts, os.sep)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
# rgbimg (unlike imgfile) is portable to platforms other than SGI. So we prefer to use it.
|
# rgbimg (unlike imgfile) is portable to platforms other than SGI.
|
||||||
|
# So we prefer to use it.
|
||||||
main(use_rgbimg=1)
|
main(use_rgbimg=1)
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,35 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
"""Simple test script for imgfile.c
|
"""Simple test script for imgfile.c
|
||||||
Roger E. Masse
|
Roger E. Masse
|
||||||
"""
|
"""
|
||||||
from test_support import verbose
|
|
||||||
|
|
||||||
import imgfile
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
|
import imgfile, uu, os
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
uu.decode(findfile('testrgb.uue'), 'test.rgb')
|
||||||
|
uu.decode(findfile('greyrgb.uue'), 'greytest.rgb')
|
||||||
|
|
||||||
# Test a 3 byte color image
|
# Test a 3 byte color image
|
||||||
testimage('test.rgb')
|
testimage('test.rgb')
|
||||||
|
|
||||||
# Test a 1 byte greyscale image
|
# Test a 1 byte greyscale image
|
||||||
testimage('greytest.rgb')
|
testimage('greytest.rgb')
|
||||||
|
|
||||||
|
unlink('test.rgb')
|
||||||
|
unlink('greytest.rgb')
|
||||||
|
|
||||||
|
def findfile(file):
|
||||||
|
if os.path.isabs(file): return file
|
||||||
|
import sys
|
||||||
|
for dn in sys.path:
|
||||||
|
fn = os.path.join(dn, file)
|
||||||
|
if os.path.exists(fn): return fn
|
||||||
|
return file
|
||||||
|
|
||||||
def testimage(name):
|
def testimage(name):
|
||||||
"""Run through the imgfile's battery of possible methods
|
"""Run through the imgfile's battery of possible methods
|
||||||
|
|
|
@ -1,5 +1,77 @@
|
||||||
# Python test set -- part 3, built-in operations.
|
import operator
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def test(name, input, output, *args):
|
||||||
|
print 'testing:', name
|
||||||
|
f = getattr(operator, name)
|
||||||
|
params = (input,) + args
|
||||||
|
try:
|
||||||
|
val = apply(f, params)
|
||||||
|
except:
|
||||||
|
val = sys.exc_type
|
||||||
|
if val <> output:
|
||||||
|
print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
|
||||||
|
|
||||||
|
test('abs', -1, 1)
|
||||||
|
test('add', 3, 7, 4)
|
||||||
|
test('and_', 0xf, 0xa, 0xa)
|
||||||
|
test('concat', 'py', 'python', 'thon')
|
||||||
|
|
||||||
|
test('countOf', [1, 2, 1, 3, 1, 4], 1, 3)
|
||||||
|
|
||||||
|
a = [4, 3, 2, 1]
|
||||||
|
test('delitem', a, None, 1)
|
||||||
|
if a <> [4, 2, 1]:
|
||||||
|
print 'delitem() failed'
|
||||||
|
|
||||||
|
a = range(10)
|
||||||
|
test('delslice', a, None, 2, 8)
|
||||||
|
if a <> [0, 1, 8, 9]:
|
||||||
|
print 'delslice() failed'
|
||||||
|
|
||||||
|
a = range(10)
|
||||||
|
test('div', 5, 2, 2)
|
||||||
|
test('getitem', a, 2, 2)
|
||||||
|
test('getslice', a, [4, 5], 4, 6)
|
||||||
|
test('indexOf', [4, 3, 2, 1], 1, 3)
|
||||||
|
test('inv', 4, -5)
|
||||||
|
test('isCallable', 4, 0)
|
||||||
|
test('isCallable', operator.isCallable, 1)
|
||||||
|
test('isMappingType', operator.isMappingType, 0)
|
||||||
|
test('isMappingType', operator.__dict__, 1)
|
||||||
|
test('isNumberType', 8.3, 1)
|
||||||
|
test('isNumberType', dir(), 0)
|
||||||
|
test('isSequenceType', dir(), 1)
|
||||||
|
test('isSequenceType', 'yeahbuddy', 1)
|
||||||
|
test('isSequenceType', 3, 0)
|
||||||
|
test('lshift', 5, 10, 1)
|
||||||
|
test('mod', 5, 1, 2)
|
||||||
|
test('mul', 5, 10, 2)
|
||||||
|
test('neg', 5, -5)
|
||||||
|
test('or_', 0xa, 0xf, 0x5)
|
||||||
|
test('pos', -5, -5)
|
||||||
|
|
||||||
|
a = range(3)
|
||||||
|
test('repeat', a, a+a, 2)
|
||||||
|
test('rshift', 5, 2, 1)
|
||||||
|
|
||||||
|
test('sequenceIncludes', range(4), 1, 2)
|
||||||
|
test('sequenceIncludes', range(4), 0, 5)
|
||||||
|
|
||||||
|
test('setitem', a, None, 0, 2)
|
||||||
|
if a <> [2, 1, 2]:
|
||||||
|
print 'setitem() failed'
|
||||||
|
|
||||||
|
a = range(4)
|
||||||
|
test('setslice', a, None, 1, 3, [2, 1])
|
||||||
|
if a <> [0, 2, 1, 3]:
|
||||||
|
print 'setslice() failed:', a
|
||||||
|
|
||||||
|
test('sub', 5, 2, 3)
|
||||||
|
test('truth', 5, 1)
|
||||||
|
test('truth', [], 0)
|
||||||
|
test('xor', 0xb, 0x7, 0xc)
|
||||||
|
|
||||||
|
|
||||||
print '3. Operations'
|
# some negative tests
|
||||||
print 'XXX Not yet implemented'
|
test('indexOf', [4, 3, 2, 1], ValueError, 9)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Testing rgbimg module
|
# Testing rgbimg module
|
||||||
|
|
||||||
import rgbimg, os
|
import rgbimg, os, uu
|
||||||
|
|
||||||
|
from test_support import verbose, unlink
|
||||||
|
|
||||||
error = 'test_rgbimg.error'
|
error = 'test_rgbimg.error'
|
||||||
|
|
||||||
|
@ -21,7 +23,7 @@ def testimg(rgb_file, raw_file):
|
||||||
rgb = rgbimg.longimagedata(rgb_file)
|
rgb = rgbimg.longimagedata(rgb_file)
|
||||||
if len(rgb) != width * height * 4:
|
if len(rgb) != width * height * 4:
|
||||||
raise error, 'bad image length'
|
raise error, 'bad image length'
|
||||||
raw = open(raw_file, 'r').read()
|
raw = open(raw_file, 'rb').read()
|
||||||
if rgb != raw:
|
if rgb != raw:
|
||||||
raise error, \
|
raise error, \
|
||||||
'images don\'t match for '+rgb_file+' and '+raw_file
|
'images don\'t match for '+rgb_file+' and '+raw_file
|
||||||
|
@ -29,6 +31,21 @@ def testimg(rgb_file, raw_file):
|
||||||
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
rgbimg.longstoimage(rgb, width, height, depth, '@.rgb')
|
||||||
os.unlink('@.rgb')
|
os.unlink('@.rgb')
|
||||||
|
|
||||||
|
table = [
|
||||||
|
('testrgb.uue', 'test.rgb'),
|
||||||
|
('testimg.uue', 'test.rawimg'),
|
||||||
|
('testimgr.uue', 'test.rawimg.rev'),
|
||||||
|
]
|
||||||
|
for source, target in table:
|
||||||
|
source = findfile(source)
|
||||||
|
target = findfile(target)
|
||||||
|
if verbose:
|
||||||
|
print "uudecoding", source, "->", target, "..."
|
||||||
|
uu.decode(source, target)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print "testing..."
|
||||||
|
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should start out as zero'
|
raise error, 'ttob should start out as zero'
|
||||||
|
@ -48,3 +65,6 @@ if ttob != 1:
|
||||||
ttob = rgbimg.ttob(0)
|
ttob = rgbimg.ttob(0)
|
||||||
if ttob != 0:
|
if ttob != 0:
|
||||||
raise error, 'ttob should be zero'
|
raise error, 'ttob should be zero'
|
||||||
|
|
||||||
|
for source, target in table:
|
||||||
|
unlink(findfile(target))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Testing select module
|
# Testing select module
|
||||||
|
from test_support import verbose
|
||||||
import select
|
import select
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -33,9 +34,15 @@ else:
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
import sys
|
||||||
|
if sys.platform in ('win', 'mac'):
|
||||||
|
if verbose:
|
||||||
|
print "Can't test select easily"
|
||||||
|
return
|
||||||
cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
|
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')
|
p = os.popen(cmd, 'r')
|
||||||
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
|
for tout in (0, 1, 2, 4, 8, 16) + (None,)*10:
|
||||||
|
if verbose:
|
||||||
print 'timeout =', tout
|
print 'timeout =', tout
|
||||||
rfd, wfd, xfd = select.select([p], [], [], tout)
|
rfd, wfd, xfd = select.select([p], [], [], tout)
|
||||||
## print rfd, wfd, xfd
|
## print rfd, wfd, xfd
|
||||||
|
@ -43,8 +50,10 @@ def test():
|
||||||
continue
|
continue
|
||||||
if (rfd, wfd, xfd) == ([p], [], []):
|
if (rfd, wfd, xfd) == ([p], [], []):
|
||||||
line = p.readline()
|
line = p.readline()
|
||||||
|
if verbose:
|
||||||
print `line`
|
print `line`
|
||||||
if not line:
|
if not line:
|
||||||
|
if verbose:
|
||||||
print 'EOF'
|
print 'EOF'
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
from test_support import verbose
|
from test_support import verbose
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.platform[:3] == 'win':
|
||||||
|
raise ImportError, "Can't test signal on Windows"
|
||||||
|
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -1,72 +1,128 @@
|
||||||
from test_support import verbose
|
#! /usr/bin/env python
|
||||||
import strop, sys
|
|
||||||
|
|
||||||
def test(name, input, output, *args):
|
# Sanity checker for time.strftime
|
||||||
|
|
||||||
|
import time, calendar, sys, string, os
|
||||||
|
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:
|
if verbose:
|
||||||
print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
|
print "strftime test for", time.ctime(now)
|
||||||
f = getattr(strop, name)
|
nowsecs = int(now)
|
||||||
|
gmt = time.gmtime(now)
|
||||||
|
now = time.localtime(now)
|
||||||
|
|
||||||
|
if now[3] < 12: ampm='AM'
|
||||||
|
else: ampm='PM'
|
||||||
|
|
||||||
|
jan1 = time.localtime(time.mktime((now[0], 1, 1) + (0,)*6))
|
||||||
|
|
||||||
|
if now[8]: tz = time.tzname[1]
|
||||||
|
else: tz = time.tzname[0]
|
||||||
|
|
||||||
|
if now[3] > 12: clock12 = now[3] - 12
|
||||||
|
elif now[3] > 0: clock12 = now[3]
|
||||||
|
else: clock12 = 12
|
||||||
|
|
||||||
|
expectations = (
|
||||||
|
('%A', calendar.day_name[now[6]], 'full weekday name'),
|
||||||
|
('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'),
|
||||||
|
('%B', calendar.month_name[now[1]], 'full month name'),
|
||||||
|
('%b', calendar.month_abbr[now[1]], 'abbreviated month name'),
|
||||||
|
('%h', calendar.month_abbr[now[1]], 'abbreviated month name'),
|
||||||
|
('%c', fixasctime(time.asctime(now)), 'near-asctime() format'),
|
||||||
|
('%D', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)), 'mm/dd/yy'),
|
||||||
|
('%d', '%02d' % now[2], 'day of month as number (00-31)'),
|
||||||
|
('%e', '%2d' % now[2], 'day of month as number, blank padded ( 0-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[4], 'minute, (00-59)'),
|
||||||
|
('%m', '%02d' % now[1], 'month as number (01-12)'),
|
||||||
|
('%p', ampm, 'AM or PM as appropriate'),
|
||||||
|
('%R', '%02d:%02d' % (now[3], now[4]), '%H:%M'),
|
||||||
|
('%r', '%02d:%02d:%02d %s' % (clock12, now[4], now[5], ampm),
|
||||||
|
'%I:%M:%S %p'),
|
||||||
|
('%S', '%02d' % now[5], 'seconds of current time (00-60)'),
|
||||||
|
('%T', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
|
||||||
|
('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'),
|
||||||
|
('%U', '%02d' % ((now[7] + jan1[6])/7),
|
||||||
|
'week number of the year (Sun 1st)'),
|
||||||
|
('%W', '%02d' % ((now[7] + (jan1[6] - 1)%7)/7),
|
||||||
|
'week number of the year (Mon 1st)'),
|
||||||
|
('%w', '%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'),
|
||||||
|
('%x', '%02d/%02d/%02d' % (now[1], now[2], (now[0]%100)),
|
||||||
|
'%m/%d/%y %H:%M:%S'),
|
||||||
|
('%Y', '%d' % now[0], 'year with century'),
|
||||||
|
('%y', '%02d' % (now[0]%100), 'year without century'),
|
||||||
|
('%Z', tz, 'time zone name'),
|
||||||
|
('%%', '%', 'single percent sign'),
|
||||||
|
)
|
||||||
|
|
||||||
|
nonstandard_expectations = (
|
||||||
|
('%C', '%02d' % (now[0]/100), 'century'),
|
||||||
|
# This is for IRIX; on Solaris, %C yields date(1) format.
|
||||||
|
# Tough.
|
||||||
|
('%k', '%2d' % now[3], 'hour, blank padded ( 0-23)'),
|
||||||
|
('%s', '%d' % nowsecs, 'seconds since the Epoch in UCT'),
|
||||||
|
('%3y', '%03d' % (now[0]%100),
|
||||||
|
'year without century rendered using fieldwidth'),
|
||||||
|
('%n', '\n', 'newline character'),
|
||||||
|
('%t', '\t', 'tab character'),
|
||||||
|
)
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print "Strftime test, platform: %s, Python version: %s" % \
|
||||||
|
(sys.platform, string.split(sys.version)[0])
|
||||||
|
|
||||||
|
for e in expectations:
|
||||||
try:
|
try:
|
||||||
value = apply(f, (input,) + args)
|
result = time.strftime(e[0], now)
|
||||||
except:
|
except ValueError, error:
|
||||||
value = sys.exc_type
|
print "Standard '%s' format gave error:" % e[0], error
|
||||||
if value != output:
|
continue
|
||||||
|
if result == e[1]: continue
|
||||||
|
if 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:
|
if verbose:
|
||||||
print 'no'
|
print "Error for nonstandard '%s' format (%s): %s" % \
|
||||||
print f, `input`, `output`, `value`
|
(e[0], e[2], str(error))
|
||||||
|
continue
|
||||||
|
if result == e[1]:
|
||||||
|
if verbose:
|
||||||
|
print "Supports nonstandard '%s' format (%s)" % (e[0], e[2])
|
||||||
|
elif result[0] == '%':
|
||||||
|
if verbose:
|
||||||
|
print "Does not appear to support '%s' format (%s)" % (e[0],
|
||||||
|
e[2])
|
||||||
else:
|
else:
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'yes'
|
print "Conflict for nonstandard '%s' format (%s):" % (e[0],
|
||||||
|
e[2])
|
||||||
|
print " Expected %s, but got %s" % (e[1], result)
|
||||||
|
|
||||||
test('atoi', " 1 ", 1)
|
def fixasctime(s):
|
||||||
test('atoi', " 1x", ValueError)
|
if s[8] == ' ':
|
||||||
test('atoi', " x1 ", ValueError)
|
s = s[:8] + '0' + s[9:]
|
||||||
test('atol', " 1 ", 1L)
|
return s
|
||||||
test('atol', " 1x ", ValueError)
|
|
||||||
test('atol', " x1 ", ValueError)
|
|
||||||
test('atof', " 1 ", 1.0)
|
|
||||||
test('atof', " 1x ", ValueError)
|
|
||||||
test('atof', " x1 ", ValueError)
|
|
||||||
|
|
||||||
test('capitalize', ' hello ', ' hello ')
|
main()
|
||||||
test('capitalize', 'hello ', 'Hello ')
|
|
||||||
test('find', 'abcdefghiabc', 0, 'abc')
|
|
||||||
test('find', 'abcdefghiabc', 9, 'abc', 1)
|
|
||||||
test('find', 'abcdefghiabc', -1, 'def', 4)
|
|
||||||
test('rfind', 'abcdefghiabc', 9, 'abc')
|
|
||||||
test('lower', 'HeLLo', 'hello')
|
|
||||||
test('upper', 'HeLLo', 'HELLO')
|
|
||||||
|
|
||||||
transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
|
|
||||||
|
|
||||||
test('maketrans', 'abc', transtable, 'xyz')
|
|
||||||
test('maketrans', 'abc', ValueError, 'xyzq')
|
|
||||||
|
|
||||||
test('split', 'this is the split function',
|
|
||||||
['this', 'is', 'the', 'split', 'function'])
|
|
||||||
test('split', 'a|b|c|d', ['a', 'b', 'c', 'd'], '|')
|
|
||||||
test('split', 'a|b|c|d', ['a', 'b', 'c|d'], '|', 2)
|
|
||||||
|
|
||||||
# join now works with any sequence type
|
|
||||||
class Sequence:
|
|
||||||
def __init__(self): self.seq = 'wxyz'
|
|
||||||
def __len__(self): return len(self.seq)
|
|
||||||
def __getitem__(self, i): return self.seq[i]
|
|
||||||
|
|
||||||
test('join', ['a', 'b', 'c', 'd'], 'a b c d')
|
|
||||||
test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
|
|
||||||
test('join', Sequence(), 'w x y z')
|
|
||||||
|
|
||||||
# try a few long ones
|
|
||||||
print strop.join(['x' * 100] * 100, ':')
|
|
||||||
print strop.join(('x' * 100,) * 100, ':')
|
|
||||||
|
|
||||||
test('strip', ' hello ', 'hello')
|
|
||||||
test('lstrip', ' hello ', 'hello ')
|
|
||||||
test('rstrip', ' hello ', ' hello')
|
|
||||||
|
|
||||||
test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
|
|
||||||
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')
|
|
||||||
|
|
||||||
strop.whitespace
|
|
||||||
strop.lowercase
|
|
||||||
strop.uppercase
|
|
||||||
|
|
Loading…
Reference in New Issue