From 4aad0dce38461ebe44b0ee90d10e49eacc2a11de Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 30 Oct 2007 10:46:16 +0100 Subject: [PATCH] added simple unittest tests as examples --- tests/python/unittest_examples.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/python/unittest_examples.py diff --git a/tests/python/unittest_examples.py b/tests/python/unittest_examples.py new file mode 100644 index 00000000..740c7312 --- /dev/null +++ b/tests/python/unittest_examples.py @@ -0,0 +1,31 @@ +import unittest + +# this file is just to illustrates and test some of the unittest module +# functionalities. + +class raise_test_case(unittest.TestCase): + def test_assertEqual(self): + """ check assertEqual returns AssertionError """ + try: + self.assertEqual(0.,1.) + except AssertionError: + pass + else: + fail('expected an AssertionError exception') + + def test_assertAlmostEqual(self): + """ check assertAlmostEqual returns AssertionError """ + try: + self.assertAlmostEqual(0.,1.) + except AssertionError: + pass + else: + fail('expected an AssertionError exception') + + def test_assertRaises(self): + """ check assertRaises works as expected """ + self.assertRaises(AssertionError, self.assertEqual, 0.,1.) + self.assertRaises(AssertionError, self.assertAlmostEqual, 0.,1.,1) + +if __name__ == '__main__': + unittest.main() -- 2.26.2