]> granicus.if.org Git - python/commitdiff
Many scripts, but small changes. Update the way the scripts obtain the
authorRoger E. Masse <rmasse@newcnri.cnri.reston.va.us>
Fri, 20 Dec 1996 22:36:52 +0000 (22:36 +0000)
committerRoger E. Masse <rmasse@newcnri.cnri.reston.va.us>
Fri, 20 Dec 1996 22:36:52 +0000 (22:36 +0000)
'verbose' flag ala GvR updated test harness architecture.

Old way:

verbose = 0
if __name__ == '__main__':
verbose = 1

New way:

from test_support import verbose

Some other small readablility and functionality updates.

Lib/test/test_array.py
Lib/test/test_cmath.py
Lib/test/test_crypt.py
Lib/test/test_dbm.py
Lib/test/test_dl.py
Lib/test/test_errno.py
Lib/test/test_fcntl.py
Lib/test/test_gdbm.py
Lib/test/test_grp.py

index 74fcd45a603769cd1b1bb92c0b6bbaae499f7f23..7474a27207a278a8ea54c0e4e836a16238660085 100755 (executable)
@@ -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()
        
index 8c452d734d0f3df42af65d24525efcaa26d55fd6..d7b1b886e138d01791783a2e6c61549e7ca6ef48 100755 (executable)
@@ -3,20 +3,33 @@
 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)
index 6fbb780c53104265b8700b73af1972fed6f521e0..0685c95eb1e61cd1be40081bf7a8640643aa7163 100755 (executable)
@@ -2,11 +2,10 @@
 """Simple test script for cryptmodule.c
    Roger E. Masse
 """
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-    
+
+from test_support import verbose    
 import crypt
+
 c = crypt.crypt('mypassword', 'ab')
 if verbose:
     print 'Test encryption: ', c
index be24c66fe4eb81550eb08aac7ee450f7d087919e..45f5f3764bd5d5bd3c78d3a25d1e4b58f265bcad 100755 (executable)
@@ -4,13 +4,18 @@
 """
 import dbm
 from dbm import error
+from test_support import verbose
+
 filename= '/tmp/delete_me'
 
 d = dbm.open(filename, 'c')
 d['a'] = 'b'
 d['12345678910'] = '019237410982340912840198242'
 d.keys()
-d.has_key('a')
+if d.has_key('a'):
+    if verbose:
+       print 'Test dbm keys: ', d.keys()
+       
 d.close()
 d = dbm.open(filename, 'r')
 d.close()
index 37ff9c64023d16e1a03f2cc4a30702043bb71a00..e85bae92610ffcf4f44611f6808293ae4905257f 100755 (executable)
@@ -2,11 +2,9 @@
 """Test dlmodule.c
    Roger E. Masse  revised strategy by Barry Warsaw
 """
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
 
 import dl
+from test_support import verbose
 
 sharedlibs = [
     # SunOS/Solaris
index a7c77fadac23a668e6c6d370e76c77cb0bf700d3..6951255becd2a2b22e729f438a3846f2ec3150c0 100755 (executable)
@@ -2,12 +2,9 @@
 """Test the errno module
    Roger E. Masse
 """
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-    
 
 import errno
+from test_support import verbose
 
 errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
          'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF',
@@ -37,7 +34,7 @@ errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
          'EUSERS', 'EWOULDBLOCK', 'EXDEV', 'EXFULL']
 
 #
-# This is is a wee bit bogus since the module pnly conditionally adds
+# 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.
 #
index 76391343f6ac47272e630600dbefe9eb2a62cdfc..4929fbb3fe17a82110813817c5348b3fa65c544c 100755 (executable)
@@ -6,10 +6,7 @@ import struct
 import fcntl
 import FCNTL
 import os
-
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
+from test_support import verbose
 
 filename = '/tmp/delete-me'
 
index d0d705ae6ebb7230ba80cde1f7f1869c23f6def2..22db6aaa9ef114bacae4816fefbb88416ef7cddd 100755 (executable)
@@ -2,12 +2,11 @@
 """Test script for the gdbm module
    Roger E. Masse
 """
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
     
 import gdbm
 from gdbm import error
+from test_support import verbose
+
 filename= '/tmp/delete_me'
 
 g = gdbm.open(filename, 'c')
index 122f2fd8f3e9c06f2008ace2ffb674e3e8fe25c6..458ed38d3cb03c65de1217670e4251576c57c88d 100755 (executable)
@@ -2,11 +2,9 @@
 """Test script for the grp module
    Roger E. Masse
 """
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-    
+  
 import grp
+from test_support import verbose
 
 groups = grp.getgrall()
 if verbose: