| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2292,13 +2292,34 @@ def defaultTestResult(self): | |||
| 2292 | 2292 | expected = ['startTest', 'test', 'stopTest'] | |
| 2293 | 2293 | self.assertEqual(events, expected) | |
| 2294 | 2294 | ||
| 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 | + | ||
| 2295 | 2315 | ###################################################################### | |
| 2296 | 2316 | ## Main | |
| 2297 | 2317 | ###################################################################### | |
| 2298 | 2318 | ||
| 2299 | 2319 | def test_main(): | |
| 2300 | 2320 | 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) | ||
| 2302 | 2323 | ||
| 2303 | 2324 | if __name__ == "__main__": | |
| 2304 | 2325 | test_main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -331,7 +331,7 @@ def failIfEqual(self, first, second, msg=None): | |||
| 331 | 331 | if first == second: | |
| 332 | 332 | raise self.failureException(msg or '%r == %r' % (first, second)) | |
| 333 | 333 | ||
| 334 | - def failUnlessAlmostEqual(self, first, second, places=7, msg=None): | ||
| 334 | + def failUnlessAlmostEqual(self, first, second, *, places=7, msg=None): | ||
| 335 | 335 | """Fail if the two objects are unequal as determined by their | |
| 336 | 336 | difference rounded to the given number of decimal places | |
| 337 | 337 | (default 7) and comparing to zero. | |
@@ -343,7 +343,7 @@ def failUnlessAlmostEqual(self, first, second, places=7, msg=None): | |||
| 343 | 343 | raise self.failureException(msg or '%r != %r within %r places' | |
| 344 | 344 | % (first, second, places)) | |
| 345 | 345 | ||
| 346 | - def failIfAlmostEqual(self, first, second, places=7, msg=None): | ||
| 346 | + def failIfAlmostEqual(self, first, second, *, places=7, msg=None): | ||
| 347 | 347 | """Fail if the two objects are equal as determined by their | |
| 348 | 348 | difference rounded to the given number of decimal places | |
| 349 | 349 | (default 7) and comparing to zero. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments