Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion ten small Python programs

View parsed - Show only message text

Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 27 May 2007 13:39:29 -0500
Date: Sun, 27 May 2007 12:39:27 -0600
From: Steven Bethard <steven.beth...@gmail.com>
User-Agent: Thunderbird 2.0.0.0 (Windows/20070326)
MIME-Version: 1.0
Newsgroups: comp.lang.python
Subject: Re: ten small Python programs
References: <mailman.8269.1180289458.32031.python-list@python.org>
In-Reply-To: <mailman.8269.1180289458.32031.python-list@python.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <VcCdnUfV8Yj8TcTbnZ2dnUVZ_h7inZ2d@comcast.com>
Lines: 34
NNTP-Posting-Host: 67.166.43.236
X-Trace: sv3-ZbcZGMOknrW+eRLgtyeKXkw89TSrQBRZTKhllLeZLf88ejmcTXLr5o+2FcLFlEsQfXeLbVAeydyEJ15!vmZKDRmZY/bUe2fNSLP2RiMZ8L7sxiWCOKm2wH+jcATCyxg+zMAcivGTxjLxhQpH+51PJEFg1hsZ!MDl8G6QzjLNgjk+1CLcAlp0TKCLurA==
X-Complaints-To: abuse@comcast.net
X-DMCA-Complaints-To: d...@comcast.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.34

Steve Howell wrote:
> --- Steven Bethard <steven.beth...@gmail.com> wrote:
>> I think I would rewrite the current unit-testing
>> example to use the 
>> standard library unittest module::
>>
>>      # Let's write reusable code, and unit test 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):
>>              self.failUnlessEqual(add_money([0.13,
>> 0.02]), 0.15)
>>              self.failUnlessEqual(add_money([100.01,
>> 99.99]), 200)
>>              self.failUnlessEqual(add_money([0,
>> -13.00, 13.00]), 0)
>>      if __name__ == '__main__':
>>          unittest.main()
>>
> 
> Just a minor quibble, but wouldn't you want the import
> and test class to only get executed in the ___main__
> context?

That would be fine too. In the real world, I'd put the tests in a 
different module.

STeVe

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google