![]() |
Python Testing Strategies -- How did you do it?
It seems to me that python is a great language, but it is a very dynamic language. And while that is one of the things that makes it so awesome -- it's also one of the things that makes thorough testing absolutely vital since misspelling a variable name can crash your program if you're not prepared for this.
One way that we dealt with this is by making sure that all of the complex interactions of our robot was separated out in modules, and that the complexity stayed out of the main loop. Then, functions were called in the main loop, but each function was surrounded by a try..except block that *ideally* makes it so that if one component of our robot fails (ie, I accidentally added the wrong variable name to the arm code), that the other parts would still run. So the blocks would all look something like this: Code:
try:Code:
try:The fake wpilib contained all the classes/functions from wpilib that we used -- except parameters that didn't really matter for our testing would just not be used, and many functions were just implemented as 'pass'. For example, our watchdog class was implemented like this: Code:
class Watchdog(object):Code:
class Joystick(object):As you can see, the chief advantage of this is that we could run such a program directly on our programming laptop before the program is loaded onto the cRio, and hopefully catch any syntax errors or whatever before we try it on the robot. We added some simple state machines to model how the robot might be stimulated by various sensors and whatever, and caught a few bugs that way too. Of course, there's all sorts of things that one could do with this approach. I'll probably publish our team's source code later this week, then you can look at it yourself. Any other useful strategies that others used? :) |
Re: Python Testing Strategies -- How did you do it?
Dustin,
Thanks for sharing this. I was hoping there was an easier way to do it of course, but knowing one team did this implies there is not. Have you considered contributing your library of stubs to the existing Python libraries (or packaging it separately) so other teams can use it? I think that is going to prove even more valuable than your "real code" Jeanne |
Re: Python Testing Strategies -- How did you do it?
Quote:
In the past I made a more full-featured test harness for WPILib/C++, but I haven't really been motivated to do that for python yet. Maybe I'll play with PyQT at some point. |
Re: Python Testing Strategies -- How did you do it?
Quote:
|
Re: Python Testing Strategies -- How did you do it?
You also hacked winpdb to run on the cRIO, right? How did that work out?
|
Re: Python Testing Strategies -- How did you do it?
Quote:
Quote:
|
Re: Python Testing Strategies -- How did you do it?
Wow, I really like this idea. I've started preparing this years event as we are doing a build for LabVIEW and Python, Ive been doing research and this will be VERY useful. Using this with some sort of Dynamic UI with tkinter for the fake_wpilib class would be awesome. It would require some time to work out all the bugs in making it very dynamic and yet still be able to use it as simple as you have it, but its worth the time over the next off-season to get this done.
|
Re: Python Testing Strategies -- How did you do it?
One thing that I like about Python is the simplicity of debugging with print statements. I see that the sample code has some prints to show what is happening ("Running teleop()", etc).
Where does that output go? How do I tail the output? |
Re: Python Testing Strategies -- How did you do it?
Quote:
|
Re: Python Testing Strategies -- How did you do it?
I got the Python netconsole working, but that does not allow 2-way communication, right?
So, how do you type "reboot" when needed? I tried the FRC NetConsole, but could not get it to work even 1-way. |
Re: Python Testing Strategies -- How did you do it?
Quote:
|
Re: Python Testing Strategies -- How did you do it?
Quote:
In order to receive the UDP communications for the NetConsole, I believe the subnet mask has to match on the cRio and the receiving PC (and possibly the router too). I've had problems with the FRC NetConsole when they didn't match. |
Re: Python Testing Strategies -- How did you do it?
Quote:
https://github.com/rbmj/netconsole It works on linux (I still need to test it on windows). I tried to be cross-platform, but sometimes things don't work as they're supposed to. There are some issues with the console picking up packets that were sent out to broadcast, even though they're on a different port (so I suspect that they're being echoed by the cRIO to signal receipt). If someone wants to take a closer look at that and submit a patch... |
Re: Python Testing Strategies -- How did you do it?
So, is typing "reboot" to the netconsole faster than using the reset button on the cRIO, or is it essentially the same thing?
|
Re: Python Testing Strategies -- How did you do it?
In my experience it's the same.
|
| All times are GMT -5. The time now is 19:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi