+from test_support import verbose
import sys
import new
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
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'
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
+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:
import sys
def test(name, input, output, *args):
+ print 'testing:', name
f = getattr(operator, name)
params = (input,) + args
try:
+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:
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
try:
pwd.getpwnam(fakename)
except KeyError:
- pass
+ print 'caught expected exception'
else:
print 'fakename', fakename, 'did not except pwd.getpwnam()'
try:
pwd.getpwuid(fakeuid)
except KeyError:
- pass
+ print 'caught expected exception'
else:
print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()'
--- /dev/null
+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!')
# 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.
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)"
+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
'test_imageop',
'test_imgfile',
'test_regex',
+ 'test_rotor',
]
if __name__ == '__main__':