assert(function name)

Asked by Sreelekshmi on 2020-03-30

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Sreelekshmi
Solved:
2020-03-31
Last query:
2020-03-31
Last reply:
2020-03-30
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

Manfred Hampl (m-hampl) said : #2

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

Sreelekshmi (sree2604) said : #3

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

Manfred Hampl (m-hampl) said : #4

What's now the relevant snippet of your code?

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

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

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.

Sreelekshmi (sree2604) said : #8

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