This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maubp
Recipients maubp
Date 2010-11-08.11:03:39
SpamBayes Score 1.5543122e-15
Marked as misclassified No
Message-id <1289214223.54.0.6247578407.issue10353@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following example unit test using assertAlmostEqual which uses the places argument as a positional argument, call this places.py:

import unittest
class Tests(unittest.TestCase):
    def test_equal_to_five_decimal_places(self):
        """Check assertAlmostEqual using decimal places"""
        self.assertAlmostEqual(0.123456789, 0.123456, 5)
if __name__ == "__main__":
    runner = unittest.TextTestRunner(verbosity = 2)
    unittest.main(testRunner=runner)



This works fine with Python 2.6.6 (Linux),

$ python2.6 places.py
Check assertAlmostEqual using decimal places ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK




Trying 2to3 on it reports no changes needed:

$ 2to3 places.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: No changes to places.py
RefactoringTool: Files that need to be modified:
RefactoringTool: places.py


Trying the test as is under Python 3.1.2 (Linux) fails:

$ python3.1 places.py
test_equal_to_five_decimal_places (__main__.Tests)
Check assertAlmostEqual using decimal places ... ERROR

======================================================================
ERROR: test_equal_to_five_decimal_places (__main__.Tests)
Check assertAlmostEqual using decimal places
----------------------------------------------------------------------
Traceback (most recent call last):
  File "places.py", line 5, in test_equal_to_five_decimal_places
    self.assertAlmostEqual(0.123456789, 0.123456, 5)
TypeError: assertAlmostEqual() takes exactly 3 positional arguments (4 given)

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)


The test can be fixed to run on Python 3.1 (any Python 2.6) by supplying the places argument by name:


import unittest
class Tests(unittest.TestCase):
    def test_equal_to_five_decimal_places(self):
        """Check assertAlmostEqual using decimal places"""
        self.assertAlmostEqual(0.123456789, 0.123456, places=5)
if __name__ == "__main__":
    runner = unittest.TextTestRunner(verbosity = 2)
    unittest.main(testRunner=runner)


Note http://docs.python.org/library/unittest.html does not explicitly discuss passing places by name vs position. On the other hand, http://docs.python.org/py3k/library/unittest.html explicitly shows the by name form only.

I think the 2to3 script needs to be extended to use the places argument by name.
History
Date User Action Args
2010-11-08 11:03:43maubpsetrecipients: + maubp
2010-11-08 11:03:43maubpsetmessageid: <1289214223.54.0.6247578407.issue10353@psf.upfronthosting.co.za>
2010-11-08 11:03:41maubplinkissue10353 messages
2010-11-08 11:03:39maubpcreate