← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #284591]: Consolidating Scripts into one folder

 

Question #284591 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/284591

Karl posted a new comment:
I don't want to have all my users install Jython as you said in
https://answers.launchpad.net/sikuli/+question/273373.

I like that Sikuli includes Jython and want to leverage the product to
run a framework of tests. The use of ".sikuli" in the foldernames breaks
the standard python/jython import. If I fully embrace the use of image
folders, I don't see what role the folders play. Can you specify the
disadvantages other than not having the IDE (which is a huge one)?

I'm including more information to demonstrate my use case.

I am using a hierarchy of folders to classify my tests on my desktop.
Here is what it looks like:

Application
    Area1
        SubArea1
        SubArea2
        SubArea3
    Area2
        SubArea1
        SubArea2
        SubArea3
    Area3
        Tests
            Test1.Sikuli
        SubArea1
        SubArea2
        SubArea3
            Tests
                Test1.sikuli
                Test2.sikuli
                Test3.sikuli

I added empty __init__.py folders throughout the structure to follow
standard python usage for packages.

I would like to use:
addImportPath("C:\\Users\\User\\Desktop\\Application")
import Area3.Tests.Test1
import Area3.SubArea3.Tests.Test1

Without talking about the image folders, the files have the following contents:
Application/Area3/Tests/Test1.sikuli/Test1.py: print "hello Area3"
Application/Area3/SubArea3/Tests/Test1.sikuli/Test1.py: print "hello SubArea3"

On first run, the expected output would be:
hello Area3
hello SubArea3

But, the error is:
[error] script [ pythonImport ] stopped with error in line 2
[error] ImportError ( No module named Test1)
*This is because there is no Test.py in the Test folders.

If I move Test1.sikuli from Area3 into the Application folder.  On first run, this is the output:
hello Area3
hello Area3
*This is similar to the addImportPath example: http://sikulix-2014.readthedocs.org/en/latest/scripting.html#addImportPath. Note that even though the third line explicitly gives the import path, the module name is only used and the first found module is in the folder of addImportPath.

If I move both the python files into their respective Tests folder, I
get the expected output.

To elaborate even further, I am using unittest to build these
collections of tests as stated on multiple questions and FAQs. Comment
#3 of this question
(https://answers.launchpad.net/sikuli/+question/262456) states "all
.sikuli's that are to be imported in one workflow, must have different
names, despite the fact, that they are in different folders (the folder
is not part of the module name)." The naming and requirement to use
*.sikuli folders to hold sikuli scripts makes working with a hierarchy
of folders practically impossible. Changing this folder suffix without
changing anything else would make this work. Another alternatives is to
let the IDE edit and run .py files.

The strengths of this usage is that the main script can be put anywhere
on the OS and unique names aren't needed. Also the imagepath would only
need to be defined in the testcase class.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.