sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #10745
Re: [Question #194681]: Use String to call Function?
Question #194681 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/194681
RaiMan proposed the following answer:
Sorry, that might have been my fault: my primary systems are Macs, so I always check on these first.
In this case, I only now went on my Win7 to test ...
and UUUUuuups, it does not work as expected.
This is based on a bug, with internally acting on sys.path creating odd entries, that I thought would have been fixed with the latest build r930/931 - but it seems that not fixed.
So I have made a script, that is equivalent, but ugly - but it works.
I go down to the .py level for the import and so I have to add the image path.
So sys.path and image path are prepared before the import/run and reset
afterwards (looks a bit weird, but this stuff is really not yet stable
in Sikuli).
The debug prints can be deleted, when it works.
this is the code:
import os
dir = os.path.dirname(getBundlePath())
tests = os.path.join(dir, "Tests")
modulesToRun = ("Test1", "Test2")
popup("OK starting Tests in Modules")
for currentModule in modulesToRun:
popup("Working with module " + currentModule)
currDir = os.path.join(tests, currentModule+".sikuli")
if not currDir in sys.path:
sys.path.append(currDir)
addImagePath(currDir)
# debug only
print("Working with module " + currentModule)
for e in sys.path: print e
print "1 IPATH*** ", list(getImagePath())
# debug only
exec("import "+ currentModule)
exec(currentModule + ".runModule()")
# debug only
for in in range(3): sys.path.pop()
for e in getImagePath(): removeImagePath(getImagePath().pop())
print "2 IPATH*** ", list(getImagePath())
# debug only
print("Testing ended")
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.