Reputation: 766
I have an built app that contains a window made with wxPython that contains a text box to take inputs from the user, and the enter
event is bound to a function and sends a wx.Frame object to it. The input value is accessed with self.txt.GetValue()
I need to write some unit tests for the function but cannot seem to find a way to create and pass an argument to the function in a way that the value will still be accessible with the same statement.
I also found a number of modules for testing python apps, including one on the wxPython page (pyunit), but the main intuition of HOW to pass the value is not clear.
How do I go about doing this?
Upvotes: 3
Views: 1117
Reputation: 33071
If you decouple the function from wxPython, you can easily unit test it. So let's say you have a widget bound to an event handler like this:
def on_text_change(self, event):
my_module.do_something_with_text(self.txt.GetValue())
Now you can add a unit test for my_module.do_something_with_text
because it won't depend on wxPython.
If you want to create what amounts to an automated UI test, you can use UIActionSimulator - https://wxpython.org/Phoenix/docs/html/wx.UIActionSimulator.html
Upvotes: 5