Newer
Older
Markus Frank
committed
from ROOT import gSystem
import os
import platform
if platform.system()=="Darwin":
gSystem.SetDynamicPath(os.environ['DD4HEP_LIBRARY_PATH'])
Markus Frank
committed
gSystem.Load('libDDPython')
from ROOT import DD4hep as Core
name_space = __import__(__name__)
def import_namespace_item(ns,nam):
scope = getattr(name_space,ns)
attr = getattr(scope,nam)
setattr(name_space,nam,attr)
return attr
def a_func():
print 'Hello world'
return 1
class a_class:
def __init__(self):
pass
def fcn(self):
print 'Hello world from member function fcn'
return 1
def fcn_except(self,args,aa):
print 'Hello world from member function fcn1 a1=',args,' a2=',aa
raise RuntimeError('Except from python test object a_class')
Markus Frank
committed
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
return 6
py = import_namespace_item('Core','DDPython')
print '+++++ Test: Execute statements in python with C++ indirection'
py.instance().execute('import sys')
py.instance().execute('print "Arguments:", sys.argv')
print '\n'
obj=a_class()
import sys, traceback
print '+++++ Test: simple function call'
ret = py.instance().call(a_func,None)
print 'ret:',ret
print '\n'
print '+++++ Test: object method call'
ret = py.instance().call(obj.fcn,None)
print 'ret:',ret
print '\n'
print '+++++ Test: object method call with non callable'
try:
ret = py.instance().call(1,None)
print 'ret:',ret
except:
traceback.print_exc()
print '\n'
print '+++++ Test: object method call with exception in python callback'
try:
ret = py.instance().call(obj.fcn_except,(1,[1,2,3,4,5,6],))
print 'ret:',ret
except:
traceback.print_exc()
print '\n'
print '+++++ All Done....\n\n'
Markus Frank
committed
#py.instance().prompt()
sys.exit(0)