-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwf.py
69 lines (65 loc) · 2.11 KB
/
twf.py
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
import os,sys
sys.path.insert(0,"/home/twf/mdsplus-tdishr/mdsobjects/python/build/lib")
try:
reload(MDSplus)
print "reloaded"
except:
import MDSplus
print MDSplus.__file__
MDSplus.Data.usePython=True
def resultStr(good):
if good:
return "Test result: Suc"+"cess" ### so you can search for good results
else:
return "Test result: Fai"+"led" ### so you can search for bad results
def TdiEvaluate(arg):
old=MDSplus.Data.usePython
MDSplus.Data.usePython=False
try:
ans=MDSplus.tdibuiltins.EVALUATE(arg).evaluate()
finally:
MDSplus.Data.usePython=old
return ans
def testEvaluate(expr_text,nodoc=False):
"""Test evaluation of expression. Test consists of:
Compile with python and tdishr and compare the results
Evaluate with python and tdishr and compare the results
print __doc__ string of the builtin if True
"""
MDSplus.Data.usePython=True
MDSplus.Data.debug=False
MDSplus.Data.showTdi=True
try:
exp=MDSplus.Data.compile(expr_text)
print(exp)
MDSplus.Data.usePython=False
exptdi=MDSplus.Data.compile(expr_text)
MDSplus.Data.usePython=True
if not exp.compare(exptdi):
print("""%s
Compile result differed
Python produced: %s,%s
TDISHR produced: %s,%s
""" % (resultStr(False),str(exp.decompile()),str(type(exp)),str(exptdi.decompile()),str(type(exptdi))))
else:
print exp
ans=exp.evaluate()
MDSplus.Data.usePython=False
print exp
tdians=exp.evaluate()
MDSplus.Data.usePython=True
if not ans.compare(tdians):
print("""%s
Evaluate result differed
Python produced: %s
TDISHR produced: %s
""" % (resultStr(False),str(ans.decompile()),str(tdians.decompile())))
else:
print(resultStr(True))
print(exp.evaluate().decompile())
except:
print(resultStr(False))
raise
if not nodoc:
print(exp.__doc__)
testEvaluate('ACHAR(BUILD_SIGNAL([88,89,90],*,*))',nodoc=True)