1
2
3
4
5
6
7
8
9
10
11
12
13
14 """Some test functions since Python 2.7 to provide backwards-compatibility
15 with previous versions of Python from 2.5 onward.
16 """
17
18 import unittest
19
20 from trac.test import rmtree
21
22
23 if not hasattr(unittest.TestCase, 'assertIs'):
24 - def assertIs(self, expr1, expr2, msg=None):
25 if expr1 is not expr2:
26 raise self.failureException(msg or '%r is not %r'
27 % (expr1, expr2))
28 unittest.TestCase.assertIs = assertIs
29
30
31 if not hasattr(unittest.TestCase, 'assertIsNot'):
33 if expr1 is expr2:
34 raise self.failureException(msg or '%r is %r' % (expr1, expr2))
35 unittest.TestCase.assertIsNot = assertIsNot
36
37
38 if not hasattr(unittest.TestCase, 'assertIsNone'):
40 self.assertIs(obj, None, msg)
41 unittest.TestCase.assertIsNone = assertIsNone
42
43
44 if not hasattr(unittest.TestCase, 'assertIsNotNone'):
46 self.assertIsNot(obj, None, msg)
47 unittest.TestCase.assertIsNotNone = assertIsNotNone
48
49
50 if not hasattr(unittest.TestCase, 'assertIn'):
51 - def assertIn(self, member, container, msg=None):
52 if member not in container:
53 raise self.failureException(msg or '%r not in %r' %
54 (member, container))
55 unittest.TestCase.assertIn = assertIn
56
57
58 if not hasattr(unittest.TestCase, 'assertNotIn'):
60 if member in container:
61 raise self.failureException(msg or '%r in %r' %
62 (member, container))
63 unittest.TestCase.assertNotIn = assertNotIn
64
65
66 if not hasattr(unittest.TestCase, 'assertIsInstance'):
68 if not isinstance(obj, cls):
69 raise self.failureException(msg or '%r is not an instance of %r' %
70 (obj, cls))
71 unittest.TestCase.assertIsInstance = assertIsInstance
72
73
74 if not hasattr(unittest.TestCase, 'assertNotIsInstance'):
76 if isinstance(obj, cls):
77 raise self.failureException(msg or '%r is an instance of %r' %
78 (obj, cls))
79 unittest.TestCase.assertNotIsInstance = assertNotIsInstance
80