/usr/share/doc/python-nwsclient/examples/exp.py is in python-nwsclient 1.6.4-8build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #!/usr/bin/env python
# XXX Might want to turn this into a sleigh test suite.
# It's getting to be a bad example.
import sys, os, math, operator, getopt
from nws.sleigh import Sleigh, SleighIllegalValueException, sshcmd
import worker
verbose = 0
launch = sshcmd
scriptDir = None
try:
opts, args = getopt.getopt(sys.argv[1:], 'vws:')
except getopt.GetoptError, e:
print >> sys.stderr, e.msg
sys.exit(1)
for opt, arg in opts:
if opt == '-s':
scriptDir = arg
elif opt == '-v':
verbose = 1
elif opt == '-w':
launch = 'web'
else:
print >> sys.stderr, 'error: getopt should have prevented this'
sys.exit(1)
print "scriptDir =", scriptDir
print "verbose =", verbose
print "launch =", launch
if launch == 'web':
print "waiting for web launch workers..."
s = Sleigh(scriptDir=scriptDir, launch=launch, verbose=verbose)
t = map(math.exp, range(100))
print "testing a simple list:"
r = s.eachElem(math.exp, range(100))
if r != t:
print "error:", r
else:
print "success"
print "testing list of one list:"
r = s.eachElem(math.exp, [range(100)])
if r != t:
print "error:", r
else:
print "success"
print "testing a list of two lists:"
r = s.eachElem(operator.add, [range(100), range(100)])
if r != range(0, 200, 2):
print "error:", r
else:
print "success"
print "testing a simple list and a fixed arg:"
r = s.eachElem(operator.add, range(100), 100)
if r != range(100, 200):
print "error:", r
else:
print "success"
print "testing a list of one list and a fixed arg:"
r = s.eachElem(operator.add, [range(100)], 100)
if r != range(100, 200):
print "error:", r
else:
print "success"
print "testing a list of one list, a fixed arg, and a permute vector:"
r = s.eachElem(operator.add, [range(100)], 100, argPermute=[1, 0])
if r != range(100, 200):
print "error:", r
else:
print "success"
print "testing a zero length permutation vector:"
r = s.eachElem(worker.answer, range(100), argPermute=[])
if r != [42] * 100:
print "error:", r
else:
print "success"
print "testing a short permutation vector:"
r = s.eachElem(math.exp, [range(100), range(100,200), range(200,300)], argPermute=[0])
if r != t:
print "error:", r
else:
print "success"
print "testing a short permutation vector non-blocking:"
p = s.eachElem(math.exp, [range(100), range(100,200), range(200,300)],
argPermute=[0], blocking=False)
print "check:", p.check()
r = p.wait()
if r != t:
print "error:", r
else:
print "success"
print "testing exception"
try:
s.eachElem(math.exp, 0)
print "error: expected illegal value exception"
except SleighIllegalValueException, e:
print "success:", e
raw_input("Hit return to stop sleigh: ")
s.stop()
|