diff options
Diffstat (limited to 'Lib/dos-8x3')
-rwxr-xr-x | Lib/dos-8x3/cgihttps.py | 5 | ||||
-rwxr-xr-x | Lib/dos-8x3/formatte.py | 4 | ||||
-rwxr-xr-x | Lib/dos-8x3/posixpat.py | 19 | ||||
-rwxr-xr-x | Lib/dos-8x3/py_compi.py | 2 | ||||
-rw-r--r-- | Lib/dos-8x3/test_arr.py | 38 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_aud.py | 355 | ||||
-rw-r--r-- | Lib/dos-8x3/test_bin.py | 46 | ||||
-rw-r--r-- | Lib/dos-8x3/test_bsd.py | 69 | ||||
-rw-r--r-- | Lib/dos-8x3/test_cma.py | 47 | ||||
-rw-r--r-- | Lib/dos-8x3/test_cry.py | 7 | ||||
-rw-r--r-- | Lib/dos-8x3/test_err.py | 44 | ||||
-rw-r--r-- | Lib/dos-8x3/test_fcn.py | 28 | ||||
-rw-r--r-- | Lib/dos-8x3/test_gdb.py | 34 | ||||
-rw-r--r-- | Lib/dos-8x3/test_ima.py | 165 | ||||
-rw-r--r-- | Lib/dos-8x3/test_img.py | 110 | ||||
-rw-r--r-- | Lib/dos-8x3/test_reg.py | 62 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_rgb.py | 3 | ||||
-rw-r--r-- | Lib/dos-8x3/test_rot.py | 28 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_sel.py | 40 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_sig.py | 33 | ||||
-rw-r--r-- | Lib/dos-8x3/test_soc.py | 142 | ||||
-rw-r--r-- | Lib/dos-8x3/test_str.py | 21 | ||||
-rw-r--r-- | Lib/dos-8x3/test_sun.py | 28 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_sup.py | 2 | ||||
-rwxr-xr-x | Lib/dos-8x3/test_thr.py | 19 | ||||
-rw-r--r-- | Lib/dos-8x3/test_tim.py | 4 |
26 files changed, 1138 insertions, 217 deletions
diff --git a/Lib/dos-8x3/cgihttps.py b/Lib/dos-8x3/cgihttps.py index 837f7c2..85e1721 100755 --- a/Lib/dos-8x3/cgihttps.py +++ b/Lib/dos-8x3/cgihttps.py @@ -191,11 +191,6 @@ def executable(path): def test(HandlerClass = CGIHTTPRequestHandler, ServerClass = BaseHTTPServer.HTTPServer): - import sys - if sys.argv[1:2] == ['-r']: - db = MyArchive() - db.regenindices() - return SimpleHTTPServer.test(HandlerClass, ServerClass) diff --git a/Lib/dos-8x3/formatte.py b/Lib/dos-8x3/formatte.py index 507ed8a..25dbe73 100755 --- a/Lib/dos-8x3/formatte.py +++ b/Lib/dos-8x3/formatte.py @@ -265,9 +265,9 @@ class AbstractFormatter: class NullWriter: - """Minimal writer interface to use in testing. - """ + """Minimal writer interface to use in testing & inheritance.""" def __init__(self): pass + def flush(self): pass def new_alignment(self, align): pass def new_font(self, font): pass def new_margin(self, margin, level): pass diff --git a/Lib/dos-8x3/posixpat.py b/Lib/dos-8x3/posixpat.py index 014dfe2..965184b 100755 --- a/Lib/dos-8x3/posixpat.py +++ b/Lib/dos-8x3/posixpat.py @@ -26,15 +26,20 @@ def isabs(s): return s[:1] == '/' -# Join two pathnames. -# Ignore the first part if the second part is absolute. +# Join pathnames. +# Ignore the previous parts if a part is absolute. # Insert a '/' unless the first part is empty or already ends in '/'. -def join(a, b): - if b[:1] == '/': return b - if a == '' or a[-1:] == '/': return a + b - # Note: join('x', '') returns 'x/'; is this what we want? - return a + '/' + b +def join(a, *p): + path = a + for b in p: + if b[:1] == '/': + path = b + elif path == '' or path[-1:] == '/': + path = path + b + else: + path = path + '/' + b + return path # Split a path in head (everything up to the last '/') and tail (the diff --git a/Lib/dos-8x3/py_compi.py b/Lib/dos-8x3/py_compi.py index fba7b1d..e9e90ff 100755 --- a/Lib/dos-8x3/py_compi.py +++ b/Lib/dos-8x3/py_compi.py @@ -19,7 +19,7 @@ def compile(file, cfile = None): timestamp = long(os.stat(file)[8]) codeobject = __builtin__.compile(codestring, file, 'exec') if not cfile: - cfile = file + 'c' + cfile = file + (__debug__ and 'c' or 'o') fc = open(cfile, 'wb') fc.write(MAGIC) wr_long(fc, timestamp) diff --git a/Lib/dos-8x3/test_arr.py b/Lib/dos-8x3/test_arr.py index 74fcd45..7474a27 100644 --- a/Lib/dos-8x3/test_arr.py +++ b/Lib/dos-8x3/test_arr.py @@ -1,16 +1,26 @@ #! /usr/bin/env python """Test the arraymodule. -Roger E. Masse + Roger E. Masse """ import array +from test_support import verbose + +def main(): + + testtype('c', 'c') + + for type in (['b', 'h', 'i', 'l', 'f', 'd']): + testtype(type, 1) + def testtype(type, example): a = array.array(type) a.append(example) - #print 40*'*' - #print 'array after append: ', a + if verbose: + print 40*'*' + print 'array after append: ', a a.typecode a.itemsize if a.typecode in ('i', 'b', 'h', 'l'): @@ -19,22 +29,24 @@ def testtype(type, example): if a.typecode == 'c': f = open('/etc/passwd', 'r') a.fromfile(f, 10) - #print 'char array with 10 bytes of /etc/passwd appended: ', a + if verbose: + print 'char array with 10 bytes of /etc/passwd appended: ', a a.fromlist(['a', 'b', 'c']) - #print 'char array with list appended: ', a + if verbose: + print 'char array with list appended: ', a a.insert(0, example) - #print 'array of %s after inserting another:' % a.typecode, a + if verbose: + print 'array of %s after inserting another:' % a.typecode, a f = open('/dev/null', 'w') a.tofile(f) a.tolist() a.tostring() - #print 'array of %s converted to a list: ' % a.typecode, a.tolist() - #print 'array of %s converted to a string: ' % a.typecode, a.tostring() - -testtype('c', 'c') - -for type in (['b', 'h', 'i', 'l', 'f', 'd']): - testtype(type, 1) + if verbose: + print 'array of %s converted to a list: ' % a.typecode, a.tolist() + if verbose: + print 'array of %s converted to a string: ' \ + % a.typecode, a.tostring() +main() diff --git a/Lib/dos-8x3/test_aud.py b/Lib/dos-8x3/test_aud.py index 3acf1bf..e966833 100755 --- a/Lib/dos-8x3/test_aud.py +++ b/Lib/dos-8x3/test_aud.py @@ -1,202 +1,263 @@ # Test audioop. import audioop +from test_support import verbose def gendata1(): - return '\0\1\2' + return '\0\1\2' def gendata2(): - if audioop.getsample('\0\1', 2, 0) == 1: - return '\0\0\0\1\0\2' - else: - return '\0\0\1\0\2\0' + if verbose: + print 'getsample' + if audioop.getsample('\0\1', 2, 0) == 1: + return '\0\0\0\1\0\2' + else: + return '\0\0\1\0\2\0' def gendata4(): - if audioop.getsample('\0\0\0\1', 4, 0) == 1: - return '\0\0\0\0\0\0\0\1\0\0\0\2' - else: - return '\0\0\0\0\1\0\0\0\2\0\0\0' + if verbose: + print 'getsample' + if audioop.getsample('\0\0\0\1', 4, 0) == 1: + return '\0\0\0\0\0\0\0\1\0\0\0\2' + else: + return '\0\0\0\0\1\0\0\0\2\0\0\0' def testmax(data): - if audioop.max(data[0], 1) <> 2 or \ - audioop.max(data[1], 2) <> 2 or \ - audioop.max(data[2], 4) <> 2: - return 0 - return 1 + if verbose: + print 'max' + if audioop.max(data[0], 1) <> 2 or \ + audioop.max(data[1], 2) <> 2 or \ + audioop.max(data[2], 4) <> 2: + return 0 + return 1 + +def testminmax(data): + if verbose: + print 'minmax' + if audioop.minmax(data[0], 1) <> (0, 2) or \ + audioop.minmax(data[1], 2) <> (0, 2) or \ + audioop.minmax(data[2], 4) <> (0, 2): + return 0 + return 1 def testmaxpp(data): - if audioop.maxpp(data[0], 1) <> 0 or \ - audioop.maxpp(data[1], 2) <> 0 or \ - audioop.maxpp(data[2], 4) <> 0: - return 0 - return 1 + if verbose: + print 'maxpp' + if audioop.maxpp(data[0], 1) <> 0 or \ + audioop.maxpp(data[1], 2) <> 0 or \ + audioop.maxpp(data[2], 4) <> 0: + return 0 + return 1 def testavg(data): - if audioop.avg(data[0], 1) <> 1 or \ - audioop.avg(data[1], 2) <> 1 or \ - audioop.avg(data[2], 4) <> 1: - return 0 - return 1 + if verbose: + print 'avg' + if audioop.avg(data[0], 1) <> 1 or \ + audioop.avg(data[1], 2) <> 1 or \ + audioop.avg(data[2], 4) <> 1: + return 0 + return 1 def testavgpp(data): - if audioop.avgpp(data[0], 1) <> 0 or \ - audioop.avgpp(data[1], 2) <> 0 or \ - audioop.avgpp(data[2], 4) <> 0: - return 0 - return 1 + if verbose: + print 'avgpp' + if audioop.avgpp(data[0], 1) <> 0 or \ + audioop.avgpp(data[1], 2) <> 0 or \ + audioop.avgpp(data[2], 4) <> 0: + return 0 + return 1 def testrms(data): - if audioop.rms(data[0], 1) <> 1 or \ - audioop.rms(data[1], 2) <> 1 or \ - audioop.rms(data[2], 4) <> 1: - return 0 - return 1 + if audioop.rms(data[0], 1) <> 1 or \ + audioop.rms(data[1], 2) <> 1 or \ + audioop.rms(data[2], 4) <> 1: + return 0 + return 1 def testcross(data): - if audioop.cross(data[0], 1) <> 0 or \ - audioop.cross(data[1], 2) <> 0 or \ - audioop.cross(data[2], 4) <> 0: - return 0 - return 1 + if verbose: + print 'cross' + if audioop.cross(data[0], 1) <> 0 or \ + audioop.cross(data[1], 2) <> 0 or \ + audioop.cross(data[2], 4) <> 0: + return 0 + return 1 def testadd(data): - data2 = [] - for d in data: - str = '' - for s in d: - str = str + chr(ord(s)*2) - data2.append(str) - if audioop.add(data[0], data[0], 1) <> data2[0] or \ - audioop.add(data[1], data[1], 2) <> data2[1] or \ - audioop.add(data[2], data[2], 4) <> data2[2]: - return 0 - return 1 + if verbose: + print 'add' + data2 = [] + for d in data: + str = '' + for s in d: + str = str + chr(ord(s)*2) + data2.append(str) + if audioop.add(data[0], data[0], 1) <> data2[0] or \ + audioop.add(data[1], data[1], 2) <> data2[1] or \ + audioop.add(data[2], data[2], 4) <> data2[2]: + return 0 + return 1 def testbias(data): - # Note: this test assumes that avg() works - d1 = audioop.bias(data[0], 1, 100) - d2 = audioop.bias(data[1], 2, 100) - d4 = audioop.bias(data[2], 4, 100) - if audioop.avg(d1, 1) <> 101 or \ - audioop.avg(d2, 2) <> 101 or \ - audioop.avg(d4, 4) <> 101: - return 0 - return 1 + if verbose: + print 'bias' + # Note: this test assumes that avg() works + d1 = audioop.bias(data[0], 1, 100) + d2 = audioop.bias(data[1], 2, 100) + d4 = audioop.bias(data[2], 4, 100) + if audioop.avg(d1, 1) <> 101 or \ + audioop.avg(d2, 2) <> 101 or \ + audioop.avg(d4, 4) <> 101: + return 0 + return 1 def testlin2lin(data): - # too simple: we test only the size - for d1 in data: - for d2 in data: - got = len(d1)/3 - wtd = len(d2)/3 - if len(audioop.lin2lin(d1, got, wtd)) <> len(d2): - return 0 - return 1 + if verbose: + print 'lin2lin' + # too simple: we test only the size + for d1 in data: + for d2 in data: + got = len(d1)/3 + wtd = len(d2)/3 + if len(audioop.lin2lin(d1, got, wtd)) <> len(d2): + return 0 + return 1 def testadpcm2lin(data): - # Very cursory test - if audioop.adpcm2lin('\0\0', 1, None) <> ('\0\0\0\0', (0,0)): - return 0 - return 1 + # Very cursory test + if audioop.adpcm2lin('\0\0', 1, None) <> ('\0\0\0\0', (0,0)): + return 0 + return 1 def testlin2adpcm(data): - # Very cursory test - if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)): - return 0 - return 1 + if verbose: + print 'lin2adpcm' + # Very cursory test + if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)): + return 0 + return 1 def testlin2ulaw(data): - if audioop.lin2ulaw(data[0], 1) <> '\377\347\333' or \ - audioop.lin2ulaw(data[1], 2) <> '\377\377\377' or \ - audioop.lin2ulaw(data[2], 4) <> '\377\377\377': - return 0 - return 1 + if verbose: + print 'lin2ulaw' + if audioop.lin2ulaw(data[0], 1) <> '\377\347\333' or \ + audioop.lin2ulaw(data[1], 2) <> '\377\377\377' or \ + audioop.lin2ulaw(data[2], 4) <> '\377\377\377': + return 0 + return 1 def testulaw2lin(data): - # Cursory - d = audioop.lin2ulaw(data[0], 1) - if audioop.ulaw2lin(d, 1) <> data[0]: - return 0 - return 1 + if verbose: + print 'ulaw2lin' + # Cursory + d = audioop.lin2ulaw(data[0], 1) + if audioop.ulaw2lin(d, 1) <> data[0]: + return 0 + return 1 def testmul(data): - data2 = [] - for d in data: - str = '' - for s in d: - str = str + chr(ord(s)*2) - data2.append(str) - if audioop.mul(data[0], 1, 2) <> data2[0] or \ - audioop.mul(data[1],2, 2) <> data2[1] or \ - audioop.mul(data[2], 4, 2) <> data2[2]: - return 0 - return 1 + if verbose: + print 'mul' + data2 = [] + for d in data: + str = '' + for s in d: + str = str + chr(ord(s)*2) + data2.append(str) + if audioop.mul(data[0], 1, 2) <> data2[0] or \ + audioop.mul(data[1],2, 2) <> data2[1] or \ + audioop.mul(data[2], 4, 2) <> data2[2]: + return 0 + return 1 + +def testratecv(data): + if verbose: + print 'ratecv' + state = (-8000, ((256, 512),)) + if audioop.ratecv(data[0], 1, 1, 8000, 16000, state) != \ + ('\001\000\000\001\001\002', state): + return 0 + return 1 def testreverse(data): - if audioop.reverse(data[0], 1) <> '\2\1\0': - return 0 - return 1 + if verbose: + print 'reverse' + if audioop.reverse(data[0], 1) <> '\2\1\0': + return 0 + return 1 def testtomono(data): - data2 = '' - for d in data[0]: - data2 = data2 + d + d - if audioop.tomono(data2, 1, 0.5, 0.5) <> data[0]: - return 0 - return 1 + if verbose: + print 'tomono' + data2 = '' + for d in data[0]: + data2 = data2 + d + d + if audioop.tomono(data2, 1, 0.5, 0.5) <> data[0]: + return 0 + return 1 def testtostereo(data): - data2 = '' - for d in data[0]: - data2 = data2 + d + d - if audioop.tostereo(data[0], 1, 1, 1) <> data2: - return 0 - return 1 + if verbose: + print 'tostereo' + data2 = '' + for d in data[0]: + data2 = data2 + d + d + if audioop.tostereo(data[0], 1, 1, 1) <> data2: + return 0 + return 1 def testfindfactor(data): - if audioop.findfactor(data[1], data[1]) <> 1.0: - return 0 - return 1 + if verbose: + print 'findfactor' + if audioop.findfactor(data[1], data[1]) <> 1.0: + return 0 + return 1 def testfindfit(data): - if audioop.findfit(data[1], data[1]) <> (0, 1.0): - return 0 - return 1 + if verbose: + print 'findfit' + if audioop.findfit(data[1], data[1]) <> (0, 1.0): + return 0 + return 1 def testfindmax(data): - if audioop.findmax(data[1], 1) <> 2: - return 0 - return 1 + if verbose: + print 'findmax' + if audioop.findmax(data[1], 1) <> 2: + return 0 + return 1 def testgetsample(data): - for i in range(3): - if audioop.getsample(data[0], 1, i) <> i or \ - audioop.getsample(data[1], 2, i) <> i or \ - audioop.getsample(data[2], 4, i) <> i: - return 0 - return 1 + if verbose: + print 'getsample' + for i in range(3): + if audioop.getsample(data[0], 1, i) <> i or \ + audioop.getsample(data[1], 2, i) <> i or \ + audioop.getsample(data[2], 4, i) <> i: + return 0 + return 1 def testone(name, data): - try: - func = eval('test'+name) - except NameError: - print 'No test found for audioop.'+name+'()' - return - try: - rv = func(data) - except 'xx': - print 'Test FAILED for audioop.'+name+'() (with an exception)' - return - if not rv: - print 'Test FAILED for audioop.'+name+'()' + try: + func = eval('test'+name) + except NameError: + print 'No test found for audioop.'+name+'()' + return + try: + rv = func(data) + except 'xx': + print 'Test FAILED for audioop.'+name+'() (with an exception)' + return + if not rv: + print 'Test FAILED for audioop.'+name+'()' def testall(): - data = [gendata1(), gendata2(), gendata4()] - names = dir(audioop) - # We know there is a routine 'add' - routines = [] - for n in names: - if type(eval('audioop.'+n)) == type(audioop.add): - routines.append(n) - for n in routines: - testone(n, data) + data = [gendata1(), gendata2(), gendata4()] + names = dir(audioop) + # We know there is a routine 'add' + routines = [] + for n in names: + if type(eval('audioop.'+n)) == type(audioop.add): + routines.append(n) + for n in routines: + testone(n, data) testall() diff --git a/Lib/dos-8x3/test_bin.py b/Lib/dos-8x3/test_bin.py new file mode 100644 index 0000000..aa156d9 --- /dev/null +++ b/Lib/dos-8x3/test_bin.py @@ -0,0 +1,46 @@ +#! /usr/bin/env python +"""Test script for the binascii C module + + Uses the mechanism of the python binhex module + Roger E. Masse +""" +import binhex +import tempfile +from test_support import verbose + +def test(): + + try: + fname1 = tempfile.mktemp() + fname2 = tempfile.mktemp() + f = open(fname1, 'w') + except: + raise ImportError, "Cannot test binascii without a temp file" + + start = 'Jack is my hero' + f.write(start) + f.close() + + binhex.binhex(fname1, fname2) + if verbose: + print 'binhex' + + binhex.hexbin(fname2, fname1) + if verbose: + print 'hexbin' + + f = open(fname1, 'r') + finish = f.readline() + + if start <> finish: + print 'Error: binhex <> hexbin' + elif verbose: + print 'binhex == hexbin' + + try: + import os + os.unlink(fname1) + os.unlink(fname2) + except: + pass +test() diff --git a/Lib/dos-8x3/test_bsd.py b/Lib/dos-8x3/test_bsd.py new file mode 100644 index 0000000..7a95eb9 --- /dev/null +++ b/Lib/dos-8x3/test_bsd.py @@ -0,0 +1,69 @@ +#! /usr/bin/env python +"""Test script for the bsddb C module + Roger E. Masse +""" +import bsddb +import tempfile +from test_support import verbose + +def test(openmethod, what): + + if verbose: + print '\nTesting: ', what + + fname = tempfile.mktemp() + f = openmethod(fname, 'c') + if verbose: + print 'creation...' + f['0'] = '' + f['a'] = 'Guido' + f['b'] = 'van' + f['c'] = 'Rossum' + f['d'] = 'invented' + f['f'] = 'Python' + if verbose: + print '%s %s %s' % (f['a'], f['b'], f['c']) + + if what == 'BTree' : + if verbose: + print 'key ordering...' + f.set_location(f.first()[0]) + while 1: + try: + rec = f.next() + except KeyError: + if rec <> f.last(): + print 'Error, last <> last!' + f.previous() + break + if verbose: + print rec + if not f.has_key('a'): + print 'Error, missing key!' + + f.sync() + f.close() + if verbose: + print 'modification...' + f = openmethod(fname, 'w') + f['d'] = 'discovered' + + if verbose: + print 'access...' + for key in f.keys(): + word = f[key] + if verbose: + print word + + f.close() + +types = [(bsddb.btopen, 'BTree'), + (bsddb.hashopen, 'Hash Table'), + # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 + # appears broken... at least on + # Solaris Intel - rmasse 1/97 + ] + +for type in types: + test(type[0], type[1]) + diff --git a/Lib/dos-8x3/test_cma.py b/Lib/dos-8x3/test_cma.py index 8c452d7..71e7729 100644 --- a/Lib/dos-8x3/test_cma.py +++ b/Lib/dos-8x3/test_cma.py @@ -1,22 +1,35 @@ #! /usr/bin/env python """ Simple test script for cmathmodule.c -Roger E. Masse + Roger E. Masse """ import cmath +from test_support import verbose -cmath.acos(1.0) -cmath.acosh(1.0) -cmath.asin(1.0) -cmath.asinh(1.0) -cmath.atan(0.2) -cmath.atanh(0.3) -cmath.cos(1.0) -cmath.cosh(1.0) -cmath.exp(1.0) -cmath.log(1.0) -cmath.log10(1.0) -cmath.sin(1.0) -cmath.sinh(1.0) -cmath.sqrt(1.0) -cmath.tan(1.0) -cmath.tanh(1.0) +testdict = {'acos' : 1.0, + 'acosh' : 1.0, + 'asin' : 1.0, + 'asinh' : 1.0, + 'atan' : 0.2, + 'atanh' : 0.2, + 'cos' : 1.0, + 'cosh' : 1.0, + 'exp' : 1.0, + 'log' : 1.0, + 'log10' : 1.0, + 'sin' : 1.0, + 'sinh' : 1.0, + 'sqrt' : 1.0, + 'tan' : 1.0, + 'tanh' : 1.0} + +for func in testdict.keys(): + f = getattr(cmath, func) + r = f(testdict[func]) + if verbose: + print 'Calling %s(%f) = %f' % (func, testdict[func], abs(r)) + +p = cmath.pi +e = cmath.e +if verbose: + print 'PI = ', abs(p) + print 'E = ', abs(e) diff --git a/Lib/dos-8x3/test_cry.py b/Lib/dos-8x3/test_cry.py index 08e6b61..0685c95 100644 --- a/Lib/dos-8x3/test_cry.py +++ b/Lib/dos-8x3/test_cry.py @@ -2,5 +2,10 @@ """Simple test script for cryptmodule.c Roger E. Masse """ + +from test_support import verbose import crypt -print 'Test encryption: ', crypt.crypt('mypassword', 'ab') + +c = crypt.crypt('mypassword', 'ab') +if verbose: + print 'Test encryption: ', c diff --git a/Lib/dos-8x3/test_err.py b/Lib/dos-8x3/test_err.py new file mode 100644 index 0000000..6951255 --- /dev/null +++ b/Lib/dos-8x3/test_err.py @@ -0,0 +1,44 @@ +#! /usr/bin/env python +"""Test the errno module + Roger E. Masse +""" + +import errno +from test_support import verbose + +errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', + 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF', + 'EBADFD', 'EBADMSG', 'EBADR', 'EBADRQC', 'EBADSLT', + 'EBFONT', 'EBUSY', 'ECHILD', 'ECHRNG', 'ECOMM', + 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', + 'EDEADLK', 'EDEADLOCK', 'EDESTADDRREQ', 'EDOM', + 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTDOWN', + 'EHOSTUNREACH', 'EIDRM', 'EILSEQ', 'EINPROGRESS', + 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', + 'EL2HLT', 'EL2NSYNC', 'EL3HLT', 'EL3RST', 'ELIBACC', + 'ELIBBAD', 'ELIBEXEC', 'ELIBMAX', 'ELIBSCN', 'ELNRNG', + 'ELOOP', 'EMFILE', 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', + 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', + 'ENFILE', 'ENOANO', 'ENOBUFS', 'ENOCSI', 'ENODATA', + 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', + 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT', + 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK', + 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTSOCK', + 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP', + 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE', + 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', + 'ERANGE', 'EREMCHG', 'EREMOTE', 'ERESTART', + 'EROFS', 'ESHUTDOWN', 'ESOCKTNOSUPPORT', 'ESPIPE', + 'ESRCH', 'ESRMNT', 'ESTALE', 'ESTRPIPE', 'ETIME', + 'ETIMEDOUT', 'ETOOMANYREFS', 'ETXTBSY', 'EUNATCH', + 'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL'] + +# +# This is is a wee bit bogus since the module only conditionally adds +# errno constants if they have been defined by errno.h However, this +# test seems to work on SGI, Sparc & intel Solaris, and linux. +# +for error in errors: + a = getattr(errno, error) + if verbose: + print '%s: %d' % (error, a) diff --git a/Lib/dos-8x3/test_fcn.py b/Lib/dos-8x3/test_fcn.py new file mode 100644 index 0000000..4929fbb --- /dev/null +++ b/Lib/dos-8x3/test_fcn.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python +"""Test program for the fcntl C module. + Roger E. Masse +""" +import struct +import fcntl +import FCNTL +import os +from test_support import verbose + +filename = '/tmp/delete-me' + +# the example from the library docs +f = open(filename,'w') +rv = fcntl.fcntl(f.fileno(), FCNTL.O_NDELAY, 1) +if verbose: + print 'Status from fnctl with O_NDELAY: ', rv + +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 + +f.close() +os.unlink(filename) diff --git a/Lib/dos-8x3/test_gdb.py b/Lib/dos-8x3/test_gdb.py new file mode 100644 index 0000000..22db6aa --- /dev/null +++ b/Lib/dos-8x3/test_gdb.py @@ -0,0 +1,34 @@ +#! /usr/bin/env python +"""Test script for the gdbm module + Roger E. Masse +""" + +import gdbm +from gdbm import error +from test_support import verbose + +filename= '/tmp/delete_me' + +g = gdbm.open(filename, 'c') +g['a'] = 'b' +g['12345678910'] = '019237410982340912840198242' +a = g.keys() +if verbose: + print 'Test gdbm file keys: ', a + +g.has_key('a') +g.close() +g = gdbm.open(filename, 'r') +g.close() +g = gdbm.open(filename, 'rw') +g.close() +g = gdbm.open(filename, 'w') +g.close() +g = gdbm.open(filename, 'n') +g.close() + +try: + import os + os.unlink(filename) +except: + pass diff --git a/Lib/dos-8x3/test_ima.py b/Lib/dos-8x3/test_ima.py new file mode 100644 index 0000000..fc8dadf --- /dev/null +++ b/Lib/dos-8x3/test_ima.py @@ -0,0 +1,165 @@ +#! /usr/bin/env python +"""Test script for the imageop module. This has the side + effect of partially testing the imgfile module as well. + Roger E. Masse +""" +from test_support import verbose + +import imageop + +def main(use_rgbimg=1): + + if use_rgbimg: + 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: + print 'crop' + newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 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. + if verbose: + print 'scale' + scaleimage = imageop.scale(image, 4, width, height, 1, 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 verbose: + print 'tovideo' + videoimage = imageop.tovideo (image, 4, width, height) + + # Convert an rgb image to an 8 bit rgb + if verbose: + print 'rgb2rgb8' + greyimage = imageop.rgb2rgb8(image, width, height) + + # Convert an 8 bit rgb image to a 24 bit rgb image + if verbose: + print 'rgb82rgb' + image = imageop.rgb82rgb(greyimage, width, height) + + # Convert an rgb image to an 8 bit greyscale image + if verbose: + print 'rgb2grey' + greyimage = imageop.rgb2grey(image, width, height) + + # Convert an 8 bit greyscale image to a 24 bit rgb image + if verbose: + print 'grey2rgb' + image = imageop.grey2rgb(greyimage, width, height) + + # Convert a 8-bit deep greyscale image to a 1-bit deep image by + # tresholding all the pixels. The resulting image is tightly packed + # and is probably only useful as an argument to mono2grey. + if verbose: + print 'grey2mono' + 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. + # All pixels that are zero-valued on input get value p0 on output and + # all one-value input pixels get value p1 on output. To convert a + # monochrome black-and-white image to greyscale pass the values 0 and + # 255 respectively. + if verbose: + print 'mono2grey' + greyimage = imageop.mono2grey (monoimage, width, height, 0, 255) + + # Convert an 8-bit greyscale image to a 1-bit monochrome image using a + # (simple-minded) dithering algorithm. + if verbose: + print 'dither2mono' + monoimage = imageop.dither2mono (greyimage, width, height) + + # Convert an 8-bit greyscale image to a 4-bit greyscale image without + # dithering. + if verbose: + print 'grey2grey4' + grey4image = imageop.grey2grey4 (greyimage, width, height) + + # Convert an 8-bit greyscale image to a 2-bit greyscale image without + # dithering. + if verbose: + print 'grey2grey2' + 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. + if verbose: + print 'dither2grey2' + grey2image = imageop.dither2grey2 (greyimage, width, height) + + # Convert a 4-bit greyscale image to an 8-bit greyscale image. + if verbose: + print 'grey42grey' + greyimage = imageop.grey42grey (grey4image, width, height) + + # Convert a 2-bit greyscale image to an 8-bit greyscale image. + if verbose: + print 'grey22grey' + image = imageop.grey22grey (grey2image, width, height) + +def getrgbimage(name): + """return a tuple consisting of image (in 'imgfile' format but + using rgbimg instead) width and height""" + + import rgbimg + + try: + sizes = rgbimg.sizeofimage(name) + except rgbimg.error: + name = get_qualified_path(name) + sizes = rgbimg.sizeofimage(name) + if verbose: + print 'rgbimg opening test image: %s, sizes: %s' % (name, str(sizes)) + + 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: + name = get_qualified_path(name) + sizes = imgfile.getsizes(name) + if verbose: + print 'imgfile opening test image: %s, sizes: %s' % (name, str(sizes)) + + image = imgfile.read(name) + return (image, sizes[0], sizes[1]) + +def get_qualified_path(name): + """ return a more qualified path to name contructed from argv[1]""" + import sys + import os + import string + + # get a more qualified path component of the script... + if __name__ == '__main__': + ourname = sys.argv[0] + else: # ...or the full path of the module + ourname = sys.modules[__name__].__file__ + + parts = string.splitfields(ourname, os.sep) + parts[-1] = name + name = string.joinfields(parts, os.sep) + return name + +# rgbimg (unlike imgfile) is portable to platforms other than SGI. So we prefer to use it. +main(use_rgbimg=1) + diff --git a/Lib/dos-8x3/test_img.py b/Lib/dos-8x3/test_img.py new file mode 100644 index 0000000..8a3b91e --- /dev/null +++ b/Lib/dos-8x3/test_img.py @@ -0,0 +1,110 @@ +#! /usr/bin/env python +"""Simple test script for imgfile.c + Roger E. Masse +""" +from test_support import verbose + +import imgfile + + +def main(): + + # Test a 3 byte color image + testimage('test.rgb') + + # Test a 1 byte greyscale image + testimage('greytest.rgb') + + +def testimage(name): + """Run through the imgfile's battery of possible methods + on the image passed in name. + """ + + import sys + import os + import string + + outputfile = '/tmp/deleteme' + + # try opening the name directly + try: + # This function returns a tuple (x, y, z) where x and y are the size + # of the image in pixels and z is the number of bytes per pixel. Only + # 3 byte RGB pixels and 1 byte greyscale pixels are supported. + sizes = imgfile.getsizes(name) + except imgfile.error: + # get a more qualified path component of the script... + if __name__ == '__main__': + ourname = sys.argv[0] + else: # ...or the full path of the module + ourname = sys.modules[__name__].__file__ + + parts = string.splitfields(ourname, os.sep) + parts[-1] = name + name = string.joinfields(parts, os.sep) + sizes = imgfile.getsizes(name) + if verbose: + print 'Opening test image: %s, sizes: %s' % (name, str(sizes)) + # This function reads and decodes the image on the specified file, + # 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. + 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. + if verbose: + print 'Writing output file' + imgfile.write (outputfile, image, sizes[0], sizes[1], sizes[2]) + + + if verbose: + print 'Opening scaled test image: %s, sizes: %s' % (name, str(sizes)) + # This function is identical to read but it returns an image that + # is scaled to the given x and y sizes. If the filter and blur + # parameters are omitted scaling is done by simply dropping + # or duplicating pixels, so the result will be less than perfect, + # especially for computer-generated images. Alternatively, + # you can specify a filter to use to smoothen the image after + # scaling. The filter forms supported are 'impulse', 'box', + # 'triangle', 'quadratic' and 'gaussian'. If a filter is + # specified blur is an optional parameter specifying the + # blurriness of the filter. It defaults to 1.0. readscaled + # makes no attempt to keep the aspect ratio correct, so that + # is the users' responsibility. + if verbose: + print 'Filtering with "impulse"' + simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'impulse', 2.0) + + # 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. + if verbose: + print 'Switching to X compatibility' + 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) + + if verbose: print 'Filtering with "quadratic"' + simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'quadratic') + if verbose: print 'Filtering with "gaussian"' + simage = imgfile.readscaled (name, sizes[0]/2, sizes[1]/2, 'gaussian', 1.0) + + if verbose: + print 'Writing output file' + imgfile.write (outputfile, simage, sizes[0]/2, sizes[1]/2, sizes[2]) + + os.unlink(outputfile) + +main() diff --git a/Lib/dos-8x3/test_reg.py b/Lib/dos-8x3/test_reg.py new file mode 100644 index 0000000..9d25d92 --- /dev/null +++ b/Lib/dos-8x3/test_reg.py @@ -0,0 +1,62 @@ +from test_support import verbose +import regex +from regex_syntax import * + +re = 'a+b+c+' +print 'no match:', regex.match(re, 'hello aaaabcccc world') +print 'successful search:', regex.search(re, 'hello aaaabcccc world') +try: + cre = regex.compile('\(' + re) +except regex.error: + print 'caught expected exception' +else: + print 'expected regex.error not raised' + +print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb') +prev = regex.set_syntax(RE_SYNTAX_AWK) +print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb') +regex.set_syntax(prev) +print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb') + +re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)' +print 'matching with group names and compile()' +cre = regex.compile(re) +print cre.match('801 999') +try: + print cre.group('one') +except regex.error: + print 'caught expected exception' +else: + print 'expected regex.error not raised' + +print 'matching with group names and symcomp()' +cre = regex.symcomp(re) +print cre.match('801 999') +print cre.group(0) +print cre.group('one') +print cre.group(1, 2) +print cre.group('one', 'two') +print 'realpat:', cre.realpat +print 'groupindex:', cre.groupindex + +re = 'world' +cre = regex.compile(re) +print 'not case folded search:', cre.search('HELLO WORLD') +cre = regex.compile(re, regex.casefold) +print 'case folded search:', cre.search('HELLO WORLD') + +print '__members__:', cre.__members__ +print 'regs:', cre.regs +print 'last:', cre.last +print 'translate:', `cre.translate` +print 'givenpat:', cre.givenpat + +print 'match with pos:', cre.match('hello world', 7) +print 'search with pos:', cre.search('hello world there world', 7) +print 'bogus group:', cre.group(0, 1, 3) +try: + print 'no name:', cre.group('one') +except regex.error: + print 'caught expected exception' +else: + print 'expected regex.error not raised' diff --git a/Lib/dos-8x3/test_rgb.py b/Lib/dos-8x3/test_rgb.py index cdadc66..52814b4 100755 --- a/Lib/dos-8x3/test_rgb.py +++ b/Lib/dos-8x3/test_rgb.py @@ -23,7 +23,8 @@ def testimg(rgb_file, raw_file): raise error, 'bad image length' raw = open(raw_file, 'r').read() if rgb != raw: - raise error, 'images don\'t match for '+rgb_file+' and '+raw_file + 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') diff --git a/Lib/dos-8x3/test_rot.py b/Lib/dos-8x3/test_rot.py new file mode 100644 index 0000000..338ea9d --- /dev/null +++ b/Lib/dos-8x3/test_rot.py @@ -0,0 +1,28 @@ +import rotor + +r = rotor.newrotor("you'll never guess this") +r = rotor.newrotor("you'll never guess this", 12) + +A = 'spam and eggs' +B = 'cheese shop' + +a = r.encrypt(A) +print a +b = r.encryptmore(B) +print b + +A1 = r.decrypt(a) +print A1 +if A1 <> A: + print 'decrypt failed' + +B1 = r.decryptmore(b) +print B1 +if B1 <> B: + print 'decryptmore failed' + +try: + r.setkey() +except TypeError: + pass +r.setkey('you guessed it!') diff --git a/Lib/dos-8x3/test_sel.py b/Lib/dos-8x3/test_sel.py index f185308..f7f20f3 100755 --- a/Lib/dos-8x3/test_sel.py +++ b/Lib/dos-8x3/test_sel.py @@ -1,14 +1,44 @@ # Testing select module +import select +import os + +# test some known error conditions +try: + rfd, wfd, xfd = select.select(1, 2, 3) +except TypeError: + pass +else: + print 'expected TypeError exception not raised' + +class Nope: + pass + +class Almost: + def fileno(self): + return 'fileno' + +try: + rfd, wfd, xfd = select.select([Nope()], [], []) +except TypeError: + pass +else: + print 'expected TypeError exception not raised' + +try: + rfd, wfd, xfd = select.select([Almost()], [], []) +except TypeError: + pass +else: + print 'expected TypeError exception not raised' + def test(): - import select - import os - cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do date; sleep 3; 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') for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: print 'timeout =', tout rfd, wfd, xfd = select.select([p], [], [], tout) - print rfd, wfd, xfd +## print rfd, wfd, xfd if (rfd, wfd, xfd) == ([], [], []): continue if (rfd, wfd, xfd) == ([p], [], []): @@ -19,5 +49,7 @@ def test(): break continue print 'Heh?' + p.close() test() + diff --git a/Lib/dos-8x3/test_sig.py b/Lib/dos-8x3/test_sig.py index bfcf517..3619b96 100755 --- a/Lib/dos-8x3/test_sig.py +++ b/Lib/dos-8x3/test_sig.py @@ -1,31 +1,37 @@ # Test the signal module - +from test_support import verbose import signal import os +if verbose: + x = '-x' +else: + x = '+x' pid = os.getpid() # Shell script that will send us asynchronous signals script = """ -( - set -x + ( + 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): - print "handlerA", args + if verbose: + print "handlerA", args HandlerBCalled = "HandlerBCalled" # Exception def handlerB(*args): - print "handlerB", args + if verbose: + print "handlerB", args raise HandlerBCalled, args signal.alarm(20) # Entire test lasts at most 20 sec. @@ -40,11 +46,18 @@ print "starting pause() loop..." try: while 1: - print "call pause()..." + if verbose: + print "call pause()..." try: signal.pause() - print "pause() returned" + if verbose: + print "pause() returned" except HandlerBCalled: - print "HandlerBCalled exception caught" + if verbose: + print "HandlerBCalled exception caught" + else: + pass + except KeyboardInterrupt: - print "KeyboardInterrupt (assume the alarm() went off)" + if verbose: + print "KeyboardInterrupt (assume the alarm() went off)" diff --git a/Lib/dos-8x3/test_soc.py b/Lib/dos-8x3/test_soc.py new file mode 100644 index 0000000..1e157b9 --- /dev/null +++ b/Lib/dos-8x3/test_soc.py @@ -0,0 +1,142 @@ +# Not tested: +# socket.fromfd() +# sktobj.getsockopt() +# sktobj.recvfrom() +# sktobj.sendto() +# sktobj.setblocking() +# sktobj.setsockopt() +# sktobj.shutdown() + + +from test_support import verbose +import socket +import os +import time +import string + +def missing_ok(str): + try: + getattr(socket, str) + except AttributeError: + pass + +print socket.error + +print socket.AF_INET + +print socket.SOCK_STREAM +print socket.SOCK_DGRAM +print socket.SOCK_RAW +print socket.SOCK_RDM +print socket.SOCK_SEQPACKET + +for optional in ("AF_UNIX", + + "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE", + "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER", + "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF", + "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO", + "SO_ERROR", "SO_TYPE", "SOMAXCONN", + + "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR", + "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG", + "MSG_ETAG", + + "SOL_SOCKET", + + "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP", + "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP", + "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP", + "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP", + "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP", + "IPPROTO_RAW", "IPPROTO_MAX", + + "IPPORT_RESERVED", "IPPORT_USERRESERVED", + + "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK", + "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP", + "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE", + + "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL", + "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR", + "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL", + "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP", + "IP_DROP_MEMBERSHIP", + ): + missing_ok(optional) + +hostname = socket.gethostname() +ip = socket.gethostbyname(hostname) +hname, aliases, ipaddrs = socket.gethostbyaddr(ip) +all_host_names = [hname] + aliases + +if verbose: + print hostname + print ip + print hname, aliases, ipaddrs + print all_host_names + +for name in all_host_names: + if string.find(name, '.'): + break +else: + print 'FQDN not found' + +print socket.getservbyname('telnet', 'tcp') +try: + socket.getservbyname('telnet', 'udp') +except socket.error: + pass + + +try: + PORT = 50007 + if os.fork(): + # parent is server + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(hostname, PORT) + s.listen(1) + if verbose: + print 'parent accepting' + conn, addr = s.accept() + if verbose: + print 'connected by', addr + # couple of interesting tests while we've got a live socket + f = conn.fileno() + if verbose: + print 'fileno:', f + p = conn.getpeername() + if verbose: + print 'peer:', p + n = conn.getsockname() + if verbose: + print 'sockname:', n + f = conn.makefile() + if verbose: + print 'file obj:', f + while 1: + data = conn.recv(1024) + if not data: + break + if verbose: + print 'received:', data + conn.send(data) + conn.close() + else: + try: + # child is client + time.sleep(1) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if verbose: + print 'child connecting' + s.connect(hostname, PORT) + msg = 'socket test' + s.send(msg) + data = s.recv(1024) + if msg <> data: + print 'parent/client mismatch' + s.close() + finally: + os._exit(1) +except socket.error: + pass diff --git a/Lib/dos-8x3/test_str.py b/Lib/dos-8x3/test_str.py index 424cf52..efc98ff 100644 --- a/Lib/dos-8x3/test_str.py +++ b/Lib/dos-8x3/test_str.py @@ -1,13 +1,21 @@ +from test_support import verbose import strop, sys def test(name, input, output, *args): + if verbose: + print 'string.%s%s =? %s... ' % (name, (input,) + args, output), f = getattr(strop, name) try: value = apply(f, (input,) + args) except: value = sys.exc_type if value != output: + if verbose: + print 'no' print f, `input`, `output`, `value` + else: + if verbose: + print 'yes' test('atoi', " 1 ", 1) test('atoi', " 1x", ValueError) @@ -38,8 +46,19 @@ test('split', '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', ('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 ') diff --git a/Lib/dos-8x3/test_sun.py b/Lib/dos-8x3/test_sun.py new file mode 100644 index 0000000..aa85752 --- /dev/null +++ b/Lib/dos-8x3/test_sun.py @@ -0,0 +1,28 @@ +from test_support import verbose, TestFailed +import sunaudiodev +import os + +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 play_sound_file(path): + fp = open(path, 'r') + data = fp.read() + fp.close() + try: + a = sunaudiodev.open('w') + except sunaudiodev.error, msg: + raise TestFailed, msg + else: + a.write(data) + a.close() + +def test(): + play_sound_file(findfile('audiotest.au')) + +test() diff --git a/Lib/dos-8x3/test_sup.py b/Lib/dos-8x3/test_sup.py index 7a76664..7dc1940 100755 --- a/Lib/dos-8x3/test_sup.py +++ b/Lib/dos-8x3/test_sup.py @@ -2,6 +2,8 @@ TestFailed = 'test_support -- test failed' # Exception +verbose = 1 # Flag set to 0 by regrtest.py + def unload(name): import sys try: diff --git a/Lib/dos-8x3/test_thr.py b/Lib/dos-8x3/test_thr.py index 4e0eb70..8a1f435 100755 --- a/Lib/dos-8x3/test_thr.py +++ b/Lib/dos-8x3/test_thr.py @@ -2,6 +2,7 @@ # Create a bunch of threads, let each do some work, wait until all are done +from test_support import verbose import whrandom import thread import time @@ -19,9 +20,11 @@ def task(ident): whmutex.acquire() delay = whrandom.random() * numtasks whmutex.release() - print 'task', ident, 'will run for', delay, 'sec' + if verbose: + print 'task', ident, 'will run for', delay, 'sec' time.sleep(delay) - print 'task', ident, 'done' + if verbose: + print 'task', ident, 'done' mutex.acquire() running = running - 1 if running == 0: @@ -33,7 +36,8 @@ def newtask(): global next_ident, running mutex.acquire() next_ident = next_ident + 1 - print 'creating task', next_ident + if verbose: + print 'creating task', next_ident thread.start_new_thread(task, (next_ident,)) running = running + 1 mutex.release() @@ -84,11 +88,14 @@ def task2(ident): whmutex.acquire() delay = whrandom.random() * numtasks whmutex.release() - print 'task', ident, 'will run for', delay, 'sec' + if verbose: + print 'task', ident, 'will run for', delay, 'sec' time.sleep(delay) - print 'task', ident, 'entering barrier', i + if verbose: + print 'task', ident, 'entering barrier', i bar.enter() - print 'task', ident, 'leaving barrier', i + if verbose: + print 'task', ident, 'leaving barrier', i mutex.acquire() running = running - 1 if running == 0: diff --git a/Lib/dos-8x3/test_tim.py b/Lib/dos-8x3/test_tim.py index bfc768a..85ea6ee 100644 --- a/Lib/dos-8x3/test_tim.py +++ b/Lib/dos-8x3/test_tim.py @@ -13,8 +13,8 @@ if int(time.mktime(time.localtime(t))) <> int(t): time.sleep(1.2) tt = time.gmtime(t) -for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'E', 'H', 'I', - 'j', 'm', 'M', 'n', 'N', 'o', 'p', 'S', 't', +for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', + 'j', 'm', 'M', 'p', 'S', 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): format = '%' + directive time.strftime(format, tt) |