Package trac :: Package tests :: Module compat

Source Code for Module trac.tests.compat

 1  # -*- coding: utf-8 -*- 
 2  # 
 3  # Copyright (C) 2013-2020 Edgewall Software 
 4  # All rights reserved. 
 5  # 
 6  # This software is licensed as described in the file COPYING, which 
 7  # you should have received as part of this distribution. The terms 
 8  # are also available at https://trac.edgewall.org/wiki/TracLicense. 
 9  # 
10  # This software consists of voluntary contributions made by many 
11  # individuals. For the exact contribution history, see the revision 
12  # history and logs, available at https://trac.edgewall.org/log/. 
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  # for backward compatibility 
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'):
32 - def assertIsNot(self, expr1, expr2, msg=None):
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'):
39 - def assertIsNone(self, obj, msg=None):
40 self.assertIs(obj, None, msg)
41 unittest.TestCase.assertIsNone = assertIsNone 42 43 44 if not hasattr(unittest.TestCase, 'assertIsNotNone'):
45 - def assertIsNotNone(self, obj, msg=None):
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'):
59 - def assertNotIn(self, member, container, msg=None):
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'):
67 - def assertIsInstance(self, obj, cls, msg=None):
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'):
75 - def assertNotIsInstance(self, obj, cls, msg=None):
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