[Tutor] Best Code testing practice?

Oscar Benjamin oscar.j.benjamin at gmail.com
Fri Jun 21 11:49:43 CEST 2013


On 20 June 2013 16:11, Matt D <md123 at nycap.rr.com> wrote:
>> Then make a small app that has just one tab (or has six dummy tabs if
>> necessary). When this app runs it should use the same function from
>> your main application to lay out the widgets but but it shouldn't bind
>> the (same) event handlers.
>>
> right make a small sample app.  exactly.  im sorry if im dense or
> whatever and obviously i am super new to this process. but i can write
> the scripts in gedit and then what?  how do i run that file and make the
> gui start? should i be doing something like this?:
>
>>>> execfile('filename.py')

You still haven't specified what GUI library you're using or described
your code layout so what I'll say below is very generic. In my mind it
looks very vaguely like this:

# file: myapp.py

def layout(tab):
    tab.add_widget()
    # blah blah blah

if __name__ == "__main__":
    app = App()
    frame = Frame(app)
    tabs = frame.add_tabs(7)
    layout(tabs[0])  # Add widgets to the tab
    bindevents(tabs[0])
    # blah blah blah
    show()

When you run the above script with 'python myapp.py' is runs like
normal. Then you have another script:

# file: test_myapp.py

from myapp import layout

if __name__ == "__main__":
    app = App()
    frame = Frame(app)
    tabs = frame.add_tabs(1)
    layout(tabs[0])  # Add widgets to the tab
    # don't bind anything here
    show()

Now when you run 'python test_myapp.py' it opens up the dummy app. The
same layout() function is used by the real app and the dummy app so
the dummy app gives you a way of checking that it works.


Oscar


More information about the Tutor mailing list