Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 21st, 2006, 12:58 PM   #1
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
unittest for every module

All right, you win. Ruby is fun, but I'm finding through use that Python is more scalable, clean, and more suited to readability. Unfortunately, it seems to me that the trend in the Ruby community is to encourage golf and one-liners, much like Perl. In Ruby's defence, it still has a much more pure design that is more thought-out then Python.

Anyway, back to the main point of this thread.
To my delight, python comes with a unit test framework. It's not as good as Ruby's, but it's still useful.

My idea was to create a bunch of unit tests for every module like so:

python Syntax (Toggle Plain Text)
  1. if __name__ == "__main__":
  2. import unittest
  3. #Inherit from unittest.TestCase and run tests

My questions are:

a) Is this a good idea?
and b) Should I create the class and run the tests under the if condition, or create some kind of main() method that's called under the if __name__.. etc thing?
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!

Last edited by Jessehk; Jul 21st, 2006 at 1:11 PM.
Jessehk is offline   Reply With Quote
Old Jul 21st, 2006, 1:28 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Sure, it's a good idea, so long as you don't have your unit tests in the same module as your code.

The unit tests for my modules tend to look something like:
python Syntax (Toggle Plain Text)
  1. import unittest
  2. from module_to_be_tested import *
  3.  
  4. class ModuleTest(unittest.TestCase):
  5.  
  6. def test_my_double_function(self):
  7. assert my_double_function(2) == 4
  8. assert my_double_function(3) == 6
  9.  
  10. ...
  11.  
  12. if __name__ == "__main__":
  13. unittest.main()
I agree with you that Python's unittest module isn't as good as it could be. It's very Java-like, and to my mind py.test is far superior (though not a standard module, and not yet released as stable).

I also agree with you about Ruby. I like the way it handles properties and classes, but dislike the Perl hackiness (if there is such a word) that pervades the language.
Arevos is offline   Reply With Quote
Old Jul 21st, 2006, 1:38 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
So I guess you'd have something like:

/app
   |____/lib
   |____/test
   |____/bin

?

In that case, if I was in /test, and I wanted to import a module in another directory, would I just append to sys.path ?

EDIT: Oh, and thanks. I'll have to look into py.test.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Jul 22nd, 2006, 10:17 PM   #4
Silvanus
Hobbyist Programmer
 
Silvanus's Avatar
 
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 4 Silvanus is on a distinguished road
You might want to look into Nose; it's the unit testing framework used by Turbogears.
__________________
:wq
Silvanus is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update a Module Dietrich Python 2 Apr 29th, 2006 2:19 PM
C++ OWL What am I doing wrong Vagabond C++ 7 Mar 24th, 2006 6:31 PM
cgi module index.py?var=x how do i retrieve this w/o os module cypherkronis Python 1 Jul 3rd, 2005 2:10 PM
Numeric module Dietrich Python 2 Apr 5th, 2005 2:37 AM
word wrap in module window? chepfaust Visual Basic 2 Mar 17th, 2005 8:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC