[Tutor] Best Code testing practice?

Matt D md123 at nycap.rr.com
Thu Jun 20 16:32:29 CEST 2013


On 06/20/2013 08:52 AM, Alan Gauld wrote:
> On 20/06/13 12:43, Matt D wrote:
> 
>> Is there a fast way test some piece of code?
> 
> There are several testing frameworks for testing Python code.
> nose is one example.
> But...
> 
>> look at the GUI I am making with out changing the file in dir 'baz'
> 
> In general your GUI should not be tied into one particular file or
> folder structure. You should be able to specify that either in a config
> file that you read when the GUI starts or as command line arguments.
> 
> That way you can separate your test data from your real production
> data.
> 
>> running the actual program (which is quite extensive).
> 
> Hopefully you have separated the presentation logic (the GUI
> components) from the processing logic? If so testing the processing
> logic is fairly easy using one of the aforementioned frameworks. Testing
> the GUI itself is more tricky and usually requires
> using some kind of robot to mimic what a user does by sending
> dummy event messages into the GUI toolkit.
> 
>> just have a .py file with only the smallest amount of code possible to
>> make the GUI run, and I could run the .py file from the interpreter to
>> make the GUI run, this would be beautiful.
> 
> That depends on how you built the app. If the GUI is encapsulated
> as an an object then you can usually import the GUI code and instantiate
> the object. But if you have hard coded links from the GUI event handlers
> to your processing logic and from there to the real data/files then its
> going to be difficult.
> 
>> Do we need an IDE for this sort of thing
> 
> Almost certainly not, although it may help.
> You never *need* an IDE for python, they are only there to help.
> 
> The bottom line is that if your application architecture
> has been well designed to separate the GUI and processing
> and you have decoupled the data from the logic then testing
> should be straightforward. If its all one big organic mashup
> then you have a tough time ahead. It may be easier to
> re-architect the application and then test it than to
> struggle to bolt on tests retrospectively.
> 
all i really want to do is test the the GUI code.   i am working on a
'tab' in a notebook of 7 tabs, which is itself part of a large python
program which gets all of its computations done in C++.  The code for
'tab', or wxPanel really, i am using is in one file.
But i dont need to get into all that at this point.  all i want to be
able to do is make a small sample app that mimics the one tab i am
working on and be able to run it to see if the lay out and dialogs are
correct.
Thanks!


More information about the Tutor mailing list