summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unittest.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-01-03 02:21:52 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2008-01-03 02:21:52 (GMT)
commit2f3c16be73a8562d357b9b13bbb8088e275840a7 (patch)
tree5334d4bd6c8b6456da10c0be232fb8bf95b1aca7 /Lib/test/test_unittest.py
parent27edd829d7673a642cf5b37c3011454ec33cb715 (diff)
downloadcpython-2f3c16be73a8562d357b9b13bbb8088e275840a7.zip
cpython-2f3c16be73a8562d357b9b13bbb8088e275840a7.tar.gz
cpython-2f3c16be73a8562d357b9b13bbb8088e275840a7.tar.bz2
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689.
Diffstat (limited to 'Lib/test/test_unittest.py')
-rw-r--r--Lib/test/test_unittest.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index 9dfed7b..5a82780 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -2264,13 +2264,34 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
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()