0

I am suppose to assert my code function to make sure they are running smoothly but I am not sure how I should go about this. The function itself makes a widget disappears and the reappears if the user clicks on it again.

For example,

yes = w.ToggleButton(description="I'll be there!")

def yes_ans(y):
    with out:
        if y['new']:  
            display(name, 
                    food, 
                    friends_1, 
                    friends_2, 
                    send)
        else:
            out.clear_output()

yes.observe(yes_ans, 'value') 

How should I assert this? I don't know if what I am saying is clear, but any help would be great thank you.

1
  • assert i_expect_this_to_be_true == True and i_expect_this_to_be_false == False Commented Dec 6, 2022 at 20:31

1 Answer 1

0

An assert statement in python simply evaluates an expression and raises an exception if the expression evaluates to False (or something false-like, ie, an empty collection, a null string, etc)

There are two ways you could test this. The first would be to identify some consequence of the branch that you want to test, that is to say, some state that you'd expect to see if the display function were called with the arguments you've provided or if the out.clear_output function were called. You would then assert that that state is the case. The test will pass silently if the assertion succeeds (and your test framework will probably display a dot to indicate a passed test), or it will fail noisily if the assertion fails to be the case

Unfortunately, based on the information given in the question we can't give better suggestions about the state you might test.

Another approach, slightly more advanced, would be to use the mock library to "mock out" the functions you want to test and assert that they have been called. You can learn more about this by reading the mock docs

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.