assertNotExists does not work in unit test --- no longer available with Sikuli X

Asked by etherman

use
assert not exists()

instead
-----------------------------------

Sorry to ask may be some of the silly questions.

i am looking at the unit test sample application for jedit which included with Sikuli. i am not able to use some of the assert used in jedit and gets error. For example the following.

self.assertNotExist("LoginDlg.png")
AttributeError: 'MyTest1' object has no attribute 'assertNotExist'

Most of the assert in jedit unit test does not work with my unittest script.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
etherman
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- i am looking at the unit test sample application for jedit which included with Sikuli.
not clear, what you are talking about?

--- self.assertNotExist("LoginDlg.png")
has to be replaced by
self.assert not exists("LoginDlg.png")

when using Sikuli X.

Revision history for this message
etherman (nambiar) said :
#2

Here is the sample code snippet from Jedi unitest shipped with sikuli x-1.0rc3

       def test_textarea_add_del_by_menu(self):
            type("hello world")
            assertExist(x.png)
            click("a", KEY_CTRL)
            type("\n######")
            assertNotExist(x.png)

I used the "assertNotExist" similar as above code snippet from Jedi in the following script

class MyTest1(unittest.TestCase):
    def setUp(self):
        self.aview = App(r'C:\Program Files\myApp.exe')
        #self.aview.open()

    def tearDown(self):
        pass

    def test_login(self):
        self.aview.open()
        wait(3)
        self.assertNotExist(pattern("LoginDlg.png").similar(0.95))

But i get the following error

       self.assertNotExist(pattern("LoginDlg.png").similar(0.95))
        AttributeError: 'MyTest1' object has no attribute 'assertNotExist'

i tried without using the pattern keyword as shown in the description of this issue but that also gets the error. Lot of similar assert is used in Jedi unit test.

self.assert not exists("LoginDlg.png") --- does not work for me, IDE displays the error "mismatched input exists"

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Uuups, sorry for being blind :-(

you have to use

assert not exists()

because assert is a built-in Python feature, that raises an assertion exception based on the evaluation of the given condition, and has to be used without self.

self.assert as an attribute of the TestCase object MyTest1 is not defined., since you did not define it.
same goes for:
self.assertNotExist()

--- Sikuli test cases
The mentioned test cases that "come" with Sikuli are the tests internally used by the developers, to test the features of Sikuli, after having made changes to Sikuli.
assertNotExist was available in Sikuli 0.9, but was deprecated in 0.10 and is no longer available with Sikuli X.
one has to use "assert not exists()" instead.

--- assertXXXX in TestCase class
there are some extra assertXXX methods defined (http://docs.python.org/library/unittest.html#test-cases)

Revision history for this message
etherman (nambiar) said :
#4

You made things clearer.
Thanks a lot