]> granicus.if.org Git - python/commitdiff
test_rotor.py: New test of the rotor module.
authorBarry Warsaw <barry@python.org>
Mon, 23 Dec 1996 23:39:42 +0000 (23:39 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 23 Dec 1996 23:39:42 +0000 (23:39 +0000)
test_*: converted to the new test harness.  GvR note!  test_signal.py
works interatively (i.e. when verbose=1) but does not work inside the
test harness.  It must be a timing issue, but I haven't figured it out
yet.

Lib/test/test_new.py
Lib/test/test_nis.py
Lib/test/test_operator.py
Lib/test/test_pwd.py
Lib/test/test_rotor.py [new file with mode: 0644]
Lib/test/test_signal.py
Lib/test/test_xdr.py
Lib/test/testall.py

index 89edafdd1903214fb57f618dc0863067c7406993..887702d1944f7ce58dd64c0d35382535e1d4a86f 100644 (file)
@@ -1,3 +1,4 @@
+from test_support import verbose
 import sys
 import new
 
@@ -5,7 +6,10 @@ class Eggs:
     def get_yolks(self):
        return self.yolks
 
+print 'new.module()'
 m = new.module('Spam')
+if verbose:
+    print m
 m.Eggs = Eggs
 sys.modules['Spam'] = m
 import Spam
@@ -13,12 +17,21 @@ import Spam
 def get_more_yolks(self):
     return self.yolks + 3
 
+print 'new.classobj()'
 C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
+if verbose:
+    print C
+print 'new.instance()'
 c = new.instance(C, {'yolks': 3})
+if verbose:
+    print c
 
 def break_yolks(self):
     self.yolks = self.yolks - 2
+print 'new.instancemethod()'
 im = new.instancemethod(break_yolks, c, C)
+if verbose:
+    print im
 
 if c.get_yolks() <> 3 and c.get_more_yolks() <> 6:
     print 'Broken call of hand-crafted class instance'
@@ -35,10 +48,16 @@ c = a + b
 ccode = compile(codestr, '<string>', 'exec')
 g = {'c': 0, '__builtins__': __builtins__}
 # this test could be more robust
+print 'new.function()'
 func = new.function(ccode, g)
+if verbose:
+    print func
 func()
 if g['c'] <> 3:
     print 'Could not create a proper function object'
 
 # bogus test of new.code()
-new.code(3, 3, 3, codestr, (), (), (), "<string>", "<name>")
+print 'new.code()'
+d = new.code(3, 3, 3, codestr, (), (), (), "<string>", "<name>")
+if verbose:
+    print d
index 4f78932306a8deef5eccac96b9302f5491f44264..9b3910d614f52520491c2f54f528e4a2ebacdb0a 100644 (file)
@@ -1,9 +1,7 @@
+from test_support import verbose
 import nis
 
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-
+print 'nis.maps()'
 maps = nis.maps()
 done = 0
 for nismap in maps:
index b2dad627e23655012a49cc2c4442d949f09ec095..ff4cba057649f020464476b66631c17afdb4b138 100644 (file)
@@ -2,6 +2,7 @@ import operator
 import sys
 
 def test(name, input, output, *args):
+    print 'testing:', name
     f = getattr(operator, name)
     params = (input,) + args
     try:
index b182d0239649d75f07c287909071a0fe3f443e26..1c2208d2e0345c9c0c453d0e04a919db2cbf2358 100644 (file)
@@ -1,10 +1,8 @@
+from test_support import verbose
 import pwd
 import string
 
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-
+print 'pwd.getpwall()'
 entries = pwd.getpwall()
 
 for e in entries:
@@ -12,12 +10,16 @@ for e in entries:
     uid = e[2]
     if verbose:
        print name, uid
+    print 'pwd.getpwuid()'
     dbuid = pwd.getpwuid(uid)
     if dbuid[0] <> name:
        print 'Mismatch in pwd.getpwuid()'
+    print 'pwd.getpwnam()'
     dbname = pwd.getpwnam(name)
     if dbname[2] <> uid:
        print 'Mismatch in pwd.getpwnam()'
+    else:
+       print 'name matches uid'
     break
 
 # try to get some errors
@@ -53,7 +55,7 @@ while bynames.has_key(fakename):
 try:
     pwd.getpwnam(fakename)
 except KeyError:
-    pass
+    print 'caught expected exception'
 else:
     print 'fakename', fakename, 'did not except pwd.getpwnam()'
 
@@ -65,6 +67,6 @@ fakeuid = uids[0] + 1
 try:
     pwd.getpwuid(fakeuid)
 except KeyError:
-    pass
+    print 'caught expected exception'
 else:
     print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()'
diff --git a/Lib/test/test_rotor.py b/Lib/test/test_rotor.py
new file mode 100644 (file)
index 0000000..475ac16
--- /dev/null
@@ -0,0 +1,25 @@
+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'
+
+r.setkey()
+r.setkey('you guessed it!')
index bfcf517ac9aa534f3836e99655d3af41adf08f7f..3619b96e5a2fc71ec3a88ead8bdfb45c0de22810 100644 (file)
@@ -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)"
index 5d9a139b04bbb3f801d44b397ec6de06f1fffc3e..0cc7a3aff73a8ea5e4a6265936dda20bcef6ec50 100644 (file)
@@ -1,22 +1,25 @@
+from test_support import verbose
 import _xdr
 
-verbose = 0
-if __name__ == '__main__':
-    verbose = 1
-
 fd = 8.01
+print '_xdr.pack_float()'
 s = _xdr.pack_float(fd)
+if verbose:
+    print `s`
+print '_xdr.unpack_float()'
 f = _xdr.unpack_float(s)
-
 if verbose:
     print f
 if int(100*f) <> int(100*fd):
     print 'pack_float() <> unpack_float()'
 
 fd = 9900000.9
+print '_xdr.pack_double()'
 s = _xdr.pack_double(fd)
+if verbose:
+    print `s`
+print '_xdr.unpack_double()'
 f = _xdr.unpack_double(s)
-
 if verbose:
     print f
 
index 5bb5f0c72c6ba7f6063a3aa34555f8bd16e8bc7c..e410e8f8bba772fa83e6ad4dcd48ab75fb414a1f 100644 (file)
@@ -33,6 +33,7 @@ tests = ['test_grammar',
         'test_imageop',
         'test_imgfile',
         'test_regex',
+        'test_rotor',
         ]
 
 if __name__ == '__main__':