Re: [Pyunit-interest] improved alltests.py example
Brought to you by:
purcell
From: Luciano R. <lg...@uo...> - 2002-12-17 19:08:38
|
In Python, the parenthesis are used to denote tuples, which are=20 immutable lists. But because they are also used in expressions, there=20 is a quirk: if your tuple has only one element, Python can't tell the=20 difference from an expression. To let Python know what you mean, you=20 need to add a comma inside the parenthesis, like this: > modules_to_test =3D ('widgettests', ) So, ('x') is a string expression equal to 'x'. But ('x',) is a tuple with containing one element, which happens to be=20= a string. Regards, Luciano On ter=E7a-feira, dezembro 17, 2002, at 04:09 PM, Jean Czerlinski wrote: > I am writing to suggest a minor-- but important-- > improvement in the file alltests.py file in the > examples folder. > > The modules_to_test should be a true list with square > brackets. As it is, if you have just one module, the > map function following it will iterate over the > letters in the string that is the module name rather > than seeing it as a list with one string element. For > example, > > modules_to_test =3D ('widgettests') > map(__import__, modules_to_test) > > results in the error > > ImportError: No module named w > > The original code and my suggested change are shown > below. > > By the way, is my terminology correct? What do you > call it with the curved brackets? > > Thanks, > > Jean > > ------------------------------------------------ > original code for alltests.py > > import unittest > > def suite(): > modules_to_test =3D ('listtests', 'widgettests') # > and so on > alltests =3D unittest.TestSuite() > for module in map(__import__, modules_to_test): > > alltests.addTest(unittest.findTestCases(module)) > return alltests > > if __name__ =3D=3D '__main__': > unittest.main(defaultTest=3D'suite') > > ------------------------------------------------ > improved code for alltests.py > > import unittest > > def suite(): > modules_to_test =3D ['listtests', 'widgettests'] # > and so on <=3D=3D=3D change is here: square brackets > instead of rounded > alltests =3D unittest.TestSuite() > for module in map(__import__, modules_to_test): > > alltests.addTest(unittest.findTestCases(module)) > return alltests > > if __name__ =3D=3D '__main__': > unittest.main(defaultTest=3D'suite') > > __________________________________________________ > Do you Yahoo!? > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. > http://mailplus.yahoo.com > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest > |