FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add a test for fail*AlmostEqual, including the new support for comple… · python/cpython@aaaef11 · GitHub

Repository navigation

Commit aaaef11

Browse files
committed
Add a test for fail*AlmostEqual, including the new support for complex numbers.
1 parent 96593ed commit aaaef11

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎Lib/test/test_unittest.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,13 +2292,34 @@ def defaultTestResult(self):
22922292
expected = ['startTest', 'test', 'stopTest']
22932293
self.assertEqual(events, expected)
22942294

2295+
class Test_Assertions(TestCase):
2296+
def test_AlmostEqual(self):
2297+
self.failUnlessAlmostEqual(1.00000001, 1.0)
2298+
self.failIfAlmostEqual(1.0000001, 1.0)
2299+
self.assertRaises(AssertionError,
2300+
self.failUnlessAlmostEqual, 1.0000001, 1.0)
2301+
self.assertRaises(AssertionError,
2302+
self.failIfAlmostEqual, 1.00000001, 1.0)
2303+
2304+
self.failUnlessAlmostEqual(1.1, 1.0, places=0)
2305+
self.assertRaises(AssertionError,
2306+
self.failUnlessAlmostEqual, 1.1, 1.0, places=1)
2307+
2308+
self.failUnlessAlmostEqual(0, .1+.1j, places=0)
2309+
self.failIfAlmostEqual(0, .1+.1j, places=1)
2310+
self.assertRaises(AssertionError,
2311+
self.failUnlessAlmostEqual, 0, .1+.1j, places=1)
2312+
self.assertRaises(AssertionError,
2313+
self.failIfAlmostEqual, 0, .1+.1j, places=0)
2314+
22952315
######################################################################
22962316
## Main
22972317
######################################################################
22982318

22992319
def test_main():
23002320
test_support.run_unittest(Test_TestCase, Test_TestLoader,
2301-
Test_TestSuite, Test_TestResult, Test_FunctionTestCase)
2321+
Test_TestSuite, Test_TestResult, Test_FunctionTestCase,
2322+
Test_Assertions)
23022323

23032324
if __name__ == "__main__":
23042325
test_main()

‎Lib/unittest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def failIfEqual(self, first, second, msg=None):
331331
if first == second:
332332
raise self.failureException(msg or '%r == %r' % (first, second))
333333

334-
def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
334+
def failUnlessAlmostEqual(self, first, second, *, places=7, msg=None):
335335
"""Fail if the two objects are unequal as determined by their
336336
difference rounded to the given number of decimal places
337337
(default 7) and comparing to zero.
@@ -343,7 +343,7 @@ def failUnlessAlmostEqual(self, first, second, places=7, msg=None):
343343
raise self.failureException(msg or '%r != %r within %r places'
344344
% (first, second, places))
345345

346-
def failIfAlmostEqual(self, first, second, places=7, msg=None):
346+
def failIfAlmostEqual(self, first, second, *, places=7, msg=None):
347347
"""Fail if the two objects are equal as determined by their
348348
difference rounded to the given number of decimal places
349349
(default 7) and comparing to zero.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL