assert(function name)

Asked by Sreelekshmi

In my function module having a function,

def Enable(obj1,obj2):
    m=findBest(obj1,obj2)
    m.getIndex(),m.getScore()

    print(m.getIndex(),m.getScore())
    if m.getIndex()==0:
        print("Button is Enabled")
    else:
        print("Button is not enabled.")
In another module where class is defined I am importing this module and asserting the functions

import function module name
class Test(unittest.TestCase):
        def test01():
              assert(Enable(obj1,obj2))

The assert always resulting as failed eventhough it is supposed to be passed.

Please note that for the functions using if exists(image) , assert is working as expected.

Question information

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

the function does not return a suitable value for assert:

def Enable(obj1,obj2):
    m=findBest(obj1,obj2)
    # m.getIndex(),m.getScore() # does not make sense

    print(m.getIndex(),m.getScore())
    if m.getIndex()==0:
        print("Button is Enabled")
        return True
    else:
        print("Button is not enabled.")
        return false

Revision history for this message
Manfred Hampl (m-hampl) said :
#2

assert() needs a boolean value, but your subroutine Enable(obj1,obj2) does not return anything.

Revision history for this message
Sreelekshmi (sree2604) said :
#3

sorry I missed that, my function returns true or false . Still assert always fails.

Revision history for this message
Manfred Hampl (m-hampl) said :
#4

What's now the relevant snippet of your code?

Revision history for this message
Sreelekshmi (sree2604) said :
#5

def Enable(obj1,obj2):
    m=findBest(obj1,obj2)
    m.getIndex(),m.getScore()

    print(m.getIndex(),m.getScore())
    if m.getIndex()==0:
        print("Button is Enabled")
        return True
    else:
        print("Button is not enabled.")
        return False

class Test(unittest.TestCase):
        def test01():
              assert(Enable(obj1,obj2))
assert always fail

Revision history for this message
Sreelekshmi (sree2604) said :
#6

def Enable(obj1,obj2):
    m=findBest(obj1,obj2)
    m.getIndex(),m.getScore()

    print(m.getIndex(),m.getScore())
    if m.getIndex()==0:
        print("Button is Enabled")
        return True
    else:
        print("Button is not enabled.")
        return False

class Test(unittest.TestCase):
        def test01():
              assert(Enable(obj1,obj2))
assert always fail

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

What do the print statements show when running the program?

What should the statment

    m.getIndex(),m.getScore()

do (already asked by RaiMan)? It does not make any sense.

Revision history for this message
Sreelekshmi (sree2604) said :
#8

Hi Manfred, Its working , I just had to restart the sikuli. Thanks :-)