summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1996-12-23 23:39:42 +0000
committerBarry Warsaw <barry@python.org>1996-12-23 23:39:42 +0000
commit49d9fd605ea94f1adcb73e843c932a7747564f12 (patch)
tree8f27621af2775001a3d2f99bc4bfbf521c37a8d8 /Lib/test
parentbe6988f27909d9e03f66f1e80921e2aadf6f76b2 (diff)
downloadcpython-49d9fd605ea94f1adcb73e843c932a7747564f12.tar.gz
test_rotor.py: New test of the rotor module.
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_new.py21
-rw-r--r--Lib/test/test_nis.py6
-rw-r--r--Lib/test/test_operator.py1
-rw-r--r--Lib/test/test_pwd.py14
-rw-r--r--Lib/test/test_rotor.py25
-rw-r--r--Lib/test/test_signal.py33
-rw-r--r--Lib/test/test_xdr.py15
-rw-r--r--Lib/test/testall.py1
8 files changed, 89 insertions, 27 deletions
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py
index 89edafdd19..887702d194 100644
--- a/Lib/test/test_new.py
+++ b/Lib/test/test_new.py
@@ -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
diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py
index 4f78932306..9b3910d614 100644
--- a/Lib/test/test_nis.py
+++ b/Lib/test/test_nis.py
@@ -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:
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index b2dad627e2..ff4cba0576 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -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:
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index b182d02396..1c2208d2e0 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -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
index 0000000000..475ac16cd8
--- /dev/null
+++ b/Lib/test/test_rotor.py
@@ -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!')
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index bfcf517ac9..3619b96e5a 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.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/test/test_xdr.py b/Lib/test/test_xdr.py
index 5d9a139b04..0cc7a3aff7 100644
--- a/Lib/test/test_xdr.py
+++ b/Lib/test/test_xdr.py
@@ -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
diff --git a/Lib/test/testall.py b/Lib/test/testall.py
index 5bb5f0c72c..e410e8f8bb 100644
--- a/Lib/test/testall.py
+++ b/Lib/test/testall.py
@@ -33,6 +33,7 @@ tests = ['test_grammar',
'test_imageop',
'test_imgfile',
'test_regex',
+ 'test_rotor',
]
if __name__ == '__main__':