pyunit-interest Mailing List for PyUnit testing framework
Brought to you by:
purcell
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(12) |
Jun
(16) |
Jul
(6) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(4) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
|
Feb
(11) |
Mar
(7) |
Apr
(50) |
May
(9) |
Jun
(5) |
Jul
(33) |
Aug
(9) |
Sep
(7) |
Oct
(7) |
Nov
(17) |
Dec
(4) |
2002 |
Jan
(8) |
Feb
|
Mar
(14) |
Apr
(9) |
May
(13) |
Jun
(30) |
Jul
(13) |
Aug
(14) |
Sep
|
Oct
|
Nov
(2) |
Dec
(11) |
2003 |
Jan
(8) |
Feb
(3) |
Mar
(6) |
Apr
(5) |
May
(15) |
Jun
(5) |
Jul
(8) |
Aug
(14) |
Sep
(12) |
Oct
(1) |
Nov
(2) |
Dec
(1) |
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(3) |
Jul
(4) |
Aug
(4) |
Sep
(2) |
Oct
|
Nov
|
Dec
|
2005 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(5) |
2007 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
|
Dec
|
2010 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: venkat <ven...@vo...> - 2012-04-19 11:55:52
|
i am new to python and just now started developing an linux application automation. scenario i am trying is thread.py --- will invoke all primary device threads and load test from testcase admincase.py --- hold my tests for the case.. what i am unable to do is i want to pass certain objects from thread.py to admincase.py when loading the test. how do i do that.. object which i am tryin to pass is (*EppQueue*) thread.py code |import threading import sys import time import logging import os import Queue from EPPimport EPP import ldtp import ldtputils from functionsimport functions from admincasesimport admincases import unittest #logging.basicConfig(level=logging.DEBUG, # format='(%(threadName)-10s) %(message)s', # ) class inittest(unittest.TestCase): global fun global EppQueue global window_name def cleanup(epp_port): if os.path.exists(epp_port): os.unlink(epp_port) def start_threads(EppQueue,server_ip,epp_port): epp= EPP EPP1= threading.Thread(name='EPP', target=epp, args=(server_ip,54321,epp_port,EppQueue,)) EPP1.setDaemon(True) EPP1.start() return epp fun= functions() EppQueue = Queue.Queue(1) server_ip='192.168.10.125' epp_port='/dev/ttyS17' print "Starting" cleanup(epp_port) print "Clean up Over" epp= start_threads(EppQueue,server_ip,epp_port) raw_input("###### Please Start the main appilcation in the ATM and hit a KEY to continue ############") check= 0 while check== 0: window_name= fun.start_up_verify('atm_main_app') if any(window_name): check= 1 else: check= 0 if not any(window_name): print "Please start the application and run the test" sys.exit(0) else: print window_name print "SYSTEM IS READY TO PERFORM TEST" raw_input("###### HIT ANY KEY TO START UNIT TEST ############") raw_input("kkk") test= unittest.defaultTestLoader.loadTestsFromName("admincases") unittest.TextTestRunner(verbosity=2).run(test) raw_input("keyy") print "final" | admincase.py code |import unittest from functionsimport functions import time import Queue class admincases(unittest.TestCase): global fun global EppQueue global window_name def test_case_1(self): print "test case 1" window_name= 'frmatm_main_app' fun.send_queue(self.EppQueue,"send_keys,&&&&&") fun.verify_screen(window_name,"ico0") fun.send_queue(self.EppQueue,"send_keys,C") fun.verify_screen(window_name,"ManagementFunctions") fun.send_queue(self.EppQueue,"send_keys,001234") fun.verify_screen(window_name,"MainMenu") fun.send_queue(self.EppQueue,"send_keys,1") fun.verify_screen(window_name,"Diagnostics") fun.send_queue(self.EppQueue,"send_keys,1") fun.verify_screen(window_name,"TerminalStatus") fun.send_queue(self.EppQueue,"send_keys,2") time.sleep(10) fun.send_queue(self.EppQueue,"send_keys,####****") fun= functions() #EppQueue = Queue.Queue(1) | Need some assistance on this... -- Regards Venkat.S |
From: Phlip <phl...@gm...> - 2010-01-13 20:09:26
|
PyUnit: (Long time first time!) The various assertions are not DRY when they force you to repeat any automatic diagnostic in a message string, if you provide it. Here's an example: def assertEqual(self, first, second, msg=None): self.assert_((first == second), msg or '%s != %s' % (first, second)) I think it should work like this: def assertEqual(self, first, second, msg=''): self.assert_((first == second), (msg + ('\n%s != %s' % (first, second))).strip()) That way if you provide a message (such as a message describing the semantic _meaning_ why "41" should not equal "42"), the assertion does not throw away the "41" and "42". Reflecting the source expressions passed in first and second is left as an exercise for the reader. C-: -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 |
From: Frank M. <fm...@qu...> - 2009-10-09 21:26:17
|
At 02:14 PM 10/9/2009, Ori Peleg wrote: >Sure, I've done it with <baseclassname>.__init__ and it worked fine, >but super() should work just as well - class TestCase itself doesn't >use either method, so whatever you choose you won't be in conflict. > >I just checked, and in Python 2.7 they converted to super() (see ><http://svn.python.org/view/python/trunk/Lib/unittest/case.py?view=markup>case.py >and ><http://svn.python.org/view/python/trunk/Lib/unittest/runner.py?view=markup>runner.py), >so you're probably better off using super() instead for future-proofing. Thank you!!!! Frank |
From: Frank M. <fm...@qu...> - 2009-10-09 16:12:22
|
At 01:34 AM 10/9/2009, Ori Peleg wrote: >It's better not to mix and match, like you said. >PyUnit itself uses <baseclassname>.__init__ and not super(), so >that's what I would suggest. How strange . . . you are correct. For its own base class calls unittest.py uses <baseclassname> as you stated. However, there are comments that suggest that the class is "super enabled" and will support that. Thus my concern. Have you actually done this . . .either way? Frank |
From: Frank M. <fm...@qu...> - 2009-10-09 00:21:10
|
So I have a test suite and I would like to have a __init__ function so some things can be done one time instead of each each case like setUp() wants to do. I gather I can create a __init__ function, but that I must call the base class __init__ function . . . so far so good. However, so far I have found three conflicting documents: 1. Says using super() is the way to call the base class under unittest 2. Says calling TestCase.__init__ is the way to call the base class under unittest 3. One is a long dissertation of the evils of super() and how a class hierarchy can either call either base class functions explicitly or use super() but not to mix and match. Clearly one of the documents is wrong. The question is, which one? The bottom line is . . . does anyone have a working example of a __init__ function in a test suite? Something that is known to work in a supported way by PyUnit? Frank |
From: W M. <wil...@pw...> - 2007-02-12 23:58:07
|
Greetings Justa-programmers. I am new to this list and python in general. I did a ( really ) quick inspection of the archive for this topic. So if this is old hat, please don't tar and feather me. After about a day of reviewing unittest.py and doing the google shuffle, I managed to extend unittest to run a master_setUp() and master_tearDown() method from my derived TestCase. The reasoning behind this was to avoid unnecessary socket connections/disconnects/reconnections. I needed: Running Master Set-up 1 -- Connection to Server setUp 1 -- Test Local setUp test_1 1 -- Run Test tearDown 1 -- Test Local tearDown .setUp 1 test_2 1 tearDown 1 .setUp 1 test_3 1 tearDown 1 .Running Master tearDown 1 -- Disconnection from Server Where I had three Tests,test_1 test_2 test_3, embedded in my TestCase derived class, each of which could share the socket connection. I could not find any similar code to this. I had considered py.test b/c it touts this functionality as one of its features, http://codespeak.net/py/current/doc/test.html#managing-test-state-across-test-modules-classes-and-methods . I found this implementation cumbersome and confusing, but it did work for what I needed. In my experience, this is a useful feature when configuring a hardware device for an actual test fixture. Alas, I was sure the strong design of unittest would lend to it being extended in this way. So for the google cache, I submit the following example of how I solved this issue. Please, any comments upon how this could be improved or simpler ways to accomplish the same result are welcomed. ( FYI: I use tabs ) I can attach as file, if that is preferred. Sincerely, William Meadows simple_test.py :: #### #!/usr/bin/python import sys import unittest class MyTestSuite( unittest.TestSuite ) : master_setUpName = "master_setUp" master_tearDownName = "master_tearDown" def __init__( self, tests = () ) : unittest.TestSuite.__init__(self,tests) self.numtests = self.countTestCases() self.numtestsleft = self.numtests def run( self, result ) : for test in self._tests : # Sometimes,when thru unittest.main() a MyTestSuite instance gets passed here . # This instance appears to be a Suite of Suites ... # I cannot figure how this get's constructed in unittest ?? if issubclass( type(test), unittest.TestCase ) : if self.numtestsleft == self.countTestCases(): eval("test.%s"%(self.master_setUpName))() self.numtestsleft = self.numtestsleft - 1 if result.shouldStop : break # Run a TestSuite or/ TestCase test(result) if issubclass( type(test), unittest.TestCase ) : if self.numtestsleft == 0 : eval("test.%s"%(self.master_tearDownName))() return result class MyTestLoader( unittest.TestLoader) : suiteClass = MyTestSuite class SimpleTest( unittest.TestCase ) : num = 1 def master_setUp(self): print "Running Master Set-up %d " % ( self.num ) def master_tearDown(self): print "Running Master tearDown %d " % ( self.num ) def setUp(self): print "setUp %d " % ( self.num ) def tearDown(self): print "tearDown %d " % ( self.num ) def test_1(self): print "test_1 %d " % ( self.num ) def test_2(self): print "test_2 %d " % ( self.num ) def test_3(self): print "test_3 %d " % ( self.num ) class SimpleTest3( SimpleTest ) : num = 3 if __name__ == "__main__" : pickOne = None if len(sys.argv) > 1 : pickOne = int(sys.argv[1]) if pickOne == None : unittest.main( testLoader = MyTestLoader() ) #/OR elif pickOne == 1 : unittest.TextTestRunner().run( MyTestLoader().loadTestsFromTestCase(SimpleTest) ) unittest.TextTestRunner().run( MyTestLoader().loadTestsFromTestCase(SimpleTest3) ) #### Sample Output: #### /* notice testoob fails to work correctly with this modification, no idea why. Perhaps, it doesn't pick-up the unittest.main( testLoader = option ) ?? > python /usr/lib/python2.4/site-packages/unittestgui.py test_sample.SimpleTest , does not seem to be working either */ user@ubuntu:~/tmp/test/unittest$ testoob test_sample.py setUp 1 test_1 1 tearDown 1 .setUp 1 test_2 1 tearDown 1 .setUp 1 test_3 1 tearDown 1 .setUp 3 test_1 3 tearDown 3 .setUp 3 test_2 3 tearDown 3 .setUp 3 test_3 3 tearDown 3 . ---------------------------------------------------------------------- Ran 6 tests in 0.002s OK /* This works */ user@ubuntu:~/tmp/test/unittest$ python test_sample.py Running Master Set-up 1 setUp 1 test_1 1 tearDown 1 .setUp 1 test_2 1 tearDown 1 .setUp 1 test_3 1 tearDown 1 .Running Master tearDown 1 Running Master Set-up 3 setUp 3 test_1 3 tearDown 3 .setUp 3 test_2 3 tearDown 3 .setUp 3 test_3 3 tearDown 3 .Running Master tearDown 3 ---------------------------------------------------------------------- Ran 6 tests in 0.001s OK /* this works also */ user@ubuntu:~/tmp/test/unittest$ python test_sample.py 1 Running Master Set-up 1 setUp 1 test_1 1 tearDown 1 .setUp 1 test_2 1 tearDown 1 .setUp 1 test_3 1 tearDown 1 .Running Master tearDown 1 ---------------------------------------------------------------------- Ran 3 tests in 0.000s OK Running Master Set-up 3 setUp 3 test_1 3 tearDown 3 .setUp 3 test_2 3 tearDown 3 .setUp 3 test_3 3 tearDown 3 .Running Master tearDown 3 ---------------------------------------------------------------------- Ran 3 tests in 0.000s OK |
From: Desilets, A. <Ala...@nr...> - 2006-12-19 19:35:07
|
Hi all, I'm trying to write PyUnit tests for an application that is based on = MySQL, and am experiencing some strange problems. Note that I am an = experienced PyUnit developer, but a complete newbie at MySQL. The short code snippet below illustrates the problem I'm having: =3D=3D Start code import MySQLdb import unittest print "-- finished server_init()" class MyTest(unittest.TestCase): def __init__(self, name): unittest.TestCase.__init__(self, name) def test_nevermind(self): self.fail("Nevermind. If I was able to get this far, it's good") arguments =3D \ ['Transana',=20 u'--datadir=3DC:\\Documents and Settings\\Desiletsa\\Application = Data\\Transana 2\\databases\\',=20 '--basedir=3D.',=20 '--language=3D./share/english'] =20 # Tests don't run unless you comment out the next line =20 MySQLdb.server_init(args=3Darguments) suite_to_run =3D unittest.TestSuite() suite_to_run.addTest(unittest.makeSuite(MyTest, 'test'))=20 print "-- running the tests" unittest.TextTestRunner().run(suite_to_run)=20 print "-- finished tests" =3D=3D=3D=3D End code Basically, I would expect this code to result in a a failed test. But = instead, I get the following on STDOUT: -- finished server_init() -- running the tests In other words, the tests never seem to be executed. The funny thing is that if I comment out the call to = MySQLdb.server_init(), and run the code again, I get the expected = output, i.e.: =3D=3D=3D=3D -- finished server_init() -- running the tests F =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D FAIL: test_nevermind (__main__.MyTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "pyUnit_with_MySQL_problem.py", line 11, in test_nevermind self.fail("Nevermind. If I was able to get this far, it's good") AssertionError: Nevermind. If I was able to get this far, it's good ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=3D1) -- finished tests =3D=3D=3D=3D Does anyone have an idea of what is going on here? Thx Alain D=E9silets |
From: Mark G. <mar...@gm...> - 2006-12-14 21:37:33
|
Actually, what you implemented is a comparison method, which you choose to call assert_equal(). In the xUnit world assert (in every modification) is a method that immediately throws exception when asserted condition fails. xUnits are Unit Test tools (not that you are prevented from forcing it into something different:) ). Pure terminology, you'll say? You are right! But important one. Assert stop= s execution on the failure and unrolls return stack to the error processing point. I think this should be kept in mind - in order not to distort this vision created by our peers.No offense. Sorry for late response - was busy grokking new job. On 12/6/06, Desilets, Alain <Ala...@nr...> wrote: > > Actually, I went ahead and implemented a recursive assert_equal() method. > It works pretty well. It basically deals with all the primitive types (in= ts, > floats, strings, etc), all collections (lists, tuples, dicts) and arbitra= ry > objects. > > When a difference is found, it provides helpful messages that help you > drill down from the top to the bottom where the difference was found. > > Alain > > > -----Original Message----- > From: Mark Geyzer [mailto:mar...@gm...] > Sent: Tuesday, December 05, 2006 1:54 AM > To: Desilets, Alain > Cc: pyu...@li... > Subject: Re: [Pyunit-interest] Recursive assert_equals. > > > You may try to convert your dictionaries to strings with "str" or "repr" > function, and then call assert method on resulting strings. This will sav= e > you the hassle of implementing recursive assert, but then - in case of > failure - you'll have top find the guilty field manually. > > If you are not happy with that approach - you'll have to write a method > that parses your dictionaries and checks each value with an assert - yuck= s! > > BTW, if you are not aware - failed assert INTERRUPTS the test, so that if > you have more than field with different values - it will throw exception = on > the first one checked. > > PyUnit is about FrameWork for your tests, that's all; alas, it is not > about checking complicated data structures. > > > Hope, it helps > > On 11/29/06, Desilets, Alain <Ala...@nr...> wrote: > Is there a way to do a recursive assert_equals on a complex data > structure? > > For example, say I want to assert that two dictionary are "equal". The > keys of the dictionary are strings, and the values are objects of type > SomeClass, which, among other things, have an attrigute called > some_attribute which is of type SomeOtherClass. > > I want to write: > > Self.assert_equal_recusrsive(expected_dict, got_dict) > > And have the system do the following: > > - Make sure that expected_dict and got_dict are both of the same type (a > dictionary in this case) > - Make sure that they have the same string keys > - For each string key, make sure that the associated objects are of the > same type (SomeClass), have the same attributes with same values. > - In particular for the some_attribute attribute, it would make sure that > the values are also of the same type (SomeOtherClass), and that they have > the same attribute values pairs. > > Has this been written before? If not would it be doble (it seems to me it > should be). > > I know that in jUnit (Java version), this kind of recursive comparison is > supported to at least some extend. For example, if I compare two dictionn= ary > objects, the system will make sure that the keys are the same and the val= ues > too. But it doesn't go recursively into the attributes of objects AFAIK. > > > ---- > Alain D=E9silets, MASc > Agent de recherches/Research Officer > Institut de technologie de l'information du CNRC / > NRC Institute for Information Technology > > ala...@nr... > T=E9l/Tel (613) 990-2813 > Facsimile/t=E9l=E9copieur: (613) 952-7151 > > Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al, > Ottawa (Ontario) K1A 0R6 > National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON > K1A 0R6 > > Gouvernement du Canada | Government of Canada > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net 's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest > > > > > -- > Mark Geyzer > Software Engineer, > tel: 972-52-6782603 > --=20 Mark Geyzer Software Engineer, tel: 972-52-6782603 |
From: Desilets, A. <Ala...@nr...> - 2006-12-06 14:05:36
|
Actually, I went ahead and implemented a recursive assert_equal() = method. It works pretty well. It basically deals with all the primitive = types (ints, floats, strings, etc), all collections (lists, tuples, = dicts) and arbitrary objects. When a difference is found, it provides helpful messages that help you = drill down from the top to the bottom where the difference was found. Alain -----Original Message----- From: Mark Geyzer [mailto:mar...@gm...]=20 Sent: Tuesday, December 05, 2006 1:54 AM To: Desilets, Alain Cc: pyu...@li... Subject: Re: [Pyunit-interest] Recursive assert_equals. You may try to convert your dictionaries to strings with "str" or "repr" = function, and then call assert method on resulting strings. This will = save you the hassle of implementing recursive assert, but then - in case = of failure - you'll have top find the guilty field manually.=20 If you are not happy with that approach - you'll have to write a method = that parses your dictionaries and checks each value with an assert - = yucks! BTW, if you are not aware - failed assert INTERRUPTS the test, so that = if you have more than field with different values - it will throw = exception on the first one checked.=20 PyUnit is about FrameWork for your tests, that's all; alas, it is not = about checking complicated data structures. Hope, it helps On 11/29/06, Desilets, Alain <Ala...@nr...> wrote: Is there a way to do a recursive assert_equals on a complex data = structure? For example, say I want to assert that two dictionary are "equal". The = keys of the dictionary are strings, and the values are objects of type = SomeClass, which, among other things, have an attrigute called = some_attribute which is of type SomeOtherClass.=20 I want to write: Self.assert_equal_recusrsive(expected_dict, got_dict) And have the system do the following: - Make sure that expected_dict and got_dict are both of the same type (a = dictionary in this case)=20 - Make sure that they have the same string keys - For each string key, make sure that the associated objects are of the = same type (SomeClass), have the same attributes with same values. - In particular for the some_attribute attribute, it would make sure = that the values are also of the same type (SomeOtherClass), and that = they have the same attribute values pairs.=20 Has this been written before? If not would it be doble (it seems to me = it should be). I know that in jUnit (Java version), this kind of recursive comparison = is supported to at least some extend. For example, if I compare two = dictionnary objects, the system will make sure that the keys are the = same and the values too. But it doesn't go recursively into the = attributes of objects AFAIK.=20 ---- Alain D=E9silets, MASc Agent de recherches/Research Officer Institut de technologie de l'information du CNRC / NRC Institute for Information Technology ala...@nr... T=E9l/Tel (613) 990-2813 Facsimile/t=E9l=E9copieur: (613) 952-7151 Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al, Ottawa (Ontario) K1A 0R6 National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON=20 K1A 0R6 Gouvernement du Canada | Government of Canada -------------------------------------------------------------------------= Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net 's Techsay panel and you'll get the chance to share = your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV _______________________________________________ Pyunit-interest mailing list Pyu...@li... https://lists.sourceforge.net/lists/listinfo/pyunit-interest --=20 Mark Geyzer Software Engineer, tel: 972-52-6782603=20 |
From: Ori P. <or...@us...> - 2006-12-06 00:51:06
|
Oops, corrected mailing list address. ---------- Forwarded message ---------- From: Ori Peleg <or...@us...> Date: Dec 6, 2006 2:47 AM Subject: Re: [Pyunit-interest] Recursive assert_equals. To: "Desilets, Alain" <Ala...@nr...> Cc: pyu...@li... Doesn't the equality operator do what you want? http://docs.python.org/ref/comparisons.html As long as your classes implement __eq__ or __cmp__, assertEquals should work fine. (http://docs.python.org/ref/customization.html) On 11/29/06, Desilets, Alain <Ala...@nr...> wrote: > Is there a way to do a recursive assert_equals on a complex data structur= e? > > For example, say I want to assert that two dictionary are "equal". The ke= ys of the dictionary are strings, and the values are objects of type SomeCl= ass, which, among other things, have an attrigute called some_attribute whi= ch is of type SomeOtherClass. > > I want to write: > > Self.assert_equal_recusrsive(expected_dict, got_dict) > > And have the system do the following: > > - Make sure that expected_dict and got_dict are both of the same type (a = dictionary in this case) > - Make sure that they have the same string keys > - For each string key, make sure that the associated objects are of the s= ame type (SomeClass), have the same attributes with same values. > - In particular for the some_attribute attribute, it would make sure that= the values are also of the same type (SomeOtherClass), and that they have = the same attribute values pairs. > > Has this been written before? If not would it be doble (it seems to me it= should be). > > I know that in jUnit (Java version), this kind of recursive comparison is= supported to at least some extend. For example, if I compare two dictionna= ry objects, the system will make sure that the keys are the same and the va= lues too. But it doesn't go recursively into the attributes of objects AFAI= K. > > > ---- > Alain D=E9silets, MASc > Agent de recherches/Research Officer > Institut de technologie de l'information du CNRC / > NRC Institute for Information Technology > > ala...@nr... > T=E9l/Tel (613) 990-2813 > Facsimile/t=E9l=E9copieur: (613) 952-7151 > > Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al, > Ottawa (Ontario) K1A 0R6 > National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON > K1A 0R6 > > Gouvernement du Canada | Government of Canada > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share y= our > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest > |
From: Mark G. <mar...@gm...> - 2006-12-05 06:54:18
|
You may try to convert your dictionaries to strings with "str" or "repr" function, and then call assert method on resulting strings. This will save you the hassle of implementing recursive assert, but then - in case of failure - you'll have top find the guilty field manually. If you are not happy with that approach - you'll have to write a method tha= t parses your dictionaries and checks each value with an assert - yucks! BTW, if you are not aware - failed assert INTERRUPTS the test, so that if you have more than field with different values - it will throw exception on the first one checked. PyUnit is about FrameWork for your tests, that's all; alas, it is not about checking complicated data structures. Hope, it helps On 11/29/06, Desilets, Alain <Ala...@nr...> wrote: > > Is there a way to do a recursive assert_equals on a complex data > structure? > > For example, say I want to assert that two dictionary are "equal". The > keys of the dictionary are strings, and the values are objects of type > SomeClass, which, among other things, have an attrigute called > some_attribute which is of type SomeOtherClass. > > I want to write: > > Self.assert_equal_recusrsive(expected_dict, got_dict) > > And have the system do the following: > > - Make sure that expected_dict and got_dict are both of the same type (a > dictionary in this case) > - Make sure that they have the same string keys > - For each string key, make sure that the associated objects are of the > same type (SomeClass), have the same attributes with same values. > - In particular for the some_attribute attribute, it would make sure that > the values are also of the same type (SomeOtherClass), and that they have > the same attribute values pairs. > > Has this been written before? If not would it be doble (it seems to me it > should be). > > I know that in jUnit (Java version), this kind of recursive comparison is > supported to at least some extend. For example, if I compare two dictionn= ary > objects, the system will make sure that the keys are the same and the val= ues > too. But it doesn't go recursively into the attributes of objects AFAIK. > > > ---- > Alain D=E9silets, MASc > Agent de recherches/Research Officer > Institut de technologie de l'information du CNRC / > NRC Institute for Information Technology > > ala...@nr... > T=E9l/Tel (613) 990-2813 > Facsimile/t=E9l=E9copieur: (613) 952-7151 > > Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al, > Ottawa (Ontario) K1A 0R6 > National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON > K1A 0R6 > > Gouvernement du Canada | Government of Canada > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest > --=20 Mark Geyzer Software Engineer, tel: 972-52-6782603 |
From: Desilets, A. <Ala...@nr...> - 2006-11-29 14:29:35
|
Is there a way to do a recursive assert_equals on a complex data = structure?=20 For example, say I want to assert that two dictionary are "equal". The = keys of the dictionary are strings, and the values are objects of type = SomeClass, which, among other things, have an attrigute called = some_attribute which is of type SomeOtherClass. I want to write: Self.assert_equal_recusrsive(expected_dict, got_dict) And have the system do the following: - Make sure that expected_dict and got_dict are both of the same type (a = dictionary in this case) - Make sure that they have the same string keys - For each string key, make sure that the associated objects are of the = same type (SomeClass), have the same attributes with same values. - In particular for the some_attribute attribute, it would make sure = that the values are also of the same type (SomeOtherClass), and that = they have the same attribute values pairs. Has this been written before? If not would it be doble (it seems to me = it should be). I know that in jUnit (Java version), this kind of recursive comparison = is supported to at least some extend. For example, if I compare two = dictionnary objects, the system will make sure that the keys are the = same and the values too. But it doesn't go recursively into the = attributes of objects AFAIK. ---- Alain D=E9silets, MASc=20 Agent de recherches/Research Officer=20 Institut de technologie de l'information du CNRC /=20 NRC Institute for Information Technology=20 ala...@nr...=20 T=E9l/Tel (613) 990-2813=20 Facsimile/t=E9l=E9copieur: (613) 952-7151=20 Conseil national de recherches Canada, M50, 1200 chemin Montr=E9al,=20 Ottawa (Ontario) K1A 0R6=20 National Research Council Canada, M50, 1200 Montreal Rd., Ottawa, ON=20 K1A 0R6=20 Gouvernement du Canada | Government of Canada=20 =20 |
From: Ori P. <or...@us...> - 2006-09-19 17:41:42
|
'--threads' with Testoob does that with unittest suites. http://testoob.sourceforge.net Jhon Honce wrote: > Has anyone updated this for the latest unittest? If I get it running, > I=92ll post. I=92m new to python and unittest so any help/ideas would b= e > appreciated. >=20 > --Jhon Honce >=20 >=20 > class ParallelTestSuite(unittest.TestSuite): > """Runs its tests in parallel threads""" > def __call__(self, testResult): > from threading import Thread > threads =3D [] > for test in self._tests: > result =3D test.defaultTestResult() > thread =3D Thread(target=3Dtest, args=3D(result,)) > threads.append((test, thread, result)) > thread.start() > for test, thread, result in threads: > thread.join() > testResult.startTest(test) > for error in result.errors: > apply(testResult.addError, error) > for failure in result.failures: > apply(testResult.addFailure, failure) > testResult.stopTest(test) >=20 >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=3Dk&kid=103432&bid#0486&dat=121642 > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest >=20 |
From: Steve P. <pu...@us...> - 2006-05-29 12:34:37
|
Hi Peter, The function 'unittest.main()' is the top-level function that turns a python file into a standalone runnable test program. It uses sys.exit () to indicate whether the tests passed or not. What you see here is the result of running that function inside an interactive interpreter, which is intercepting the 'SystemExit' that is thrown by sys.exit(). If you don't care about the exit code, you can just wrap 'unittest.main()' in a try: except SystemExit: block. Hope that helps, -Steve On 29 May 2006, at 00:04, Peter Olsen wrote: > I am completely befuddled. > > > I run this program > > ---------- > > def matrixSize(matrix): > return (len(matrix),len(matrix[0])) > > if __name__ == "__main__": > > import unittest > > print "Unit test code." > > # class MatrixUtilsTest(unittest.TestCase): > # def setUp(self): > # self.a=[[1,2],[3,4]] > # self.b = [[2,4],[6,8]] > # self.c = [[3,6],[9,12]] > # self.d = [[2,8],[18,32]] > # print self.a > > class MatrixSizeTest(unittest.TestCase): > def runTest(self): > self.a = [[1,2],[3,4]] > self.assertEqual(matrixSize(self.a),(2,2)) > > > # class MatrixSumTest(MatrixUtilsTest): > # def testSum(self): > # self.failUnless(matrixSum(self.a, self.b) == [[3,6], > [9,12]], > # "sum incorrect") > > > t = MatrixSizeTest() > print t > unittest.main() > > ---------- > > and get this result > > ---------- > > >>> ================================ RESTART > ================================ > >>> > Unit test code. > runTest (__main__.MatrixSizeTest) > . > ---------------------------------------------------------------------- > Ran 1 test in 0.024s > > OK > > Traceback (most recent call last): > File "/Users/pcolsen/D.Sources/Nash_Compact_Numerical_Methods/ > testTest.py", line 32, in -toplevel- > unittest.main() > File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ > python2.4/unittest.py", line 759, in __init__ > self.runTests() > File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ > python2.4/unittest.py", line 797, in runTests > sys.exit(not result.wasSuccessful()) > SystemExit: False > >>> > > ---------- > > I'm using MacPython 2.4 running on OS-X > > System Version: Mac OS X 10.4.6 (8I127) > Kernel Version: Darwin 8.6.0 > > > > > > ------------------------------------------------------- > All the advantages of Linux Managed Hosting--Without the Cost and > Risk! > Fully trained technicians. The highest number of Red Hat > certifications in > the hosting industry. Fanatical Support. Click to learn more > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=107521&bid=248729&dat=121642 > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest |
From: Peter O. <pc...@co...> - 2006-05-28 22:04:18
|
I am completely befuddled. I run this program ---------- def matrixSize(matrix): return (len(matrix),len(matrix[0])) if __name__ == "__main__": import unittest print "Unit test code." # class MatrixUtilsTest(unittest.TestCase): # def setUp(self): # self.a=[[1,2],[3,4]] # self.b = [[2,4],[6,8]] # self.c = [[3,6],[9,12]] # self.d = [[2,8],[18,32]] # print self.a class MatrixSizeTest(unittest.TestCase): def runTest(self): self.a = [[1,2],[3,4]] self.assertEqual(matrixSize(self.a),(2,2)) # class MatrixSumTest(MatrixUtilsTest): # def testSum(self): # self.failUnless(matrixSum(self.a, self.b) == [[3,6], [9,12]], # "sum incorrect") t = MatrixSizeTest() print t unittest.main() ---------- and get this result ---------- >>> ================================ RESTART ================================ >>> Unit test code. runTest (__main__.MatrixSizeTest) . ---------------------------------------------------------------------- Ran 1 test in 0.024s OK Traceback (most recent call last): File "/Users/pcolsen/D.Sources/Nash_Compact_Numerical_Methods/ testTest.py", line 32, in -toplevel- unittest.main() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/unittest.py", line 759, in __init__ self.runTests() File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ python2.4/unittest.py", line 797, in runTests sys.exit(not result.wasSuccessful()) SystemExit: False >>> ---------- I'm using MacPython 2.4 running on OS-X System Version: Mac OS X 10.4.6 (8I127) Kernel Version: Darwin 8.6.0 |
From: Jhon H. <ho...@ma...> - 2006-01-20 23:28:01
|
Has anyone updated this for the latest unittest? If I get it running, =20= I=92ll post. I=92m new to python and unittest so any help/ideas would be = =20 appreciated. --Jhon Honce class ParallelTestSuite(unittest.TestSuite): """Runs its tests in parallel threads""" def __call__(self, testResult): from threading import Thread threads =3D [] for test in self._tests: result =3D test.defaultTestResult() thread =3D Thread(target=3Dtest, args=3D(result,)) threads.append((test, thread, result)) thread.start() for test, thread, result in threads: thread.join() testResult.startTest(test) for error in result.errors: apply(testResult.addError, error) for failure in result.failures: apply(testResult.addFailure, failure) testResult.stopTest(test) |
From: Honce, J. W <jho...@in...> - 2006-01-20 22:32:28
|
Has anyone updated this for the latest unittest? If I get it running, I'll post. I'm new to python and unittest so any help/ideas would be appreciated.=20 =20 --Jhon Honce =20 =20 class ParallelTestSuite(unittest.TestSuite): """Runs its tests in parallel threads""" def __call__(self, testResult): from threading import Thread threads =3D [] for test in self._tests: result =3D test.defaultTestResult() thread =3D Thread(target=3Dtest, args=3D(result,)) threads.append((test, thread, result)) thread.start() for test, thread, result in threads: thread.join() testResult.startTest(test) for error in result.errors: apply(testResult.addError, error) for failure in result.failures: apply(testResult.addFailure, failure) testResult.stopTest(test) |
From: Tim B. <tb...@bi...> - 2005-08-11 17:33:06
|
I desire a better graphical test runner (than the tkinter unittestgui.py) to run my unit test cases, which are implemented using the standard unittest module. I have searched Google and all the seemingly-relevant newsgroups, and the only reference I found is 5 years old. Before I reinvent the wheel, I thought I'd post a new request, as wxPython is my preferred gui framework. Also, I have had problems with the Tkinter version never updating during test running and would like better features such as automatic test searching and grouping, generating results reports, etc. =20 Thanks, Tim Black Biamp Systems (503)641-7287 ext.153 =20 |
From: Magnus L. H. <ma...@he...> - 2005-03-14 10:15:20
|
Hi! I've been using the default test loader, writing several tests in the same TestCase (using the method naming convention method). This seems fine for hard-coded tests, but I keep running into the need to auto-generate tests, by trying out various combinations of parameters, for example (i.e., having a few loops in my test method). The problem is that I'd like to run each case (i.e., combination of parameters) with the same fixture. In other words, I'd like to have a separate test (with a separate run of setUp/tearDown) for each case -- but without having to write separate test methods for each of them. I guess I could have separate code for creating individual TestCase objects separately and add them to a common suite etc. -- but using the standard unittest.main() method is quite convenient... :] What is the "best practice" for automatically generated tests in PyUnit? -- Magnus Lie Hetland Time flies like the wind. Fruit flies http://hetland.org like bananas. -- Groucho Marx |
From: Steve P. <ste...@ya...> - 2004-09-09 08:17:41
|
Hi Jim, unittest.main() is designed to turn a test module into an executable test script, it explicitly calls 'sys.exit()' to indicate success or otherwise. You are running the entire script from within the interpreter, and the interpreter is reporting to you that sys.exit() has been called, which works by raising SystemExit. In other words, it's nothing to worry about, but it is a nuisance when pushing an entire test script through the interpreter, as happens when executing a script in emacs' python mode. One way to avoid having the traceback printed out is to replace unittest.main() with try: unittest.main() except SystemExit: pass Best wishes, -Steve -- http://www.pythonconsulting.com/ On Wednesday 08 September 2004 19:42, Frohnhofer, James wrote: > Is it expected behavior that the text-based test runner print a stack > traceback upon completion? For example (from the pyunit documentation): > > import unittest > > class IntegerArithmenticTestCase(unittest.TestCase): > def testAdd(self): ## test method names begin 'test*' > self.assertEquals((1 + 2), 3) > self.assertEquals(0 + 1, 1) > def testMultiply(self): > self.assertEquals((0 * 10), 0) > self.assertEquals((5 * 8), 40) > > if __name__ == '__main__': > unittest.main() > > > When run as a script returns: > > > .. > ---------------------------------------------------------------------- > Ran 2 tests in 0.015s > > OK > Traceback (most recent call last): > File "H:/Python23/Lib/testest.py", line 12, in ? > unittest.main() > File "H:\Python23\lib\unittest.py", line 721, in __init__ > self.runTests() > File "H:\Python23\lib\unittest.py", line 759, in runTests > sys.exit(not result.wasSuccessful()) > SystemExit: False > > > > While I can see the OK and the two dots (..) for success, I would expect > success not to be followed by a stack trace. Am I doing something wrong > or am I being a moron -- a real possibility. I am familiar with xUnit, > but fairly new to Python. > > Thanks, > > Jim > > ========================================================================= >===== This message is for the sole use of the intended recipient. If you > received this message in error please delete it and notify us. If this > message was misdirected, CSFB does not waive any confidentiality or > privilege. CSFB retains and monitors electronic communications sent > through its network. Instructions transmitted over this system are not > binding on CSFB until they are confirmed by us. Message transmission is > not guaranteed to be secure. > ========================================================================= >===== > > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest |
From: Frohnhofer, J. <jam...@cs...> - 2004-09-08 18:42:53
|
Is it expected behavior that the text-based test runner print a stack traceback upon completion? For example (from the pyunit documentation): import unittest class IntegerArithmenticTestCase(unittest.TestCase): def testAdd(self): ## test method names begin 'test*' self.assertEquals((1 + 2), 3) self.assertEquals(0 + 1, 1) def testMultiply(self): self.assertEquals((0 * 10), 0) self.assertEquals((5 * 8), 40) if __name__ == '__main__': unittest.main() When run as a script returns: >>> .. ---------------------------------------------------------------------- Ran 2 tests in 0.015s OK Traceback (most recent call last): File "H:/Python23/Lib/testest.py", line 12, in ? unittest.main() File "H:\Python23\lib\unittest.py", line 721, in __init__ self.runTests() File "H:\Python23\lib\unittest.py", line 759, in runTests sys.exit(not result.wasSuccessful()) SystemExit: False >>> While I can see the OK and the two dots (..) for success, I would expect success not to be followed by a stack trace. Am I doing something wrong or am I being a moron -- a real possibility. I am familiar with xUnit, but fairly new to Python. Thanks, Jim ============================================================================== This message is for the sole use of the intended recipient. If you received this message in error please delete it and notify us. If this message was misdirected, CSFB does not waive any confidentiality or privilege. CSFB retains and monitors electronic communications sent through its network. Instructions transmitted over this system are not binding on CSFB until they are confirmed by us. Message transmission is not guaranteed to be secure. ============================================================================== |
From: Diener, E. <Edw...@lo...> - 2004-08-20 15:23:01
|
There is hardly any documentation on the TestRunner class in the Python 2.3 docs. What are its member functions and attributes ? How does one replace the TextTestRunner used by unittest with another one ? |
From: Steve P. <ste...@ya...> - 2004-08-15 17:45:55
|
On Saturday 14 August 2004 21:26, Antoine Brenner wrote: > Hi ! > > Is there a (or more exactely what is the) way to run some kind of super > tearDown only after an error or a failure of a test ? > > I still need the regular tearDown after each test, but failed ones need > a special cleanup that is slow and unnecessary when tests run OK. Hi Antoine, This is not directly supported, but you can get the effect you want by wrapping test methods in an object that calls a clean-up method for you, as shown below. It's a bit hacky, and maybe in future it would be a good idea to add 'onFail()' hook methods to TestCase. Opinions, anyone? Best wishes, -Steve --------- import unittest class AddExceptionHook: def __init__(self, method, hook_method): self.method, self.hook_method = method, hook_method def __call__(self): try: return self.method() except: self.hook_method() raise class MyTestCase(unittest.TestCase): def tearDown(self): print "normal tearDown" def test_that_may_fail(self): raise Exception("deliberate failure") ## Additional tear-down hook def on_fail(): print "Tearing down because we failed" classmethod(on_fail) ## Add clean-up hooks to relevant methods test_that_may_fail = AddExceptionHook(test_that_may_fail, on_fail) if __name__ == '__main__': unittest.main() -- Steve Purcell http://www.pythonconsulting.com |
From: Antoine B. <pyt...@sp...> - 2004-08-14 20:26:41
|
Hi ! Is there a (or more exactely what is the) way to run some kind of super tearDown only after an error or a failure of a test ? I still need the regular tearDown after each test, but failed ones need a special cleanup that is slow and unnecessary when tests run OK. Best regards, Antoine Brenner |
From: Jim F. <ji...@zo...> - 2004-08-06 15:58:01
|
TestSuite objects provide no public mechanism for iteration. We have a need to be able to iterate over them. Up to now, we've been using the _tests attribute, which is bad. If no one objects, I'll add an __iter__ method. (I'll do this in the Python CVS repository.) Jim -- Jim Fulton mailto:ji...@zo... Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org |