Author: jeffrey.yasskin
Date: Fri Sep 7 17:00:39 2007
New Revision: 58039
Modified:
python/branches/py3k/Lib/test/test_unittest.py
python/branches/py3k/Lib/unittest.py
Log:
Add a test for fail*AlmostEqual, including the new support for complex numbers.
Modified: python/branches/py3k/Lib/test/test_unittest.py
==============================================================================
--- python/branches/py3k/Lib/test/test_unittest.py (original)
+++ python/branches/py3k/Lib/test/test_unittest.py Fri Sep 7 17:00:39 2007
@@ -2292,13 +2292,34 @@
expected = ['startTest', 'test', 'stopTest']
self.assertEqual(events, expected)
+class Test_Assertions(TestCase):
+ def test_AlmostEqual(self):
+ self.failUnlessAlmostEqual(1.00000001, 1.0)
+ self.failIfAlmostEqual(1.0000001, 1.0)
+ self.assertRaises(AssertionError,
+ self.failUnlessAlmostEqual, 1.0000001, 1.0)
+ self.assertRaises(AssertionError,
+ self.failIfAlmostEqual, 1.00000001, 1.0)
+
+ self.failUnlessAlmostEqual(1.1, 1.0, places=0)
+ self.assertRaises(AssertionError,
+ self.failUnlessAlmostEqual, 1.1, 1.0, places=1)
+
+ self.failUnlessAlmostEqual(0, .1+.1j, places=0)
+ self.failIfAlmostEqual(0, .1+.1j, places=1)
+ self.assertRaises(AssertionError,
+ self.failUnlessAlmostEqual, 0, .1+.1j, places=1)
+ self.assertRaises(AssertionError,
+ self.failIfAlmostEqual, 0, .1+.1j, places=0)
+
######################################################################
## Main
######################################################################
def test_main():
test_support.run_unittest(Test_TestCase, Test_TestLoader,
- Test_TestSuite, Test_TestResult, Test_FunctionTestCase)
+ Test_TestSuite, Test_TestResult, Test_FunctionTestCase,
+ Test_Assertions)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k/Lib/unittest.py
==============================================================================
--- python/branches/py3k/Lib/unittest.py (original)
+++ python/branches/py3k/Lib/unittest.py Fri Sep 7 17:00:39 2007
@@ -331,7 +331,7 @@
if first == second:
raise self.failureException(msg or '%r == %r' % (first, second))
- def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
+ def failUnlessAlmostEqual(self, first, second, *, places=7, msg=None):
"""Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
@@ -343,7 +343,7 @@
raise self.failureException(msg or '%r != %r within %r places'
% (first, second, places))
- def failIfAlmostEqual(self, first, second, places=7, msg=None):
+ def failIfAlmostEqual(self, first, second, *, places=7, msg=None):
"""Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero.
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins