diff options
Diffstat (limited to 'Lib/dos_8x3')
-rw-r--r-- | Lib/dos_8x3/test_arr.py | 17 | ||||
-rw-r--r-- | Lib/dos_8x3/test_err.py | 13 | ||||
-rwxr-xr-x | Lib/dos_8x3/test_gra.py | 4 | ||||
-rw-r--r-- | Lib/dos_8x3/test_ima.py | 18 | ||||
-rw-r--r-- | Lib/dos_8x3/test_img.py | 23 | ||||
-rwxr-xr-x | Lib/dos_8x3/test_ope.py | 78 | ||||
-rwxr-xr-x | Lib/dos_8x3/test_rgb.py | 24 | ||||
-rwxr-xr-x | Lib/dos_8x3/test_sel.py | 15 | ||||
-rwxr-xr-x | Lib/dos_8x3/test_sig.py | 4 | ||||
-rw-r--r-- | Lib/dos_8x3/test_str.py | 172 |
10 files changed, 282 insertions, 86 deletions
diff --git a/Lib/dos_8x3/test_arr.py b/Lib/dos_8x3/test_arr.py index 7474a27..832f192 100644 --- a/Lib/dos_8x3/test_arr.py +++ b/Lib/dos_8x3/test_arr.py @@ -3,7 +3,7 @@ Roger E. Masse """ import array -from test_support import verbose +from test_support import verbose, TESTFN, unlink def main(): @@ -12,10 +12,11 @@ def main(): for type in (['b', 'h', 'i', 'l', 'f', 'd']): testtype(type, 1) + unlink(TESTFN) + def testtype(type, example): - a = array.array(type) a.append(example) if verbose: @@ -27,10 +28,14 @@ def testtype(type, example): a.byteswap() 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) + f.close() 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']) if verbose: print 'char array with list appended: ', a @@ -38,8 +43,9 @@ def testtype(type, example): a.insert(0, example) if verbose: print 'array of %s after inserting another:' % a.typecode, a - f = open('/dev/null', 'w') + f = open(TESTFN, 'w') a.tofile(f) + f.close() a.tolist() a.tostring() if verbose: @@ -48,5 +54,6 @@ def testtype(type, example): print 'array of %s converted to a string: ' \ % a.typecode, a.tostring() + main() diff --git a/Lib/dos_8x3/test_err.py b/Lib/dos_8x3/test_err.py index 6951255..7228fdf 100644 --- a/Lib/dos_8x3/test_err.py +++ b/Lib/dos_8x3/test_err.py @@ -23,7 +23,7 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', 'ENOMEM', 'ENOMSG', 'ENONET', 'ENOPKG', 'ENOPROTOOPT', 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTBLK', - 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTSOCK', + 'ENOTCONN', 'ENOTDIR', 'ENOTEMPTY', 'ENOTOBACCO', 'ENOTSOCK', 'ENOTTY', 'ENOTUNIQ', 'ENXIO', 'EOPNOTSUPP', 'EOVERFLOW', 'EPERM', 'EPFNOSUPPORT', 'EPIPE', 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', @@ -39,6 +39,11 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV', # 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) + try: + a = getattr(errno, error) + except AttributeError: + if verbose: + print '%s: not found' % error + else: + if verbose: + print '%s: %d' % (error, a) diff --git a/Lib/dos_8x3/test_gra.py b/Lib/dos_8x3/test_gra.py index b9607ac..21012d2 100755 --- a/Lib/dos_8x3/test_gra.py +++ b/Lib/dos_8x3/test_gra.py @@ -83,8 +83,8 @@ x = 3.1e4 print '1.1.3 String literals' -def assert(s): - if not s: raise TestFailed, 'see traceback' +##def assert(s): +## if not s: raise TestFailed, 'see traceback' x = ''; y = ""; assert(len(x) == 0 and x == y) x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39) diff --git a/Lib/dos_8x3/test_ima.py b/Lib/dos_8x3/test_ima.py index fc8dadf..f9108ef 100644 --- a/Lib/dos_8x3/test_ima.py +++ b/Lib/dos_8x3/test_ima.py @@ -1,14 +1,19 @@ #! /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 +from test_support import verbose, unlink + +import imageop, uu def main(use_rgbimg=1): + # Create binary test files + uu.decode(get_qualified_path('testrgb.uue'), 'test.rgb') + if use_rgbimg: image, width, height = getrgbimage('test.rgb') else: @@ -106,7 +111,10 @@ def main(use_rgbimg=1): # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' - image = imageop.grey22grey (grey2image, width, height) + image = imageop.grey22grey (grey2image, width, height) + + # Cleanup + unlink('test.rgb') def getrgbimage(name): """return a tuple consisting of image (in 'imgfile' format but @@ -160,6 +168,6 @@ def get_qualified_path(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. +# 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 index 8a3b91e..576a51c 100644 --- a/Lib/dos_8x3/test_img.py +++ b/Lib/dos_8x3/test_img.py @@ -1,13 +1,18 @@ #! /usr/bin/env python + """Simple test script for imgfile.c 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 testimage('test.rgb') @@ -15,6 +20,16 @@ def main(): # Test a 1 byte greyscale image 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): """Run through the imgfile's battery of possible methods diff --git a/Lib/dos_8x3/test_ope.py b/Lib/dos_8x3/test_ope.py index 1a75065..ff4cba0 100755 --- a/Lib/dos_8x3/test_ope.py +++ b/Lib/dos_8x3/test_ope.py @@ -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`) -print '3. Operations' -print 'XXX Not yet implemented' +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) + + +# some negative tests +test('indexOf', [4, 3, 2, 1], ValueError, 9) diff --git a/Lib/dos_8x3/test_rgb.py b/Lib/dos_8x3/test_rgb.py index 52814b4..f0f772c 100755 --- a/Lib/dos_8x3/test_rgb.py +++ b/Lib/dos_8x3/test_rgb.py @@ -1,6 +1,8 @@ # Testing rgbimg module -import rgbimg, os +import rgbimg, os, uu + +from test_support import verbose, unlink error = 'test_rgbimg.error' @@ -21,7 +23,7 @@ def testimg(rgb_file, raw_file): rgb = rgbimg.longimagedata(rgb_file) if len(rgb) != width * height * 4: raise error, 'bad image length' - raw = open(raw_file, 'r').read() + raw = open(raw_file, 'rb').read() if rgb != raw: raise error, \ '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') 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) if ttob != 0: raise error, 'ttob should start out as zero' @@ -48,3 +65,6 @@ if ttob != 1: ttob = rgbimg.ttob(0) if ttob != 0: raise error, 'ttob should be zero' + +for source, target in table: + unlink(findfile(target)) diff --git a/Lib/dos_8x3/test_sel.py b/Lib/dos_8x3/test_sel.py index f7f20f3..32ccfd1 100755 --- a/Lib/dos_8x3/test_sel.py +++ b/Lib/dos_8x3/test_sel.py @@ -1,4 +1,5 @@ # Testing select module +from test_support import verbose import select import os @@ -33,19 +34,27 @@ else: 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' p = os.popen(cmd, 'r') for tout in (0, 1, 2, 4, 8, 16) + (None,)*10: - print 'timeout =', tout + if verbose: + print 'timeout =', tout rfd, wfd, xfd = select.select([p], [], [], tout) ## print rfd, wfd, xfd if (rfd, wfd, xfd) == ([], [], []): continue if (rfd, wfd, xfd) == ([p], [], []): line = p.readline() - print `line` + if verbose: + print `line` if not line: - print 'EOF' + if verbose: + print 'EOF' break continue print 'Heh?' diff --git a/Lib/dos_8x3/test_sig.py b/Lib/dos_8x3/test_sig.py index 3619b96..51b120b 100755 --- a/Lib/dos_8x3/test_sig.py +++ b/Lib/dos_8x3/test_sig.py @@ -2,6 +2,10 @@ from test_support import verbose import signal import os +import sys + +if sys.platform[:3] == 'win': + raise ImportError, "Can't test signal on Windows" if verbose: diff --git a/Lib/dos_8x3/test_str.py b/Lib/dos_8x3/test_str.py index efc98ff..f568970 100644 --- a/Lib/dos_8x3/test_str.py +++ b/Lib/dos_8x3/test_str.py @@ -1,72 +1,128 @@ +#! /usr/bin/env python + +# Sanity checker for time.strftime + +import time, calendar, sys, string, os from test_support import verbose -import strop, sys -def test(name, input, output, *args): +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 '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' + print "strftime test for", time.ctime(now) + nowsecs = int(now) + gmt = time.gmtime(now) + now = time.localtime(now) -test('atoi', " 1 ", 1) -test('atoi', " 1x", ValueError) -test('atoi', " x1 ", ValueError) -test('atol', " 1 ", 1L) -test('atol', " 1x ", ValueError) -test('atol', " x1 ", ValueError) -test('atof', " 1 ", 1.0) -test('atof', " 1x ", ValueError) -test('atof', " x1 ", ValueError) + if now[3] < 12: ampm='AM' + else: ampm='PM' -test('capitalize', ' hello ', ' hello ') -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') + jan1 = time.localtime(time.mktime((now[0], 1, 1) + (0,)*6)) -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' + if now[8]: tz = time.tzname[1] + else: tz = time.tzname[0] -test('maketrans', 'abc', transtable, 'xyz') -test('maketrans', 'abc', ValueError, 'xyzq') + if now[3] > 12: clock12 = now[3] - 12 + elif now[3] > 0: clock12 = now[3] + else: clock12 = 12 -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) + 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'), + ) -# 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] + 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'), + ) -test('join', ['a', 'b', 'c', 'd'], 'a b c d') -test('join', ('a', 'b', 'c', 'd'), 'abcd', '') -test('join', Sequence(), 'w x y z') + if verbose: + print "Strftime test, platform: %s, Python version: %s" % \ + (sys.platform, string.split(sys.version)[0]) -# try a few long ones -print strop.join(['x' * 100] * 100, ':') -print strop.join(('x' * 100,) * 100, ':') + 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 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) -test('strip', ' hello ', 'hello') -test('lstrip', ' hello ', 'hello ') -test('rstrip', ' hello ', ' hello') + 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(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: + if verbose: + print "Conflict for nonstandard '%s' format (%s):" % (e[0], + e[2]) + print " Expected %s, but got %s" % (e[1], result) -test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS') -test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def') +def fixasctime(s): + if s[8] == ' ': + s = s[:8] + '0' + s[9:] + return s -strop.whitespace -strop.lowercase -strop.uppercase +main() |