Re: Debugging Python scripts



Hi Rob,

To try and answer your questions:

1. Print should send it's data to Dia's stdout, so if you start Dia from the command line, you should see the output from your script there.
2. Afaik there isn't any way to get Dia to reload the scripts as they are loaded at start up.

Some tips on debugging Python in regards to Dia and in general that I have learned over the years:

The easiest way in the long run is to look at using unittest and mock object to set up some unit tests - you don't have to go the full TDD route, but take it from me, a few well designed tests now will save a lot of pain later. By using unittest and mock objects, you can control how your code interacts with Dia in a deterministic fashion and not have to mess around with manually testing each possible case.

With mock object, you can mock all or just part of an existing Python object. This blog explains Mock object in detail. To really speed things up, I created a Mock Dia python class which lets you write and test your code without having to start Dia at all. You can find it here if it's something you think might help: https://github.com/chebizarro/dia-test. With unittest and the mock Dia object you should be able to design and code *most* of your project without leaving your preferred IDE. One caveat is that the Dia Mock object is not complete, as I only implemented the functionality that I needed for my project, which seems like it had fairly similar requirements to your own. You can find that project here if you think it might be useful - https://github.com/chebizarro/postdia.

In terms of debugging, I personally can't recommend pudb enough, it's an interactive command line debugger which you can use with unittest to zero in on what part of the code is causing the problem. That way you don't need to pollute your code with print statements and you can examine the internal state of your objects much more thoroughly.

I hope that helps and good luck!
Cheers
Chris D


2015-12-20 2:33 GMT-08:00 Rob Wortham <r h wortham gmail com>:
I am trying to use Python scripting in Dia to export a hierarchical diagram in a specific format. I'm new to Python. I see that codegen.py is almost what I need, so I plan to take that as a starting point. Because I'm new to Python I'll need to iterate and learn to get this coded.

Just a couple of hopefully straightforward questions ...

1. Where does print send its data (for debugging)? It does not seem to send it to the Dia Python console. Where is stdout?
2. How can I get Dia to reload the script as I edit it. At the moment changes only seem to take effect if Dia is stopped and restarted.

Rob

-- 
Rob Wortham
PhD Student, Department of Computer Science
E: r h wortham bath ac uk
W: www.robwortham.com T:@RobWortham


_______________________________________________
dia-list mailing list
dia-list gnome org
https://mail.gnome.org/mailman/listinfo/dia-list
FAQ at http://live.gnome.org/Dia/Faq
Main page at http://live.gnome.org/Dia





--
Chris Daley
Pacific Northwest

e: chebizarro gmail com
m: +1601 980 1249
s: chebizarro
tw: chebizarro
tz: PDT



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]