| |
comp.lang.python |
--- Steven Bethard <steven.beth...@gmail.com> wrote: > >> # Let's write reusable code, and unit test > self.failUnlessEqual(add_money([0.13, > self.failUnlessEqual(add_money([100.01, > > Just a minor quibble, but wouldn't you want the > That would be fine too. In the real world, I'd put I am in 100% agreement with you that most unit tests ___________________________________________________________________________ _________Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
> > --- Steven Bethard <steven.beth...@gmail.com>
> wrote:
> >> I think I would rewrite the current unit-testing
> >> example to use the
> >> standard library unittest module::
> it.
> >> def add_money(amounts):
> >> # do arithmetic in pennies so as not to
> >> accumulate float errors
> >> pennies = sum([round(int(amount * 100))
> for
> >> amount in amounts])
> >> return float(pennies / 100.0)
> >> import unittest
> >> class TestAddMoney(unittest.TestCase):
> >> def test_float_errors(self):
> >> 0.02]), 0.15)
> >> 99.99]), 200)
> >> self.failUnlessEqual(add_money([0,
> >> -13.00, 13.00]), 0)
> >> if __name__ == '__main__':
> >> unittest.main()
> import
> > and test class to only get executed in the
> ___main__
> > context?
> the tests in a
> different module.
hyperlink to alternatives. Would you accept the idea
that we keep my original example on the SimplePrograms
page, but we link to a UnitTestingPhilosophies page,
and we show your alternative there? Or vice versa,
show your example on the first page, but then show
mine on the hyperlinked page?
would be completely outside the module, although I
often follow the practice that my modules have a
little "if __main__" section that runs a few simple
unit tests, as sort of a bit of self-documentation.
http://smallbusiness.yahoo.com/webhosting