1. edgewall
  2. Trac

Commits

rjollos  committed d1a4cf3

1.1.2dev: Merged [12070:12079] from trac-trunk (fix for #11284).

  • Participants
  • Parent commits aa71b47
  • Branches trunk

Comments (0)

Files changed (31)

File trac/admin/tests/console.py

View file
             sys.stdout = _out
 
     def assertEqual(self, expected_results, output):
-        if not (isinstance(expected_results, basestring) and \
+        if not (isinstance(expected_results, basestring) and
                 isinstance(output, basestring)):
             return unittest.TestCase.assertEqual(self, expected_results, output)
         def diff():
         rv, output = self._execute('component chown bad_component changed_owner')
         self.assertEqual(2, rv)
         # We currently trigger a deprecation warning with py26 so we
-        # can currrently only verify that the end of the output string is
+        # can currently only verify that the end of the output string is
         # correct
         self.assertEqual(output.endswith(self.expected_results[test_name]), True)
 
         """
         test_name = sys._getframe().f_code.co_name
         self._execute(u'milestone add \xa9tat_final "%s"'  #\xc2\xa9
-                              % self._test_date)
+                      % self._test_date)
         rv, output = self._execute('milestone list')
         self.assertEqual(0, rv)
         self.assertEqual(self.expected_results[test_name], output)
         self.assertEqual(0, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_add_missing_sid(self):
+    def test_session_add_missing_sid(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session add')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_add_duplicate_sid(self):
+    def test_session_add_duplicate_sid(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env)
         rv, output = self._execute('session add name00')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_add_sid_all(self):
+    def test_session_add_sid_all(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session add john John john@example.org')
         self.assertEqual(0, rv)
                          % {'today': format_date(None, console_date_format)},
                          output)
 
-    def  test_session_add_sid(self):
+    def test_session_add_sid(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session add john')
         self.assertEqual(0, rv)
                          % {'today': format_date(None, console_date_format)},
                          output)
 
-    def  test_session_add_sid_name(self):
+    def test_session_add_sid_name(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session add john John')
         self.assertEqual(0, rv)
                          % {'today': format_date(None, console_date_format)},
                          output)
 
-    def  test_session_set_attr_name(self):
+    def test_session_set_attr_name(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env)
         rv, output = self._execute('session set name name00 JOHN')
         rv, output = self._execute('session list name00')
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_set_attr_email(self):
+    def test_session_set_attr_email(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env)
         rv, output = self._execute('session set email name00 JOHN@EXAMPLE.ORG')
         rv, output = self._execute('session list name00')
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_set_attr_missing_attr(self):
+    def test_session_set_attr_missing_attr(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session set')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_set_attr_missing_value(self):
+    def test_session_set_attr_missing_value(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session set name john')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_set_attr_missing_sid(self):
+    def test_session_set_attr_missing_sid(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session set name')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_set_attr_nonexistent_sid(self):
+    def test_session_set_attr_nonexistent_sid(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session set name john foo')
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_delete_sid(self):
+    def test_session_delete_sid(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env)
         rv, output = self._execute('session delete name00')
         rv, output = self._execute('session list nam00')
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_delete_missing_params(self):
+    def test_session_delete_missing_params(self):
         test_name = sys._getframe().f_code.co_name
         rv, output = self._execute('session delete')
         self.assertEqual(0, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_delete_anonymous(self):
+    def test_session_delete_anonymous(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env)
         rv, output = self._execute('session delete anonymous')
         rv, output = self._execute('session list *')
         self.assertEqual(self.expected_results[test_name], output)
 
-    def  test_session_purge_age(self):
+    def test_session_purge_age(self):
         test_name = sys._getframe().f_code.co_name
         _prep_session_table(self.env, spread_visits=True)
         rv, output = self._execute('session purge 20100112')

File trac/mimeview/pygments.py

View file
 from trac.env import ISystemInfoProvider
 from trac.mimeview.api import IHTMLPreviewRenderer, Mimeview
 from trac.prefs import IPreferencePanelProvider
+from trac.tests import compat
 from trac.util import get_pkginfo
 from trac.util.datefmt import http_date, localtz
 from trac.util.translation import _

File trac/mimeview/tests/api.py

View file
 
 from trac.core import *
 from trac.test import EnvironmentStub
+from trac.tests import compat
 from trac.mimeview import api
 from trac.mimeview.api import get_mimetype, IContentConverter, Mimeview, \
                               _group_lines
     def test_text_only_stream(self):
         input = [(TEXT, "test", (None, -1, -1))]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 1)
-        self.assertTrue(isinstance(lines[0], Stream))
-        self.assertEquals(lines[0].events, input)
+        self.assertEqual(len(lines), 1)
+        self.assertIsInstance(lines[0], Stream)
+        self.assertEqual(lines[0].events, input)
 
     def test_text_only_stream2(self):
         input = [(TEXT, "test\n", (None, -1, -1))]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 1)
-        self.assertTrue(isinstance(lines[0], Stream))
-        self.assertEquals(lines[0].events, [(TEXT, "test", (None, -1, -1))])
+        self.assertEqual(len(lines), 1)
+        self.assertIsInstance(lines[0], Stream)
+        self.assertEqual(lines[0].events, [(TEXT, "test", (None, -1, -1))])
 
     def test_simplespan(self):
         input = HTMLParser(StringIO(u"<span>test</span>"), encoding=None)
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 1)
-        self.assertTrue(isinstance(lines[0], Stream))
+        self.assertEqual(len(lines), 1)
+        self.assertIsInstance(lines[0], Stream)
         for (a, b) in zip(lines[0], input):
             self.assertEqual(a, b)
 
         """
         input = [(TEXT, "", (None, -1, -1))]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 0)
+        self.assertEqual(len(lines), 0)
 
     def test_newline_stream(self):
         input = [(TEXT, "\n", (None, -1, -1))]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 1)
+        self.assertEqual(len(lines), 1)
 
     def test_newline_stream2(self):
         input = [(TEXT, "\n\n\n", (None, -1, -1))]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), 3)
+        self.assertEqual(len(lines), 3)
 
     def test_empty_text_in_span(self):
         """
                     '<span class="c">b</span>',
                    ]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), len(expected))
+        self.assertEqual(len(lines), len(expected))
         for a, b in zip(lines, expected):
-            self.assertEquals(a.render('html'), b)
+            self.assertEqual(a.render('html'), b)
 
     def test_newline2(self):
         """
                     '<span class="c">b</span>',
                    ]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), len(expected))
+        self.assertEqual(len(lines), len(expected))
         for a, b in zip(lines, expected):
-            self.assertEquals(a.render('html'), b)
+            self.assertEqual(a.render('html'), b)
 
     def test_multinewline(self):
         """
                     '<span class="c">a</span>',
                    ]
         lines = list(_group_lines(input))
-        self.assertEquals(len(lines), len(expected))
+        self.assertEqual(len(lines), len(expected))
         for a, b in zip(lines, expected):
-            self.assertEquals(a.render('html'), b)
+            self.assertEqual(a.render('html'), b)
 
 
 def suite():

File trac/mimeview/tests/patch.py

View file
         result = XML(result.render(encoding='utf-8')).render(encoding='utf-8')
         expected, result = expected.splitlines(), result.splitlines()
         for exp, res in zip(expected, result):
-            self.assertEquals(exp, res)
-        self.assertEquals(len(expected), len(result))
+            self.assertEqual(exp, res)
+        self.assertEqual(len(expected), len(result))
 
     def test_simple(self):
         """
              '@@ -1 +1 @@',
              '-aa\tb',
              '+aaxb'], 8)
-        self.assertEquals('aa<del>&nbsp; &nbsp; &nbsp; </del>b',
-                          str(changes[0]['diffs'][0][0]['base']['lines'][0]))
-        self.assertEquals('aa<ins>x</ins>b',
-                          str(changes[0]['diffs'][0][0]['changed']['lines'][0]))
+        self.assertEqual('aa<del>&nbsp; &nbsp; &nbsp; </del>b',
+                         str(changes[0]['diffs'][0][0]['base']['lines'][0]))
+        self.assertEqual('aa<ins>x</ins>b',
+                         str(changes[0]['diffs'][0][0]['changed']['lines'][0]))
 
     def test_diff_to_hdf_leading_ws(self):
         """Regression test related to #5795"""
              '@@ -1 +1 @@',
              '-*a',
              '+ *a'], 8)
-        self.assertEquals('<del></del>*a',
-                          str(changes[0]['diffs'][0][0]['base']['lines'][0]))
-        self.assertEquals('<ins>&nbsp;</ins>*a',
-                          str(changes[0]['diffs'][0][0]['changed']['lines'][0]))
+        self.assertEqual('<del></del>*a',
+                         str(changes[0]['diffs'][0][0]['base']['lines'][0]))
+        self.assertEqual('<ins>&nbsp;</ins>*a',
+                         str(changes[0]['diffs'][0][0]['changed']['lines'][0]))
 
 def suite():
     suite = unittest.TestSuite()

File trac/mimeview/tests/pygments.py

View file
         #print "\nR: " + repr(result)
         expected, result = expected.splitlines(), result.splitlines()
         for exp, res in zip(expected, result):
-            self.assertEquals(exp, res)
-        self.assertEquals(len(expected), len(result))
+            self.assertEqual(exp, res)
+        self.assertEqual(len(expected), len(result))
 
     def test_python_hello(self):
         """
         pygments when rendering empty files.
         """
         result = self.pygments.render(self.context, 'text/x-python', '')
-        self.assertEqual(None, result)
+        self.assertIsNone(result)
 
     def test_extra_mimetypes(self):
         """

File trac/tests/attachment.py

View file
                                       hashes['42'][0:3], hashes['42'],
                                       hashes['foo.2.txt'] + '.txt'),
                          attachment.path)
-        self.assert_(os.path.exists(attachment.path))
+        self.assertTrue(os.path.exists(attachment.path))
 
     def test_insert_outside_attachments_dir(self):
         attachment = Attachment(self.env, '../../../../../sth/private', 42)
         attachment1.delete()
         attachment2.delete()
 
-        assert not os.path.exists(attachment1.path)
-        assert not os.path.exists(attachment2.path)
+        self.assertFalse(os.path.exists(attachment1.path))
+        self.assertFalse(os.path.exists(attachment2.path))
 
         attachments = Attachment.select(self.env, 'wiki', 'SomePage')
         self.assertEqual(0, len(list(attachments)))
         self.assertEqual(2, len(list(attachments)))
         attachments = Attachment.select(self.env, 'ticket', 123)
         self.assertEqual(0, len(list(attachments)))
-        assert os.path.exists(path1) and os.path.exists(attachment2.path)
+        self.assertTrue(os.path.exists(path1) and os.path.exists(attachment2.path))
 
         attachment1.reparent('ticket', 123)
         self.assertEqual('ticket', attachment1.parent_realm)
         self.assertEqual(1, len(list(attachments)))
         attachments = Attachment.select(self.env, 'ticket', 123)
         self.assertEqual(1, len(list(attachments)))
-        assert not os.path.exists(path1) and os.path.exists(attachment1.path)
-        assert os.path.exists(attachment2.path)
+        self.assertFalse(os.path.exists(path1) and os.path.exists(attachment1.path))
+        self.assertTrue(os.path.exists(attachment2.path))
 
     def test_legacy_permission_on_parent(self):
         """Ensure that legacy action tests are done on parent.  As
         `ATTACHMENT_VIEW` maps to `TICKET_VIEW`, the `TICKET_VIEW` is tested
         against the ticket's resource."""
         attachment = Attachment(self.env, 'ticket', 42)
-        self.assert_('ATTACHMENT_VIEW' in self.perm(attachment.resource))
+        self.assertTrue('ATTACHMENT_VIEW' in self.perm(attachment.resource))
 
     def test_resource_doesnt_exist(self):
         r = Resource('wiki', 'WikiStart').child('attachment', 'file.txt')
-        self.assertEqual(False, AttachmentModule(self.env).resource_exists(r))
+        self.assertFalse(AttachmentModule(self.env).resource_exists(r))
 
     def test_resource_exists(self):
         att = Attachment(self.env, 'wiki', 'WikiStart')

File trac/tests/compat.py

View file
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2013 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://trac.edgewall.org/wiki/TracLicense.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For the exact contribution history, see the revision
+# history and logs, available at http://trac.edgewall.org/log/.
+
+"""Some test functions since Python 2.7 to provide backwards-compatibility
+with previous versions of Python from 2.5 onward.
+"""
+
+import unittest
+
+
+if not hasattr(unittest.TestCase, 'assertIs'):
+    def assertIs(self, expr1, expr2, msg=None):
+        if expr1 is not expr2:
+            raise self.failureException(msg or '%r is not %r'
+                                               % (expr1, expr2))
+    unittest.TestCase.assertIs = assertIs
+
+
+if not hasattr(unittest.TestCase, 'assertIsNot'):
+    def assertIsNot(self, expr1, expr2, msg=None):
+        if expr1 is expr2:
+            raise self.failureException(msg or '%r is %r' % (expr1, expr2))
+    unittest.TestCase.assertIsNot = assertIsNot
+
+
+if not hasattr(unittest.TestCase, 'assertIsNone'):
+    def assertIsNone(self, obj, msg=None):
+        self.assertIs(obj, None, msg)
+    unittest.TestCase.assertIsNone = assertIsNone
+
+
+if not hasattr(unittest.TestCase, 'assertIsNotNone'):
+    def assertIsNotNone(self, obj, msg=None):
+        self.assertIsNot(obj, None, msg)
+    unittest.TestCase.assertIsNotNone = assertIsNotNone
+
+
+if not hasattr(unittest.TestCase, 'assertIn'):
+    def assertIn(self, member, container, msg=None):
+        if member not in container:
+            raise self.failureException(msg or '%r not in %r' %
+                                               (member, container))
+    unittest.TestCase.assertIn = assertIn
+
+
+if not hasattr(unittest.TestCase, 'assertNotIn'):
+    def assertNotIn(self, member, container, msg=None):
+        if member in container:
+            raise self.failureException(msg or '%r in %r' %
+                                               (member, container))
+    unittest.TestCase.assertNotIn = assertNotIn
+
+
+if not hasattr(unittest.TestCase, 'assertIsInstance'):
+    def assertIsInstance(self, obj, cls, msg=None):
+        if not isinstance(obj, cls):
+            raise self.failureException(msg or '%r is not an instance of %r' %
+                                               (obj, cls))
+    unittest.TestCase.assertIsInstance = assertIsInstance
+
+
+if not hasattr(unittest.TestCase, 'assertNotIsInstance'):
+    def assertNotIsInstance(self, obj, cls, msg=None):
+        if isinstance(obj, cls):
+            raise self.failureException(msg or '%r is an instance of %r' %
+                                               (obj, cls))
+    unittest.TestCase.assertNotIsInstance = assertNotIsInstance

File trac/tests/config.py

View file
 from trac.config import *
 from trac.core import Component, Interface, implements
 from trac.test import Configuration, EnvironmentStub
+from trac.tests import compat
 from trac.util import create_file
 
 
 
     def test_default(self):
         config = self._read()
-        self.assertEquals('', config.get('a', 'option'))
-        self.assertEquals('value', config.get('a', 'option', 'value'))
+        self.assertEqual('', config.get('a', 'option'))
+        self.assertEqual('value', config.get('a', 'option', 'value'))
 
         class Foo(object):
             option_a = Option('a', 'option', 'value')
 
-        self.assertEquals('value', config.get('a', 'option'))
+        self.assertEqual('value', config.get('a', 'option'))
 
     def test_default_bool(self):
         config = self._read()
-        self.assertEquals(False, config.getbool('a', 'option'))
-        self.assertEquals(True, config.getbool('a', 'option', 'yes'))
-        self.assertEquals(True, config.getbool('a', 'option', 1))
+        self.assertFalse(config.getbool('a', 'option'))
+        self.assertTrue(config.getbool('a', 'option', 'yes'))
+        self.assertTrue(config.getbool('a', 'option', 1))
 
         class Foo(object):
             option_a = Option('a', 'option', 'true')
 
-        self.assertEquals(True, config.getbool('a', 'option'))
+        self.assertTrue(config.getbool('a', 'option'))
 
     def test_default_int(self):
         config = self._read()
         self.assertRaises(ConfigurationError,
                           config.getint, 'a', 'option', 'b')
-        self.assertEquals(0, config.getint('a', 'option'))
-        self.assertEquals(1, config.getint('a', 'option', '1'))
-        self.assertEquals(1, config.getint('a', 'option', 1))
+        self.assertEqual(0, config.getint('a', 'option'))
+        self.assertEqual(1, config.getint('a', 'option', '1'))
+        self.assertEqual(1, config.getint('a', 'option', 1))
 
         class Foo(object):
             option_a = Option('a', 'option', '2')
 
-        self.assertEquals(2, config.getint('a', 'option'))
+        self.assertEqual(2, config.getint('a', 'option'))
 
     def test_default_float(self):
         config = self._read()
         self.assertRaises(ConfigurationError,
                           config.getfloat, 'a', 'option', 'b')
-        self.assertEquals(0.0, config.getfloat('a', 'option'))
-        self.assertEquals(1.2, config.getfloat('a', 'option', '1.2'))
-        self.assertEquals(1.2, config.getfloat('a', 'option', 1.2))
-        self.assertEquals(1.0, config.getfloat('a', 'option', 1))
+        self.assertEqual(0.0, config.getfloat('a', 'option'))
+        self.assertEqual(1.2, config.getfloat('a', 'option', '1.2'))
+        self.assertEqual(1.2, config.getfloat('a', 'option', 1.2))
+        self.assertEqual(1.0, config.getfloat('a', 'option', 1))
 
         class Foo(object):
             option_a = Option('a', 'option', '2.5')
 
-        self.assertEquals(2.5, config.getfloat('a', 'option'))
+        self.assertEqual(2.5, config.getfloat('a', 'option'))
 
     def test_default_path(self):
         config = self._read()
         class Foo(object):
             option_a = PathOption('a', 'opt1', 'file.ini')
             option_b = PathOption('a', 'opt2', '/somewhere/file.ini')
-        self.assertEquals('file.ini', config.get('a', 'opt1'))
+        self.assertEqual('file.ini', config.get('a', 'opt1'))
         self.assertNotEquals('file.ini', config.getpath('a', 'opt1'))
         self.assertTrue(os.path.isabs(config.getpath('a', 'opt1')))
-        self.assertEquals('/somewhere/file.ini', os.path.splitdrive(
-                config.getpath('a', 'opt2'))[1].replace('\\', '/'))
-        self.assertEquals('/none.ini', os.path.splitdrive(
-                config.getpath('a', 'opt3', '/none.ini'))[1].replace('\\', '/'))
+        self.assertEqual('/somewhere/file.ini', os.path.splitdrive(
+                         config.getpath('a', 'opt2'))[1].replace('\\', '/'))
+        self.assertEqual('/none.ini', os.path.splitdrive(
+                         config.getpath('a', 'opt3',
+                                        '/none.ini'))[1].replace('\\', '/'))
         self.assertNotEquals('none.ini', config.getpath('a', 'opt3', 'none.ini'))
 
     def test_read_and_get(self):
         self._write(['[a]', 'option = x'])
         config = self._read()
-        self.assertEquals('x', config.get('a', 'option'))
-        self.assertEquals('x', config.get('a', 'option', 'y'))
-        self.assertEquals('y', config.get('b', 'option2', 'y'))
+        self.assertEqual('x', config.get('a', 'option'))
+        self.assertEqual('x', config.get('a', 'option', 'y'))
+        self.assertEqual('y', config.get('b', 'option2', 'y'))
 
     def test_read_and_get_unicode(self):
         self._write([u'[ä]', u'öption = x'])
         config = self._read()
-        self.assertEquals('x', config.get(u'ä', u'öption'))
-        self.assertEquals('x', config.get(u'ä', u'öption', 'y'))
-        self.assertEquals('y', config.get('b', u'öption2', 'y'))
+        self.assertEqual('x', config.get(u'ä', u'öption'))
+        self.assertEqual('x', config.get(u'ä', u'öption', 'y'))
+        self.assertEqual('y', config.get('b', u'öption2', 'y'))
 
     def test_read_and_getbool(self):
         self._write(['[a]', 'option = yes', 'option2 = true',
                      'option5 = 1', 'option6 = 123', 'option7 = 123.456',
                      'option8 = disabled', 'option9 = 0', 'option10 = 0.0'])
         config = self._read()
-        self.assertEquals(True, config.getbool('a', 'option'))
-        self.assertEquals(True, config.getbool('a', 'option', False))
-        self.assertEquals(True, config.getbool('a', 'option2'))
-        self.assertEquals(True, config.getbool('a', 'option3'))
-        self.assertEquals(True, config.getbool('a', 'option4'))
-        self.assertEquals(True, config.getbool('a', 'option5'))
-        self.assertEquals(True, config.getbool('a', 'option6'))
-        self.assertEquals(True, config.getbool('a', 'option7'))
-        self.assertEquals(False, config.getbool('a', 'option8'))
-        self.assertEquals(False, config.getbool('a', 'option9'))
-        self.assertEquals(False, config.getbool('a', 'option10'))
-        self.assertEquals(False, config.getbool('b', 'option_b'))
-        self.assertEquals(False, config.getbool('b', 'option_b', False))
-        self.assertEquals(False, config.getbool('b', 'option_b', 'disabled'))
+        self.assertTrue(config.getbool('a', 'option'))
+        self.assertTrue(config.getbool('a', 'option', False))
+        self.assertTrue(config.getbool('a', 'option2'))
+        self.assertTrue(config.getbool('a', 'option3'))
+        self.assertTrue(config.getbool('a', 'option4'))
+        self.assertTrue(config.getbool('a', 'option5'))
+        self.assertTrue(config.getbool('a', 'option6'))
+        self.assertTrue(config.getbool('a', 'option7'))
+        self.assertFalse(config.getbool('a', 'option8'))
+        self.assertFalse(config.getbool('a', 'option9'))
+        self.assertFalse(config.getbool('a', 'option10'))
+        self.assertFalse(config.getbool('b', 'option_b'))
+        self.assertFalse(config.getbool('b', 'option_b', False))
+        self.assertFalse(config.getbool('b', 'option_b', 'disabled'))
 
     def test_read_and_getint(self):
         self._write(['[a]', 'option = 42'])
         config = self._read()
-        self.assertEquals(42, config.getint('a', 'option'))
-        self.assertEquals(42, config.getint('a', 'option', 25))
-        self.assertEquals(0, config.getint('b', 'option2'))
-        self.assertEquals(25, config.getint('b', 'option2', 25))
-        self.assertEquals(25, config.getint('b', 'option2', '25'))
+        self.assertEqual(42, config.getint('a', 'option'))
+        self.assertEqual(42, config.getint('a', 'option', 25))
+        self.assertEqual(0, config.getint('b', 'option2'))
+        self.assertEqual(25, config.getint('b', 'option2', 25))
+        self.assertEqual(25, config.getint('b', 'option2', '25'))
 
     def test_read_and_getfloat(self):
         self._write(['[a]', 'option = 42.5'])
         config = self._read()
-        self.assertEquals(42.5, config.getfloat('a', 'option'))
-        self.assertEquals(42.5, config.getfloat('a', 'option', 25.3))
-        self.assertEquals(0, config.getfloat('b', 'option2'))
-        self.assertEquals(25.3, config.getfloat('b', 'option2', 25.3))
-        self.assertEquals(25.0, config.getfloat('b', 'option2', 25))
-        self.assertEquals(25.3, config.getfloat('b', 'option2', '25.3'))
+        self.assertEqual(42.5, config.getfloat('a', 'option'))
+        self.assertEqual(42.5, config.getfloat('a', 'option', 25.3))
+        self.assertEqual(0, config.getfloat('b', 'option2'))
+        self.assertEqual(25.3, config.getfloat('b', 'option2', 25.3))
+        self.assertEqual(25.0, config.getfloat('b', 'option2', 25))
+        self.assertEqual(25.3, config.getfloat('b', 'option2', '25.3'))
 
     def test_read_and_getlist(self):
         self._write(['[a]', 'option = foo, bar, baz'])
         config = self._read()
-        self.assertEquals(['foo', 'bar', 'baz'],
-                          config.getlist('a', 'option'))
-        self.assertEquals([],
-                          config.getlist('b', 'option2'))
-        self.assertEquals(['foo', 'bar', 'baz'],
-                    config.getlist('b', 'option2', ['foo', 'bar', 'baz']))
-        self.assertEquals(['foo', 'bar', 'baz'],
-                    config.getlist('b', 'option2', 'foo, bar, baz'))
+        self.assertEqual(['foo', 'bar', 'baz'],
+                         config.getlist('a', 'option'))
+        self.assertEqual([],
+                         config.getlist('b', 'option2'))
+        self.assertEqual(['foo', 'bar', 'baz'],
+                         config.getlist('b', 'option2',
+                                        ['foo', 'bar', 'baz']))
+        self.assertEqual(['foo', 'bar', 'baz'],
+                         config.getlist('b', 'option2', 'foo, bar, baz'))
 
     def test_read_and_getlist_sep(self):
         self._write(['[a]', 'option = foo | bar | baz'])
         config = self._read()
-        self.assertEquals(['foo', 'bar', 'baz'],
-                          config.getlist('a', 'option', sep='|'))
+        self.assertEqual(['foo', 'bar', 'baz'],
+                         config.getlist('a', 'option', sep='|'))
 
     def test_read_and_getlist_keep_empty(self):
         self._write(['[a]', 'option = ,bar,baz'])
         config = self._read()
-        self.assertEquals(['bar', 'baz'], config.getlist('a', 'option'))
-        self.assertEquals(['', 'bar', 'baz'],
-                          config.getlist('a', 'option', keep_empty=True))
+        self.assertEqual(['bar', 'baz'], config.getlist('a', 'option'))
+        self.assertEqual(['', 'bar', 'baz'],
+                         config.getlist('a', 'option', keep_empty=True))
 
     def test_read_and_getlist_false_values(self):
         config = self._read()
         values = [None, False, '', 'foo', u'', u'bar',
                   0, 0L, 0.0, 0j, 42, 43.0]
-        self.assertEquals([False, 'foo', u'bar', 0, 0L, 0.0, 0j, 42, 43.0],
-                          config.getlist('a', 'false', values))
-        self.assertEquals(values, config.getlist('a', 'false', values,
-                                                 keep_empty=True))
+        self.assertEqual([False, 'foo', u'bar', 0, 0L, 0.0, 0j, 42, 43.0],
+                         config.getlist('a', 'false', values))
+        self.assertEqual(values, config.getlist('a', 'false', values,
+                                                keep_empty=True))
 
     def test_read_and_choice(self):
         self._write(['[a]', 'option = 2', 'invalid = d'])
                 self.config = config
 
         foo = Foo()
-        self.assertEquals('2', foo.option)
-        self.assertEquals('1', foo.other)
+        self.assertEqual('2', foo.option)
+        self.assertEqual('1', foo.other)
         self.assertRaises(ConfigurationError, getattr, foo, 'invalid')
 
     def test_read_and_getextensionoption(self):
 
         foo = Foo(self.env)
         self.assertRaises(ConfigurationError, getattr, foo, 'default1')
-        self.assertTrue(isinstance(foo.default2, ImplA))
+        self.assertIsInstance(foo.default2, ImplA)
         self.assertRaises(ConfigurationError, getattr, foo, 'default3')
-        self.assertTrue(isinstance(foo.option, ImplA))
-        self.assertTrue(isinstance(foo.option2, ImplA))
+        self.assertIsInstance(foo.option, ImplA)
+        self.assertIsInstance(foo.option2, ImplA)
         self.assertRaises(ConfigurationError, getattr, foo, 'invalid')
 
     def test_read_and_getorderedextensionsoption(self):
         foo = Foo(self.env)
         self.assertEqual([], foo.default1)
         self.assertEqual(3, len(foo.default2))
-        self.assertTrue(isinstance(foo.default2[0], ImplA))
-        self.assertTrue(isinstance(foo.default2[1], ImplB))
-        self.assertTrue(isinstance(foo.default2[2], ImplC))
+        self.assertIsInstance(foo.default2[0], ImplA)
+        self.assertIsInstance(foo.default2[1], ImplB)
+        self.assertIsInstance(foo.default2[2], ImplC)
         self.assertEqual(2, len(foo.default3))
-        self.assertTrue(isinstance(foo.default3[0], ImplB))
-        self.assertTrue(isinstance(foo.default3[1], ImplC))
+        self.assertIsInstance(foo.default3[0], ImplB)
+        self.assertIsInstance(foo.default3[1], ImplC)
         self.assertEqual(2, len(foo.option))
-        self.assertTrue(isinstance(foo.option[0], ImplA))
-        self.assertTrue(isinstance(foo.option[1], ImplB))
+        self.assertIsInstance(foo.option[0], ImplA)
+        self.assertIsInstance(foo.option[1], ImplB)
         self.assertRaises(ConfigurationError, getattr, foo, 'invalid')
 
     def test_getpath(self):
         config.set('a', 'path_a', os.path.join(base, 'here', 'absolute.txt'))
         config.set('a', 'path_b', 'thisdir.txt')
         config.set('a', 'path_c', os.path.join(os.pardir, 'parentdir.txt'))
-        self.assertEquals(os.path.join(base, 'here', 'absolute.txt'),
-                          config.getpath('a', 'path_a'))
-        self.assertEquals(os.path.join(base, 'thisdir.txt'),
-                          config.getpath('a', 'path_b'))
-        self.assertEquals(os.path.join(os.path.dirname(base), 'parentdir.txt'),
-                          config.getpath('a', 'path_c'))
+        self.assertEqual(os.path.join(base, 'here', 'absolute.txt'),
+                         config.getpath('a', 'path_a'))
+        self.assertEqual(os.path.join(base, 'thisdir.txt'),
+                         config.getpath('a', 'path_b'))
+        self.assertEqual(os.path.join(os.path.dirname(base), 'parentdir.txt'),
+                         config.getpath('a', 'path_c'))
 
     def test_set_raises(self):
         class Foo(object):
         config.set(u'aä', 'option1', u"Voilà l'été") # unicode
         # Note: the following would depend on the locale.getpreferredencoding()
         # config.set('a', 'option3', "Voil\xe0 l'\xe9t\xe9") # latin-1
-        self.assertEquals('x', config.get(u'aä', u'öption0'))
-        self.assertEquals(u"Voilà l'été", config.get(u'aä', 'option1'))
-        self.assertEquals(u"Voilà l'été", config.get(u'aä', 'option2'))
+        self.assertEqual('x', config.get(u'aä', u'öption0'))
+        self.assertEqual(u"Voilà l'été", config.get(u'aä', 'option1'))
+        self.assertEqual(u"Voilà l'été", config.get(u'aä', 'option2'))
         config.save()
 
         configfile = open(self.filename, 'r')
-        self.assertEquals(['# -*- coding: utf-8 -*-\n',
-                           '\n',
-                           '[aä]\n',
-                           "option1 = Voilà l'été\n",
-                           "option2 = Voilà l'été\n",
-                           'öption0 = x\n',
-                           # "option3 = Voilà l'été\n",
-                           '\n',
-                           '[b]\n',
-                           'öption0 = y\n',
-                           '\n'],
-                          configfile.readlines())
+        self.assertEqual(['# -*- coding: utf-8 -*-\n',
+                          '\n',
+                          '[aä]\n',
+                          "option1 = Voilà l'été\n",
+                          "option2 = Voilà l'été\n",
+                          'öption0 = x\n',
+                          # "option3 = Voilà l'été\n",
+                          '\n',
+                          '[b]\n',
+                          'öption0 = y\n',
+                          '\n'],
+                         configfile.readlines())
         configfile.close()
         config2 = Configuration(self.filename)
-        self.assertEquals('x', config2.get(u'aä', u'öption0'))
-        self.assertEquals(u"Voilà l'été", config2.get(u'aä', 'option1'))
-        self.assertEquals(u"Voilà l'été", config2.get(u'aä', 'option2'))
-        # self.assertEquals(u"Voilà l'été", config2.get('a', 'option3'))
+        self.assertEqual('x', config2.get(u'aä', u'öption0'))
+        self.assertEqual(u"Voilà l'été", config2.get(u'aä', 'option1'))
+        self.assertEqual(u"Voilà l'été", config2.get(u'aä', 'option2'))
+        # self.assertEqual(u"Voilà l'été", config2.get('a', 'option3'))
 
     def test_set_and_save_inherit(self):
         def testcb():
             config = self._read()
             config.set('a', 'option2', "Voilà l'été")  # UTF-8
             config.set('a', 'option1', u"Voilà l'été") # unicode
-            self.assertEquals('x', config.get('a', 'option'))
-            self.assertEquals(u"Voilà l'été", config.get('a', 'option1'))
-            self.assertEquals(u"Voilà l'été", config.get('a', 'option2'))
+            self.assertEqual('x', config.get('a', 'option'))
+            self.assertEqual(u"Voilà l'été", config.get('a', 'option1'))
+            self.assertEqual(u"Voilà l'été", config.get('a', 'option2'))
             config.save()
 
             configfile = open(self.filename, 'r')
-            self.assertEquals(['# -*- coding: utf-8 -*-\n',
-                               '\n',
-                               '[a]\n',
-                               "option1 = Voilà l'été\n",
-                               "option2 = Voilà l'été\n",
-                               '\n',
-                               '[inherit]\n',
-                               "file = trac-site.ini\n",
-                               '\n'],
-                              configfile.readlines())
+            self.assertEqual(['# -*- coding: utf-8 -*-\n',
+                              '\n',
+                              '[a]\n',
+                              "option1 = Voilà l'été\n",
+                              "option2 = Voilà l'été\n",
+                              '\n',
+                              '[inherit]\n',
+                              "file = trac-site.ini\n",
+                              '\n'],
+                             configfile.readlines())
             configfile.close()
             config2 = Configuration(self.filename)
-            self.assertEquals('x', config2.get('a', 'option'))
-            self.assertEquals(u"Voilà l'été", config2.get('a', 'option1'))
-            self.assertEquals(u"Voilà l'été", config2.get('a', 'option2'))
+            self.assertEqual('x', config2.get('a', 'option'))
+            self.assertEqual(u"Voilà l'été", config2.get('a', 'option1'))
+            self.assertEqual(u"Voilà l'été", config2.get('a', 'option2'))
         self._test_with_inherit(testcb)
 
     def test_simple_remove(self):
         config.get('a', 'option') # populates the cache
         config.set(u'aä', u'öption', u'öne')
         config.remove('a', 'option')
-        self.assertEquals('', config.get('a', 'option'))
+        self.assertEqual('', config.get('a', 'option'))
         config.remove(u'aä', u'öption')
-        self.assertEquals('', config.get('aä', 'öption'))
+        self.assertEqual('', config.get('aä', 'öption'))
         config.remove('a', 'option2') # shouldn't fail
         config.remove('b', 'option2') # shouldn't fail
 
     def test_sections(self):
         self._write(['[a]', 'option = x', '[b]', 'option = y'])
         config = self._read()
-        self.assertEquals(['a', 'b'], config.sections())
+        self.assertEqual(['a', 'b'], config.sections())
 
         class Foo(object):
             # enclose in parentheses to avoid messages extraction
             section_c = (ConfigSection)('c', 'Doc for c')
             option_c = Option('c', 'option', 'value')
 
-        self.assertEquals(['a', 'b', 'c'], config.sections())
+        self.assertEqual(['a', 'b', 'c'], config.sections())
         foo = Foo()
         foo.config = config
-        self.assert_(foo.section_c is config['c'])
-        self.assertEquals('value', foo.section_c.get('option'))
+        self.assertTrue(foo.section_c is config['c'])
+        self.assertEqual('value', foo.section_c.get('option'))
 
     def test_sections_unicode(self):
         self._write([u'[aä]', u'öption = x', '[b]', 'option = y'])
         config = self._read()
-        self.assertEquals([u'aä', 'b'], config.sections())
+        self.assertEqual([u'aä', 'b'], config.sections())
 
         class Foo(object):
             option_c = Option(u'cä', 'option', 'value')
 
-        self.assertEquals([u'aä', 'b', u'cä'], config.sections())
+        self.assertEqual([u'aä', 'b', u'cä'], config.sections())
 
     def test_options(self):
         self._write(['[a]', 'option = x', '[b]', 'option = y'])
         config = self._read()
-        self.assertEquals(('option', 'x'), iter(config.options('a')).next())
-        self.assertEquals(('option', 'y'), iter(config.options('b')).next())
+        self.assertEqual(('option', 'x'), iter(config.options('a')).next())
+        self.assertEqual(('option', 'y'), iter(config.options('b')).next())
         self.assertRaises(StopIteration, iter(config.options('c')).next)
-        self.assertEquals('option', iter(config['a']).next())
-        self.assertEquals('option', iter(config['b']).next())
+        self.assertEqual('option', iter(config['a']).next())
+        self.assertEqual('option', iter(config['b']).next())
         self.assertRaises(StopIteration, iter(config['c']).next)
 
         class Foo(object):
             option_a = Option('a', 'b', 'c')
 
-        self.assertEquals([('option', 'x'), ('b', 'c')],
-                                list(config.options('a')))
+        self.assertEqual([('option', 'x'), ('b', 'c')],
+                         list(config.options('a')))
 
     def test_options_unicode(self):
         self._write([u'[ä]', u'öption = x', '[b]', 'option = y'])
         config = self._read()
-        self.assertEquals((u'öption', 'x'), iter(config.options(u'ä')).next())
-        self.assertEquals(('option', 'y'), iter(config.options('b')).next())
+        self.assertEqual((u'öption', 'x'), iter(config.options(u'ä')).next())
+        self.assertEqual(('option', 'y'), iter(config.options('b')).next())
         self.assertRaises(StopIteration, iter(config.options('c')).next)
-        self.assertEquals(u'öption', iter(config['ä']).next())
+        self.assertEqual(u'öption', iter(config['ä']).next())
 
         class Foo(object):
             option_a = Option(u'ä', u'öption2', 'c')
 
-        self.assertEquals([(u'öption', 'x'), (u'öption2', 'c')],
-                                list(config.options(u'ä')))
+        self.assertEqual([(u'öption', 'x'), (u'öption2', 'c')],
+                         list(config.options(u'ä')))
 
     def test_has_option(self):
         config = self._read()
-        self.assertEquals(False, config.has_option('a', 'option'))
-        self.assertEquals(False, 'option' in config['a'])
+        self.assertFalse(config.has_option('a', 'option'))
+        self.assertFalse('option' in config['a'])
         self._write(['[a]', 'option = x'])
         config = self._read()
-        self.assertEquals(True, config.has_option('a', 'option'))
-        self.assertEquals(True, 'option' in config['a'])
+        self.assertTrue(config.has_option('a', 'option'))
+        self.assertTrue('option' in config['a'])
 
         class Foo(object):
             option_a = Option('a', 'option2', 'x2')
 
-        self.assertEquals(True, config.has_option('a', 'option2'))
+        self.assertTrue(config.has_option('a', 'option2'))
 
     def test_has_option_unicode(self):
         config = self._read()
-        self.assertEquals(False, config.has_option(u'ä', u'öption'))
-        self.assertEquals(False, u'öption' in config[u'ä'])
+        self.assertFalse(config.has_option(u'ä', u'öption'))
+        self.assertFalse(u'öption' in config[u'ä'])
         self._write([u'[ä]', u'öption = x'])
         config = self._read()
-        self.assertEquals(True, config.has_option(u'ä', u'öption'))
-        self.assertEquals(True, u'öption' in config[u'ä'])
+        self.assertTrue(config.has_option(u'ä', u'öption'))
+        self.assertTrue(u'öption' in config[u'ä'])
 
         class Foo(object):
             option_a = Option(u'ä', u'öption2', 'x2')
 
-        self.assertEquals(True, config.has_option(u'ä', u'öption2'))
+        self.assertTrue(config.has_option(u'ä', u'öption2'))
 
     def test_reparse(self):
         self._write(['[a]', 'option = x'])
         config = self._read()
-        self.assertEquals('x', config.get('a', 'option'))
+        self.assertEqual('x', config.get('a', 'option'))
         time.sleep(2) # needed because of low mtime granularity,
                       # especially on fat filesystems
 
         self._write(['[a]', 'option = y'])
         config.parse_if_needed()
-        self.assertEquals('y', config.get('a', 'option'))
+        self.assertEqual('y', config.get('a', 'option'))
 
     def test_inherit_one_level(self):
         def testcb():
             config.remove('a', 'option') # Should *not* remove option in parent
             self.assertEqual('x', config.get('a', 'option'))
             self.assertEqual([('option', 'x')], list(config.options('a')))
-            self.assertEqual(True, 'a' in config)
+            self.assertTrue('a' in config)
         self._test_with_inherit(testcb)
 
     def test_inherit_multiple(self):
         config.set_defaults()
         config.save()
         with open(self.filename, 'r') as f:
-            self.assertEquals('# -*- coding: utf-8 -*-\n',            f.next())
-            self.assertEquals('\n',                                   f.next())
-            self.assertEquals('[a]\n',                                f.next())
-            self.assertEquals('blah = Blàh!\n',                       f.next())
-            self.assertEquals('choice = -42\n',                       f.next())
-            self.assertEquals('false = disabled\n',                   f.next())
-            self.assertEquals('list = #cc0|4.2|42|0||enabled|disabled|\n',
-                              f.next())
-            self.assertEquals('# none = <inherited>\n',               f.next())
-            self.assertEquals('true = enabled\n',                     f.next())
-            self.assertEquals('\n',                                   f.next())
+            self.assertEqual('# -*- coding: utf-8 -*-\n',            f.next())
+            self.assertEqual('\n',                                   f.next())
+            self.assertEqual('[a]\n',                                f.next())
+            self.assertEqual('blah = Blàh!\n',                       f.next())
+            self.assertEqual('choice = -42\n',                       f.next())
+            self.assertEqual('false = disabled\n',                   f.next())
+            self.assertEqual('list = #cc0|4.2|42|0||enabled|disabled|\n',
+                             f.next())
+            self.assertEqual('# none = <inherited>\n',               f.next())
+            self.assertEqual('true = enabled\n',                     f.next())
+            self.assertEqual('\n',                                   f.next())
             self.assertRaises(StopIteration, f.next)
 
     def test_unicode_option_with_raw_default(self):
         config.set_defaults()
         config.save()
         with open(self.filename, 'r') as f:
-            self.assertEquals('# -*- coding: utf-8 -*-\n',            f.next())
-            self.assertEquals('\n',                                   f.next())
-            self.assertEquals('[résumé]\n',                           f.next())
-            self.assertEquals('bláh = Blàh!\n',                       f.next())
-            self.assertEquals('chöicé = -42\n',                       f.next())
-            self.assertEquals('fálsé = disabled\n',                   f.next())
-            self.assertEquals('liśt = #ccö|4.2|42|0||enabled|disabled|\n',
-                              f.next())
-            self.assertEquals('# nöné = <inherited>\n',               f.next())
-            self.assertEquals('trüé = enabled\n',                     f.next())
-            self.assertEquals('\n',                                   f.next())
+            self.assertEqual('# -*- coding: utf-8 -*-\n',            f.next())
+            self.assertEqual('\n',                                   f.next())
+            self.assertEqual('[résumé]\n',                           f.next())
+            self.assertEqual('bláh = Blàh!\n',                       f.next())
+            self.assertEqual('chöicé = -42\n',                       f.next())
+            self.assertEqual('fálsé = disabled\n',                   f.next())
+            self.assertEqual('liśt = #ccö|4.2|42|0||enabled|disabled|\n',
+                             f.next())
+            self.assertEqual('# nöné = <inherited>\n',               f.next())
+            self.assertEqual('trüé = enabled\n',                     f.next())
+            self.assertEqual('\n',                                   f.next())
             self.assertRaises(StopIteration, f.next)
 
     def _test_with_inherit(self, testcb):

File trac/tests/core.py

View file
 
 from trac.core import *
 from trac.core import ComponentManager
+from trac.tests import compat
 
 import unittest
 
         registry.
         """
         from trac.core import ComponentMeta
-        assert Component not in ComponentMeta._components
+        self.assertNotIn(Component, ComponentMeta._components)
         self.assertRaises(TracError, self.compmgr.__getitem__, Component)
 
     def test_abstract_component_not_registered(self):
         from trac.core import ComponentMeta
         class AbstractComponent(Component):
             abstract = True
-        assert AbstractComponent not in ComponentMeta._components
+        self.assertNotIn(AbstractComponent, ComponentMeta._components)
         self.assertRaises(TracError, self.compmgr.__getitem__,
                           AbstractComponent)
 
         """
         class ComponentA(Component):
             pass
-        assert self.compmgr[ComponentA]
-        assert ComponentA(self.compmgr)
+        self.assertTrue(self.compmgr[ComponentA])
+        self.assertTrue(ComponentA(self.compmgr))
 
     def test_component_identity(self):
         """
             pass
         c1 = ComponentA(self.compmgr)
         c2 = ComponentA(self.compmgr)
-        assert c1 is c2, 'Expected same component instance'
+        self.assertIs(c1, c2, 'Expected same component instance')
         c2 = self.compmgr[ComponentA]
-        assert c1 is c2, 'Expected same component instance'
+        self.assertIs(c1, c2, 'Expected same component instance')
 
     def test_component_initializer(self):
         """
             def test(self):
                 return 'x'
         tests = iter(ComponentA(self.compmgr).tests)
-        self.assertEquals('x', tests.next().test())
+        self.assertEqual('x', tests.next().test())
         self.assertRaises(StopIteration, tests.next)
 
     def test_extension_point_with_two_extensions(self):
             def test(self):
                 return 'y'
         results = [test.test() for test in ComponentA(self.compmgr).tests]
-        self.assertEquals(['x', 'y'], sorted(results))
+        self.assertEqual(['x', 'y'], sorted(results))
 
     def test_inherited_extension_point(self):
         """
             def test(self):
                 return 'x'
         tests = iter(ConcreteComponent(self.compmgr).tests)
-        self.assertEquals('x', tests.next().test())
+        self.assertEqual('x', tests.next().test())
         self.assertRaises(StopIteration, tests.next)
 
     def test_inherited_implements(self):
         class ConcreteComponent(BaseComponent):
             pass
         from trac.core import ComponentMeta
-        assert ConcreteComponent in ComponentMeta._registry.get(ITest, [])
+        self.assertIn(ConcreteComponent, ComponentMeta._registry.get(ITest, []))
 
     def test_inherited_implements_multilevel(self):
         """
         class ConcreteComponent(ChildComponent):
             pass
         from trac.core import ComponentMeta
-        assert ConcreteComponent in ComponentMeta._registry.get(ITest, [])
-        assert ConcreteComponent in ComponentMeta._registry.get(IOtherTest, [])
+        self.assertIn(ConcreteComponent, ComponentMeta._registry.get(ITest, []))
+        self.assertIn(ConcreteComponent, ComponentMeta._registry.get(IOtherTest, []))
 
     def test_component_manager_component(self):
         """
             def test(self):
                 return 'x'
         mgr = ManagerComponent('Test', 42)
-        assert id(mgr) == id(mgr[ManagerComponent])
+        self.assertEqual(id(mgr), id(mgr[ManagerComponent]))
         tests = iter(mgr.tests)
-        self.assertEquals('x', tests.next().test())
+        self.assertEqual('x', tests.next().test())
         self.assertRaises(StopIteration, tests.next)
 
     def test_component_manager_component_isolation(self):
         mgrA = ManagerComponentA()
         mgrB = ManagerComponentB()
 
-        self.assertEquals([mgrA], Tester(mgrA).tests)
-        self.assertEquals([mgrB], Tester(mgrB).tests)
+        self.assertEqual([mgrA], Tester(mgrA).tests)
+        self.assertEqual([mgrB], Tester(mgrB).tests)
 
     def test_instantiation_doesnt_enable(self):
         """
             pass
         mgr = DisablingComponentManager()
         instance = ComponentA(mgr)
-        self.assertEqual(None, mgr[ComponentA])
+        self.assertIsNone(mgr[ComponentA])
 
 
 def suite():

File trac/tests/env.py

View file
 import tempfile
 import unittest
 
+from trac.tests import compat
 from trac import db_default
 from trac.core import ComponentManager
 from trac.env import Environment
 
 class EnvironmentTestCase(unittest.TestCase):
 
-    if not hasattr(unittest.TestCase, 'assertIs'):
-        def assertIs(self, expr1, expr2, msg=None):
-            if expr1 is not expr2:
-                raise self.failureException(msg or '%r is not %r'
-                                                   % (expr1, expr2))
-
     def setUp(self):
         env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
         self.env = Environment(env_path, create=True)

File trac/tests/functional/testcases.py

View file
             fixup3 = traclogfile.read()
             message = 'Logging still off when it should have been on.\n' \
                       '%r\n%r' % (debug3, fixup3)
-        self.assert_(success, message)
+        self.assertTrue(success, message)
 
 
 class RegressionTestTicket5572(FunctionalTwillTestCaseSetup):

File trac/tests/perm.py

View file
             [('john', 'WIKI_MODIFY'),
              ('john', 'REPORT_ADMIN'),
              ('kate', 'TICKET_CREATE')])
-        self.assertEquals(['REPORT_ADMIN', 'WIKI_MODIFY'],
-                          sorted(self.store.get_user_permissions('john')))
-        self.assertEquals(['TICKET_CREATE'],
-                          self.store.get_user_permissions('kate'))
+        self.assertEqual(['REPORT_ADMIN', 'WIKI_MODIFY'],
+                         sorted(self.store.get_user_permissions('john')))
+        self.assertEqual(['TICKET_CREATE'],
+                         self.store.get_user_permissions('kate'))
 
     def test_simple_group(self):
         self.env.db_transaction.executemany(
             [('dev', 'WIKI_MODIFY'),
              ('dev', 'REPORT_ADMIN'),
              ('john', 'dev')])
-        self.assertEquals(['REPORT_ADMIN', 'WIKI_MODIFY'],
-                          sorted(self.store.get_user_permissions('john')))
+        self.assertEqual(['REPORT_ADMIN', 'WIKI_MODIFY'],
+                         sorted(self.store.get_user_permissions('john')))
 
     def test_nested_groups(self):
         self.env.db_transaction.executemany(
              ('dev', 'REPORT_ADMIN'),
              ('admin', 'dev'),
              ('john', 'admin')])
-        self.assertEquals(['REPORT_ADMIN', 'WIKI_MODIFY'],
-                          sorted(self.store.get_user_permissions('john')))
+        self.assertEqual(['REPORT_ADMIN', 'WIKI_MODIFY'],
+                         sorted(self.store.get_user_permissions('john')))
 
     def test_mixed_case_group(self):
         self.env.db_transaction.executemany(
              ('Dev', 'REPORT_ADMIN'),
              ('Admin', 'Dev'),
              ('john', 'Admin')])
-        self.assertEquals(['REPORT_ADMIN', 'WIKI_MODIFY'],
-                          sorted(self.store.get_user_permissions('john')))
+        self.assertEqual(['REPORT_ADMIN', 'WIKI_MODIFY'],
+                         sorted(self.store.get_user_permissions('john')))
 
     def test_builtin_groups(self):
         self.env.db_transaction.executemany(
             [('authenticated', 'WIKI_MODIFY'),
              ('authenticated', 'REPORT_ADMIN'),
              ('anonymous', 'TICKET_CREATE')])
-        self.assertEquals(['REPORT_ADMIN', 'TICKET_CREATE', 'WIKI_MODIFY'],
-                          sorted(self.store.get_user_permissions('john')))
-        self.assertEquals(['TICKET_CREATE'],
-                          self.store.get_user_permissions('anonymous'))
+        self.assertEqual(['REPORT_ADMIN', 'TICKET_CREATE', 'WIKI_MODIFY'],
+                         sorted(self.store.get_user_permissions('john')))
+        self.assertEqual(['TICKET_CREATE'],
+                         self.store.get_user_permissions('anonymous'))
 
     def test_get_all_permissions(self):
         self.env.db_transaction.executemany(
                     ('dev', 'REPORT_ADMIN'),
                     ('john', 'dev')]
         for res in self.store.get_all_permissions():
-            self.failIf(res not in expected)
+            self.assertFalse(res not in expected)
 
 
 class TestPermissionRequestor(Component):
         expected = [('bob', 'TEST_CREATE'),
                     ('jane', 'TEST_ADMIN')]
         for res in self.perm.get_all_permissions():
-            self.failIf(res not in expected)
+            self.assertFalse(res not in expected)
 
     def test_expand_actions_iter_7467(self):
         # Check that expand_actions works with iterators (#7467)
         self.env.reset_db()
 
     def test_contains(self):
-        self.assertEqual(True, 'TEST_MODIFY' in self.perm)
-        self.assertEqual(True, 'TEST_ADMIN' in self.perm)
-        self.assertEqual(False, 'TRAC_ADMIN' in self.perm)
+        self.assertTrue('TEST_MODIFY' in self.perm)
+        self.assertTrue('TEST_ADMIN' in self.perm)
+        self.assertFalse('TRAC_ADMIN' in self.perm)
 
     def test_has_permission(self):
-        self.assertEqual(True, self.perm.has_permission('TEST_MODIFY'))
-        self.assertEqual(True, self.perm.has_permission('TEST_ADMIN'))
-        self.assertEqual(False, self.perm.has_permission('TRAC_ADMIN'))
+        self.assertTrue(self.perm.has_permission('TEST_MODIFY'))
+        self.assertTrue(self.perm.has_permission('TEST_ADMIN'))
+        self.assertFalse(self.perm.has_permission('TRAC_ADMIN'))
 
     def test_require(self):
         self.perm.require('TEST_MODIFY')

File trac/ticket/tests/model.py

View file
 from trac.attachment import Attachment
 from trac.core import TracError, implements
 from trac.resource import ResourceNotFound
+from trac.tests import compat
 from trac.ticket.model import (
     Ticket, Component, Milestone, Priority, Type, Version
 )
         log = ticket3.get_changelog()
         self.assertEqual(len(log), 3)
         ok_vals = ['foo', 'summary', 'comment']
-        self.failUnless(log[0][2] in ok_vals)
-        self.failUnless(log[1][2] in ok_vals)
-        self.failUnless(log[2][2] in ok_vals)
+        self.assertIn(log[0][2], ok_vals)
+        self.assertIn(log[1][2], ok_vals)
+        self.assertIn(log[2][2], ok_vals)
 
     def test_create_ticket_5(self):
         ticket3 = self._modify_a_ticket()
         ticket.save_changes()
 
         for change in ticket.get_changelog():
-            self.assertEqual(None, change[1])
+            self.assertIsNone(change[1])
 
     def test_comment_with_whitespace_only_is_not_saved(self):
         ticket = Ticket(self.env)
         self.assertEqual('john', ticket['reporter'])
 
         # An unknown field
-        assert ticket['bar'] is None
+        self.assertIsNone(ticket['bar'])
 
         # Custom field
         self.assertEqual('bar', ticket['foo'])
         ticket.delete_change(cnum=4, when=t)
         self.assertEqual('a, b', ticket['keywords'])
         self.assertEqual('change3', ticket['foo'])
-        self.assertEqual(None, ticket.get_change(cnum=4))
-        self.assertNotEqual(None, ticket.get_change(cnum=3))
+        self.assertIsNone(ticket.get_change(cnum=4))
+        self.assertIsNotNone(ticket.get_change(cnum=3))
         self.assertEqual(t, ticket.time_changed)
 
     def test_delete_last_comment_when_custom_field_gone(self):
         ticket.delete_change(cnum=4, when=t)
         self.assertEqual('a, b', ticket['keywords'])
         # 'foo' is no longer defined for the ticket
-        self.assertEqual(None, ticket['foo'])
+        self.assertIsNone(ticket['foo'])
         # however, 'foo=change3' is still in the database
         self.assertEqual([('change3',)], self.env.db_query("""
             SELECT value FROM ticket_custom WHERE ticket=%s AND name='foo'
             """, (self.id,)))
-        self.assertEqual(None, ticket.get_change(cnum=4))
-        self.assertNotEqual(None, ticket.get_change(cnum=3))
+        self.assertIsNone(ticket.get_change(cnum=4))
+        self.assertIsNotNone(ticket.get_change(cnum=3))
         self.assertEqual(t, ticket.time_changed)
 
     def test_delete_last_comment_by_date(self):
         ticket.delete_change(cdate=self.t4, when=t)
         self.assertEqual('a, b', ticket['keywords'])
         self.assertEqual('change3', ticket['foo'])
-        self.assertEqual(None, ticket.get_change(cdate=self.t4))
-        self.assertNotEqual(None, ticket.get_change(cdate=self.t3))
+        self.assertIsNone(ticket.get_change(cdate=self.t4))
+        self.assertIsNotNone(ticket.get_change(cdate=self.t3))
         self.assertEqual(t, ticket.time_changed)
 
     def test_delete_mid_comment(self):
             foo=dict(author='joe', old='change3', new='change4'))
         t = datetime.now(utc)
         ticket.delete_change(cnum=3, when=t)
-        self.assertEqual(None, ticket.get_change(cnum=3))
+        self.assertIsNone(ticket.get_change(cnum=3))
         self.assertEqual('a', ticket['keywords'])
         self.assertChange(ticket, 4, self.t4, 'joe',
             comment=dict(author='joe', old='4', new='Comment 4'),
             foo=dict(author='joe', old='change3', new='change4'))
         t = datetime.now(utc)
         ticket.delete_change(cdate=self.t3, when=t)
-        self.assertEqual(None, ticket.get_change(cdate=self.t3))
+        self.assertIsNone(ticket.get_change(cdate=self.t3))
         self.assertEqual('a', ticket['keywords'])
         self.assertChange(ticket, 4, self.t4, 'joe',
             comment=dict(author='joe', old='4', new='Comment 4'),
             keywords=dict(author='joe', old='1, 2', new='a'),
             foo=dict(author='joe', old='change3', new='change4'))
         ticket.delete_change(3)
-        self.assertEqual(None, ticket.get_change(3))
+        self.assertIsNone(ticket.get_change(3))
         self.assertEqual('a', ticket['keywords'])
         self.assertChange(ticket, 4, self.t4, 'joe',
             comment=dict(author='joe', old='4', new='Comment 4'),
         prio = Priority(self.env)
         prio.name = 'foo'
         prio.insert()
-        self.assertEqual(True, prio.exists)
+        self.assertTrue(prio.exists)
 
     def test_priority_insert_with_value(self):
         prio = Priority(self.env)
         prio.name = 'bar'
         prio.value = 100
         prio.insert()
-        self.assertEqual(True, prio.exists)
+        self.assertTrue(prio.exists)
 
     def test_priority_update(self):
         prio = Priority(self.env, 'major')
         prio = Priority(self.env, 'major')
         self.assertEqual('3', prio.value)
         prio.delete()
-        self.assertEqual(False, prio.exists)
+        self.assertFalse(prio.exists)
         self.assertRaises(TracError, Priority, self.env, 'major')
         prio = Priority(self.env, 'minor')
         self.assertEqual('3', prio.value)
 
     def test_new_milestone(self):
         milestone = Milestone(self.env)
-        self.assertEqual(False, milestone.exists)
-        self.assertEqual(None, milestone.name)
-        self.assertEqual(None, milestone.due)
-        self.assertEqual(None, milestone.completed)
+        self.assertFalse(milestone.exists)
+        self.assertIsNone(milestone.name)
+        self.assertIsNone(milestone.due)
+        self.assertIsNone(milestone.completed)
         self.assertEqual('', milestone.description)
 
     def test_new_milestone_empty_name(self):
         milestone being correctly detected as non-existent.
         """
         milestone = Milestone(self.env, '')
-        self.assertEqual(False, milestone.exists)
-        self.assertEqual(None, milestone.name)
-        self.assertEqual(None, milestone.due)
-        self.assertEqual(None, milestone.completed)
+        self.assertFalse(milestone.exists)
+        self.assertIsNone(milestone.name)
+        self.assertIsNone(milestone.due)
+        self.assertIsNone(milestone.completed)
         self.assertEqual('', milestone.description)
 
     def test_existing_milestone(self):
         self.env.db_transaction("INSERT INTO milestone (name) VALUES ('Test')")
 
         milestone = Milestone(self.env, 'Test')
-        self.assertEqual(True, milestone.exists)
+        self.assertTrue(milestone.exists)
         self.assertEqual('Test', milestone.name)
-        self.assertEqual(None, milestone.due)
-        self.assertEqual(None, milestone.completed)
+        self.assertIsNone(milestone.due)
+        self.assertIsNone(milestone.completed)
         self.assertEqual('', milestone.description)
 
     def test_create_and_update_milestone(self):
 
         milestone = Milestone(self.env, 'Test')
         milestone.delete()
-        self.assertEqual(False, milestone.exists)
+        self.assertFalse(milestone.exists)
         self.assertEqual([],
             self.env.db_query("SELECT * FROM milestone WHERE name='Test'"))
 
 
         milestone = Milestone(self.env, 'Test')
         milestone.delete(retarget_to='Other')
-        self.assertEqual(False, milestone.exists)
+        self.assertFalse(milestone.exists)
 
         self.assertEqual('Other', Ticket(self.env, tkt1.id)['milestone'])
         self.assertEqual('Other', Ticket(self.env, tkt2.id)['milestone'])
 
         milestones = list(Milestone.select(self.env))
         self.assertEqual('1.0', milestones[0].name)
-        assert milestones[0].exists
+        self.assertTrue(milestones[0].exists)
         self.assertEqual('2.0', milestones[1].name)
-        assert milestones[1].exists
+        self.assertTrue(milestones[1].exists)
 
     def test_change_listener_created(self):
         listener = TestMilestoneChangeListener(self.env)
         listener = TestMilestoneChangeListener(self.env)
         milestone = self._create_milestone(name='Milestone 1')
         milestone.insert()
-        self.assertEqual(True, milestone.exists)
+        self.assertTrue(milestone.exists)
         milestone.delete()
         self.assertEqual('Milestone 1', milestone.name)
-        self.assertEqual(False, milestone.exists)
+        self.assertFalse(milestone.exists)
         self.assertEqual('deleted', listener.action)
         self.assertEqual(milestone, listener.milestone)
 

File trac/ticket/tests/notification.py

View file
         # checks there is no duplicate in the recipient list
         rcpts = []
         for r in recipients:
-            self.failIf(r in rcpts)
+            self.assertFalse(r in rcpts)
             rcpts.append(r)
         # checks that all cc recipients have been notified
         cc_list = self.env.config.get('notification', 'smtp_always_cc')
         cc_list = "%s, %s" % (cc_list, ticket['cc'])
         for r in cc_list.replace(',', ' ').split():
-            self.failIf(r not in recipients)
+            self.assertFalse(r not in recipients)
         # checks that owner has been notified
-        self.failIf(smtp_address(ticket['owner']) not in recipients)
+        self.assertFalse(smtp_address(ticket['owner']) not in recipients)
         # checks that reporter has been notified
-        self.failIf(smtp_address(ticket['reporter']) not in recipients)
+        self.assertFalse(smtp_address(ticket['reporter']) not in recipients)
 
     def test_no_recipient(self):
         """No recipient case"""
         recipients = notifysuite.smtpd.get_recipients()
         message = notifysuite.smtpd.get_message()
         # checks that no message has been sent
-        self.failIf(recipients)
-        self.failIf(sender)
-        self.failIf(message)
+        self.assertFalse(recipients)
+        self.assertFalse(sender)
+        self.assertFalse(message)
 
     def test_cc_only(self):
         """Notification w/o explicit recipients but Cc: (#3101)"""
         # checks that all cc recipients have been notified
         cc_list = self.env.config.get('notification', 'smtp_always_cc')
         for r in cc_list.replace(',', ' ').split():
-            self.failIf(r not in recipients)
+            self.assertFalse(r not in recipients)
 
     def test_structure(self):
         """Basic SMTP message structure (headers, body)"""
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
         # checks for header existence
-        self.failIf(not headers)
+        self.assertFalse(not headers)
         # checks for body existance
-        self.failIf(not body)
+        self.assertFalse(not body)
         # checks for expected headers
-        self.failIf('Date' not in headers)
-        self.failIf('Subject' not in headers)
-        self.failIf('Message-ID' not in headers)
-        self.failIf('From' not in headers)
+        self.assertFalse('Date' not in headers)
+        self.assertFalse('Subject' not in headers)
+        self.assertFalse('Message-ID' not in headers)
+        self.assertFalse('From' not in headers)
 
     def test_date(self):
         """Date format compliance (RFC822)
         tn.notify(ticket, newticket=True)
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
-        self.failIf('Date' not in headers)
+        self.assertFalse('Date' not in headers)
         mo = date_re.match(headers['Date'])
-        self.failIf(not mo)
+        self.assertFalse(not mo)
         if mo.group('day'):
-            self.failIf(mo.group('day') not in days)
-        self.failIf(int(mo.group('dm')) not in range(1, 32))
-        self.failIf(mo.group('month') not in months)
-        self.failIf(int(mo.group('hour')) not in range(0, 24))
+            self.assertFalse(mo.group('day') not in days)
+        self.assertFalse(int(mo.group('dm')) not in range(1, 32))
+        self.assertFalse(mo.group('month') not in months)
+        self.assertFalse(int(mo.group('hour')) not in range(0, 24))
         if mo.group('tz'):
-            self.failIf(mo.group('tz') not in tz)
+            self.assertFalse(mo.group('tz') not in tz)
 
     def test_bcc_privacy(self):
         """Visibility of recipients"""
             (headers, body) = parse_smtp_message(message)
             if public:
                 # Msg should have a To list
-                self.failIf('To' not in headers)
+                self.assertFalse('To' not in headers)
                 # Extract the list of 'To' recipients from the message
                 to = [rcpt.strip() for rcpt in headers['To'].split(',')]
             else:
                 # Msg should not have a To list
-                self.failIf('To' in headers)
+                self.assertFalse('To' in headers)
                 # Extract the list of 'To' recipients from the message
                 to = []
             # Extract the list of 'Cc' recipients from the message
             for rcpt in cclist:
                 # Each recipient of the 'Cc' list should appear
                 # in the 'Cc' header
-                self.failIf(rcpt not in cc)
+                self.assertFalse(rcpt not in cc)
                 # Check the message has actually been sent to the recipients
-                self.failIf(rcpt not in rcptlist)
+                self.assertFalse(rcpt not in rcptlist)
             # Build the list of the expected 'Bcc' recipients
             bccrcpt = self.env.config.get('notification', 'smtp_always_bcc')
             bcclist = [bccr.strip() for bccr in bccrcpt.split(',')]
             for rcpt in bcclist:
                 # Check none of the 'Bcc' recipients appears
                 # in the 'To' header
-                self.failIf(rcpt in to)
+                self.assertFalse(rcpt in to)
                 # Check the message has actually been sent to the recipients
-                self.failIf(rcpt not in rcptlist)
+                self.assertFalse(rcpt not in rcptlist)
         run_bcc_feature(True)
         run_bcc_feature(False)
 
             (headers, body) = parse_smtp_message(message)
             # Msg should not have a 'To' header
             if not enabled:
-                self.failIf('To' in headers)
+                self.assertFalse('To' in headers)
             else:
                 tolist = [addr.strip() for addr in headers['To'].split(',')]
             # Msg should have a 'Cc' field
-            self.failIf('Cc' not in headers)
+            self.assertFalse('Cc' not in headers)
             cclist = [addr.strip() for addr in headers['Cc'].split(',')]
             if enabled:
                 # Msg should be delivered to the reporter
-                self.failIf(ticket['reporter'] not in tolist)
+                self.assertFalse(ticket['reporter'] not in tolist)
             else:
                 # Msg should not be delivered to joeuser
-                self.failIf(ticket['reporter'] in cclist)
+                self.assertFalse(ticket['reporter'] in cclist)
             # Msg should still be delivered to the always_cc list
-            self.failIf(self.env.config.get('notification',
+            self.assertFalse(self.env.config.get('notification',
                         'smtp_always_cc') not in cclist)
         # Validate with and without the short addr option enabled
         for enable in [False, True]:
             message = notifysuite.smtpd.get_message()
             (headers, body) = parse_smtp_message(message)
             # Msg should always have a 'Cc' field
-            self.failIf('Cc' not in headers)
+            self.assertFalse('Cc' not in headers)
             cclist = [addr.strip() for addr in headers['Cc'].split(',')]
-            self.failIf('joewithdom@example.com' not in cclist)
-            self.failIf('joe.bar@example.net' not in cclist)
+            self.assertFalse('joewithdom@example.com' not in cclist)
+            self.assertFalse('joe.bar@example.net' not in cclist)
             if not enabled:
-                self.failIf(len(cclist) != 2)
-                self.failIf('joenodom' in cclist)
+                self.assertFalse(len(cclist) != 2)
+                self.assertFalse('joenodom' in cclist)
             else:
-                self.failIf(len(cclist) != 3)
-                self.failIf('joenodom@example.org' not in cclist)
+                self.assertFalse(len(cclist) != 3)
+                self.assertFalse('joenodom@example.org' not in cclist)
 
         # Validate with and without a default domain
         for enable in [False, True]:
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
         # Msg should always have a 'To' field
-        self.failIf('To' not in headers)
+        self.assertFalse('To' not in headers)
         tolist = [addr.strip() for addr in headers['To'].split(',')]
         # 'To' list should have been resolved to the real email address
-        self.failIf('user-joe@example.com' not in tolist)
-        self.failIf('user-jim@example.com' not in tolist)
-        self.failIf('joeuser' in tolist)
-        self.failIf('jim@domain' in tolist)
+        self.assertFalse('user-joe@example.com' not in tolist)
+        self.assertFalse('user-jim@example.com' not in tolist)
+        self.assertFalse('joeuser' in tolist)
+        self.assertFalse('jim@domain' in tolist)
 
     def test_from_author(self):
         """Using the reporter or change author as the notification sender"""
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
         # Msg should always have a 'To' field
-        self.failIf('To' not in headers)
+        self.assertFalse('To' not in headers)
         tolist = [addr.strip() for addr in headers['To'].split(',')]
         # 'To' list should not contain addresses with non-SMTP domains
-        self.failIf('kerberos@example.com' in tolist)
-        self.failIf('kerberos@example.org' in tolist)
+        self.assertFalse('kerberos@example.com' in tolist)
+        self.assertFalse('kerberos@example.org' in tolist)
         # 'To' list should have been resolved to the actual email address
-        self.failIf('kerb@example.net' not in tolist)
-        self.failIf(len(tolist) != 1)
+        self.assertFalse('kerb@example.net' not in tolist)
+        self.assertFalse(len(tolist) != 1)
 
     def test_admit_domains(self):
         """SMTP domain inclusion"""
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
         # Msg should always have a 'To' field
-        self.failIf('Cc' not in headers)
+        self.assertFalse('Cc' not in headers)
         cclist = [addr.strip() for addr in headers['Cc'].split(',')]
         # 'Cc' list should contain addresses with SMTP included domains
-        self.failIf('joe.user@localdomain' not in cclist)
-        self.failIf('joe.user@server' not in cclist)
+        self.assertFalse('joe.user@localdomain' not in cclist)
+        self.assertFalse('joe.user@server' not in cclist)
         # 'Cc' list should not contain non-FQDN domains
-        self.failIf('joe.user@unknown' in cclist)
-        self.failIf(len(cclist) != 2+2)
+        self.assertFalse('joe.user@unknown' in cclist)
+        self.assertFalse(len(cclist) != 2+2)
 
     def test_multiline_header(self):
         """Encoded headers split into multiple lines"""
         # Discards the project name & ticket number
         subject = headers['Subject']
         summary = subject[subject.find(':')+2:]
-        self.failIf(ticket['summary'] != summary)
+        self.assertFalse(ticket['summary'] != summary)
 
     def test_mimebody_b64(self):
         """MIME Base64/utf-8 encoding"""
             message = notifysuite.smtpd.get_message()
             (headers, body) = parse_smtp_message(message)
             # checks for header existence
-            self.failIf(not headers)
+            self.assertFalse(not headers)
             # checks for updater in the 'To' recipient list
-            self.failIf('To' not in headers)
+            self.assertFalse('To' not in headers)
             tolist = [addr.strip() for addr in headers['To'].split(',')]
             if disable:
-                self.failIf('joe.bar2@example.com' in tolist)
+                self.assertFalse('joe.bar2@example.com' in tolist)
             else:
-                self.failIf('joe.bar2@example.com' not in tolist)
+                self.assertFalse('joe.bar2@example.com' not in tolist)
 
         # Validate with and without a default domain
         for disable in [False, True]:
         tn = TicketNotifyEmail(self.env)
         tn.notify(ticket, newticket=True)
         recipients = notifysuite.smtpd.get_recipients()
-        self.failIf(recipients is None)
-        self.failIf(len(recipients) != 1)
-        self.failIf(recipients[0] != 'joe@example.com')
+        self.assertFalse(recipients is None)
+        self.assertFalse(len(recipients) != 1)
+        self.assertFalse(recipients[0] != 'joe@example.com')
 
     def test_updater_is_reporter(self):
         """Notification to reporter w/ updater option disabled (#3780)"""
         tn = TicketNotifyEmail(self.env)
         tn.notify(ticket, newticket=True)
         recipients = notifysuite.smtpd.get_recipients()
-        self.failIf(recipients is None)
-        self.failIf(len(recipients) != 1)
-        self.failIf(recipients[0] != 'joe@example.org')
+        self.assertFalse(recipients is None)
+        self.assertFalse(len(recipients) != 1)
+        self.assertFalse(recipients[0] != 'joe@example.org')
 
     def _validate_mimebody(self, mime, ticket, newtk):
         """Body of a ticket notification message"""
         tn.notify(ticket, newticket=newtk)
         message = notifysuite.smtpd.get_message()
         (headers, body) = parse_smtp_message(message)
-        self.failIf('MIME-Version' not in headers)
-        self.failIf('Content-Type' not in headers)
-        self.failIf('Content-Transfer-Encoding' not in headers)
-        self.failIf(not re.compile(r"1.\d").match(headers['MIME-Version']))
+        self.assertFalse('MIME-Version' not in headers)
+        self.assertFalse('Content-Type' not in headers)
+        self.assertFalse('Content-Transfer-Encoding' not in headers)
+        self.assertFalse(not re.compile(r"1.\d").match(headers['MIME-Version']))
         type_re = re.compile(r'^text/plain;\scharset="([\w\-\d]+)"$')
         charset = type_re.match(headers['Content-Type'])
-        self.failIf(not charset)
+        self.assertFalse(not charset)
         charset = charset.group(1)
         self.assertEqual(charset, mime_charset)
         self.assertEqual(headers['Content-Transfer-Encoding'], mime_name)
         # checks the width of each body line
         for line in body.splitlines():
-            self.failIf(len(line) > MAXBODYWIDTH)
+            self.assertFalse(len(line) > MAXBODYWIDTH)
         # attempts to decode the body, following the specified MIME endoding
         # and charset
         try:
         while ( not banner_delim_re.match(bodylines[0]) ):
             bodyheader.append(bodylines.pop(0))
         # summary should be present
-        self.failIf(not bodyheader)
+        self.assertFalse(not bodyheader)
         # banner should not be empty
-        self.failIf(not bodylines)
+        self.assertFalse(not bodylines)
         # extracts the ticket ID from the first line
         (tknum, bodyheader[0]) = bodyheader[0].split(' ', 1)
         self.assertEqual(tknum[0], '#')
         summary = ' '.join(bodyheader)
         self.assertEqual(summary, ticket['summary'])
         # now checks the banner contents
-        self.failIf(not banner_delim_re.match(bodylines[0]))
+        self.assertFalse(not banner_delim_re.match(bodylines[0]))
         banner = True
         footer = None
         props = {}
             if footer != None:
                 footer += 1
                 # invalid footer detection
-                self.failIf(footer > 3)
+                self.assertFalse(footer > 3)
                 # check ticket link
                 if line[:11] == 'Ticket URL:':
                     ticket_link = self.env.abs_href.ticket(ticket.id)
         xlist = ['summary', 'description', 'comment', 'time', 'changetime']
         # check banner content (field exists, msg value matches ticket value)
         for p in [prop for prop in ticket.values.keys() if prop not in xlist]:
-            self.failIf(not props.has_key(p))
+            self.assertFalse(not props.has_key(p))
             # Email addresses might be obfuscated
             if '@' in ticket[p] and '@' in props[p]:
-                self.failIf(props[p].split('@')[0] != ticket[p].split('@')[0])
+                self.assertFalse(props[p].split('@')[0] != ticket[p].split('@')[0])
             else:
-                self.failIf(props[p] != ticket[p])
+                self.assertFalse(props[p] != ticket[p])
 
     def test_props_format_ambiwidth_single(self):
         self.env.config.set('notification', 'mime_encoding', 'none')

File trac/ticket/tests/roadmap.py

View file
         self.stats = TicketGroupStats('title', 'units')
 
     def test_init(self):
-        self.assertEquals('title', self.stats.title, 'title incorrect')
-        self.assertEquals('units', self.stats.unit, 'unit incorrect')
-        self.assertEquals(0, self.stats.count, 'count not zero')
-        self.assertEquals(0, len(self.stats.intervals), 'intervals not empty')
+        self.assertEqual('title', self.stats.title, 'title incorrect')
+        self.assertEqual('units', self.stats.unit, 'unit incorrect')
+        self.assertEqual(0, self.stats.count, 'count not zero')
+        self.assertEqual(0, len(self.stats.intervals), 'intervals not empty')
 
     def test_add_iterval(self):
         self.stats.add_interval('intTitle', 3, {'k1': 'v1'}, 'css', 0)
         self.stats.refresh_calcs()
-        self.assertEquals(3, self.stats.count, 'count not incremented')
+        self.assertEqual(3, self.stats.count, 'count not incremented')
         int = self.stats.intervals[0]
-        self.assertEquals('intTitle', int['title'], 'title incorrect')
-        self.assertEquals(3, int['count'], 'count incorrect')
-        self.assertEquals({'k1': 'v1'}, int['qry_args'], 'query args incorrect')
-        self.assertEquals('css', int['css_class'], 'css class incorrect')
-        self.assertEquals(100, int['percent'], 'percent incorrect')
+        self.assertEqual('intTitle', int['title'], 'title incorrect')
+        self.assertEqual(3, int['count'], 'count incorrect')
+        self.assertEqual({'k1': 'v1'}, int['qry_args'], 'query args incorrect')
+        self.assertEqual('css', int['css_class'], 'css class incorrect')
+        self.assertEqual(100, int['percent'], 'percent incorrect')
         self.stats.add_interval('intTitle', 3, {'k1': 'v1'}, 'css', 0)
         self.stats.refresh_calcs()
-        self.assertEquals(50, int['percent'], 'percent not being updated')
+        self.assertEqual(50, int['percent'], 'percent not being updated')
 
     def test_add_interval_no_prog(self):
         self.stats.add_interval('intTitle', 3, {'k1': 'v1'}, 'css', 0)
         self.stats.add_interval('intTitle', 5, {'k1': 'v1'}, 'css', 0)
         self.stats.refresh_calcs()
         interval = self.stats.intervals[1]
-        self.assertEquals(0, self.stats.done_count, 'count added for no prog')
-        self.assertEquals(0, self.stats.done_percent, 'percent incremented')
+        self.assertEqual(0, self.stats.done_count, 'count added for no prog')
+        self.assertEqual(0, self.stats.done_percent, 'percent incremented')
 
     def test_add_interval_prog(self):
         self.stats.add_interval('intTitle', 3, {'k1': 'v1'}, 'css', 0)
         self.stats.add_interval('intTitle', 1, {'k1': 'v1'}, 'css', 1)
         self.stats.refresh_calcs()
-        self.assertEquals(4, self.stats.count, 'count not incremented')
-        self.assertEquals(1, self.stats.done_count, 'count not added to prog')
-        self.assertEquals(25, self.stats.done_percent, 'done percent not incr')
+        self.assertEqual(4, self.stats.count, 'count not incremented')
+        self.assertEqual(1, self.stats.done_count, 'count not added to prog')
+        self.assertEqual(25, self.stats.done_percent, 'done percent not incr')
 
     def test_add_interval_fudging(self):
         self.stats.add_interval('intTitle', 3, {'k1': 'v1'}, 'css', 0)
         self.stats.add_interval('intTitle', 5, {'k1': 'v1'}, 'css', 1)
         self.stats.refresh_calcs()
-        self.assertEquals(8, self.stats.count, 'count not incremented')
-        self.assertEquals(5, self.stats.done_count, 'count not added to prog')
-        self.assertEquals(62, self.stats.done_percent,
-                          'done percnt not fudged downward')
-        self.assertEquals(62, self.stats.intervals[1]['percent'],
-                          'interval percent not fudged downward')
-        self.assertEquals(38, self.stats.intervals[0]['percent'],
-                          'interval percent not fudged upward')
+        self.assertEqual(8, self.stats.count, 'count not incremented')
+        self.assertEqual(5, self.stats.done_count, 'count not added to prog')
+        self.assertEqual(62, self.stats.done_percent,
+                         'done percnt not fudged downward')
+        self.assertEqual(62, self.stats.intervals[1]['percent'],
+                         'interval percent not fudged downward')
+        self.assertEqual(38, self.stats.intervals[0]['percent'],
+                         'interval percent not fudged upward')
 
 
 class DefaultTicketGroupStatsProviderTestCase(unittest.TestCase):
         self.env.reset_db()
 
     def test_stats(self):
-        self.assertEquals(self.stats.title, 'ticket status', 'title incorrect')
-        self.assertEquals(self.stats.unit, 'tickets', 'unit incorrect')
-        self.assertEquals(2, len(self.stats.intervals), 'more than 2 intervals')
+        self.assertEqual(self.stats.title, 'ticket status', 'title incorrect')