Back to index

python3.2  3.2.2
Public Member Functions
unittest.test.test_assertions.Test_Assertions Class Reference

List of all members.

Public Member Functions

def test_AlmostEqual
def test_AmostEqualWithDelta
def test_assertRaises
def testAssertNotRegex

Detailed Description

Definition at line 6 of file test_assertions.py.


Member Function Documentation

Definition at line 7 of file test_assertions.py.

00007 
00008     def test_AlmostEqual(self):
00009         self.assertAlmostEqual(1.00000001, 1.0)
00010         self.assertNotAlmostEqual(1.0000001, 1.0)
00011         self.assertRaises(self.failureException,
00012                           self.assertAlmostEqual, 1.0000001, 1.0)
00013         self.assertRaises(self.failureException,
00014                           self.assertNotAlmostEqual, 1.00000001, 1.0)
00015 
00016         self.assertAlmostEqual(1.1, 1.0, places=0)
00017         self.assertRaises(self.failureException,
00018                           self.assertAlmostEqual, 1.1, 1.0, places=1)
00019 
00020         self.assertAlmostEqual(0, .1+.1j, places=0)
00021         self.assertNotAlmostEqual(0, .1+.1j, places=1)
00022         self.assertRaises(self.failureException,
00023                           self.assertAlmostEqual, 0, .1+.1j, places=1)
00024         self.assertRaises(self.failureException,
00025                           self.assertNotAlmostEqual, 0, .1+.1j, places=0)
00026 
00027         self.assertAlmostEqual(float('inf'), float('inf'))
00028         self.assertRaises(self.failureException, self.assertNotAlmostEqual,
00029                           float('inf'), float('inf'))

Here is the call graph for this function:

Definition at line 30 of file test_assertions.py.

00030 
00031     def test_AmostEqualWithDelta(self):
00032         self.assertAlmostEqual(1.1, 1.0, delta=0.5)
00033         self.assertAlmostEqual(1.0, 1.1, delta=0.5)
00034         self.assertNotAlmostEqual(1.1, 1.0, delta=0.05)
00035         self.assertNotAlmostEqual(1.0, 1.1, delta=0.05)
00036 
00037         self.assertRaises(self.failureException, self.assertAlmostEqual,
00038                           1.1, 1.0, delta=0.05)
00039         self.assertRaises(self.failureException, self.assertNotAlmostEqual,
00040                           1.1, 1.0, delta=0.5)
00041 
00042         self.assertRaises(TypeError, self.assertAlmostEqual,
00043                           1.1, 1.0, places=2, delta=2)
00044         self.assertRaises(TypeError, self.assertNotAlmostEqual,
00045                           1.1, 1.0, places=2, delta=2)
00046 
00047         first = datetime.datetime.now()
00048         second = first + datetime.timedelta(seconds=10)
00049         self.assertAlmostEqual(first, second,
00050                                delta=datetime.timedelta(seconds=20))
00051         self.assertNotAlmostEqual(first, second,
00052                                   delta=datetime.timedelta(seconds=5))

Here is the call graph for this function:

Definition at line 53 of file test_assertions.py.

00053 
00054     def test_assertRaises(self):
00055         def _raise(e):
00056             raise e
00057         self.assertRaises(KeyError, _raise, KeyError)
00058         self.assertRaises(KeyError, _raise, KeyError("key"))
00059         try:
00060             self.assertRaises(KeyError, lambda: None)
00061         except self.failureException as e:
00062             self.assertIn("KeyError not raised", str(e))
00063         else:
00064             self.fail("assertRaises() didn't fail")
00065         try:
00066             self.assertRaises(KeyError, _raise, ValueError)
00067         except ValueError:
00068             pass
00069         else:
00070             self.fail("assertRaises() didn't let exception pass through")
00071         with self.assertRaises(KeyError) as cm:
00072             try:
00073                 raise KeyError
00074             except Exception as e:
00075                 exc = e
00076                 raise
00077         self.assertIs(cm.exception, exc)
00078 
00079         with self.assertRaises(KeyError):
00080             raise KeyError("key")
00081         try:
00082             with self.assertRaises(KeyError):
00083                 pass
00084         except self.failureException as e:
00085             self.assertIn("KeyError not raised", str(e))
00086         else:
00087             self.fail("assertRaises() didn't fail")
00088         try:
00089             with self.assertRaises(KeyError):
00090                 raise ValueError
00091         except ValueError:
00092             pass
00093         else:
00094             self.fail("assertRaises() didn't let exception pass through")

Here is the call graph for this function:

Definition at line 95 of file test_assertions.py.

00095 
00096     def testAssertNotRegex(self):
00097         self.assertNotRegex('Ala ma kota', r'r+')
00098         try:
00099             self.assertNotRegex('Ala ma kota', r'k.t', 'Message')
00100         except self.failureException as e:
00101             self.assertIn("'kot'", e.args[0])
00102             self.assertIn('Message', e.args[0])
00103         else:
00104             self.fail('assertNotRegex should have failed.')
00105 

Here is the call graph for this function:


The documentation for this class was generated from the following file: