Re: unittests with different parameters

2010-11-24 Thread Jack Keegan
Apologies if this is a bit off the wall but I've only just started getting into unit testing (in Python) this morning. Would generators help you in any way? You might be able to have a generator which would yield an attribute set combination each time it is called. I'm not sure if it would still st

Re: unittests with different parameters

2010-11-24 Thread Ulrich Eckhardt
Short update on what I've settled for generating test functions for various input data: # test case with common test function class MyTest(unittest.TestCase): def _test_invert_flags(self, input, flags, expected):       res = do_invert(input, flags)       self.assertEqual(res, expected) #

Re: unittests with different parameters

2010-11-23 Thread Jonathan Hartley
On Nov 22, 11:38 am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I

Re: unittests with different parameters

2010-11-22 Thread Ben Finney
Ulrich Eckhardt writes: > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I have in the test case is > something like this: > > def test_invert_flags(self): > """test flags to invert coordinates""" > tests

Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Ian Kelly wrote: > On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: >> Also, I'd rather construct the error message from the data >> instead of maintaining it in different places, because >> manually keeping those in sync is another, errorprone burden. > > I'm not sure I follow the problem you're de

Re: unittests with different parameters

2010-11-22 Thread Ian Kelly
On 11/22/2010 4:38 AM, Ulrich Eckhardt wrote: Let's say I have two flags invert X and invert Y. Now, for testing these, I would write one test for each combination. What I have in the test case is something like this: def test_invert_flags(self): """test flags to invert coordinates"""

Re: unittests with different parameters

2010-11-22 Thread Roy Smith
In article , Ulrich Eckhardt wrote: > > Yet another possibility is to leave it the way you originally wrote it > > and not worry about the fact that the loop aborts on the first failure. > > Let it fail, fix it, then re-run the test to find the next failure. > > Perhaps not as efficient as findi

Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Richard Thomas wrote: [batch-programming different unit tests] > You could have a parameter to the test method and some custom > TestLoader that knows what to do with it. Interesting, thanks for this suggestion, I'll look into it! Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amt

Re: unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Roy Smith wrote: > Writing one test method per parameter combination, as you suggested, is > a reasonable approach, especially if the number of combinations is > reasonably small. The number of parameters and thus combinations are unfortunately rather large. Also, sometimes that data is not static

Re: unittests with different parameters

2010-11-22 Thread Roy Smith
In article , Ulrich Eckhardt wrote: > def test_invert_flags(self): > """test flags to invert coordinates""" > tests = [((10, 20), INVERT_NONE, (10, 20)), >((10, 20), INVERT_X, (-10, 20)), >((10, 20), INVERT_Y, (10, -20))] > for input, flags, ex

Re: unittests with different parameters

2010-11-22 Thread Richard Thomas
On Nov 22, 11:38 am, Ulrich Eckhardt wrote: > Hi! > > I'm writing tests and I'm wondering how to achieve a few things most > elegantly with Python's unittest module. > > Let's say I have two flags invert X and invert Y. Now, for testing these, I > would write one test for each combination. What I

unittests with different parameters

2010-11-22 Thread Ulrich Eckhardt
Hi! I'm writing tests and I'm wondering how to achieve a few things most elegantly with Python's unittest module. Let's say I have two flags invert X and invert Y. Now, for testing these, I would write one test for each combination. What I have in the test case is something like this: def test