[patch] add assertIsInstance

Martin Pool mbp at sourcefrog.net
Sun Feb 26 17:36:31 GMT 2006


Pretty tiny patch to add another testcase helper.

-- 
Martin
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py	
+++ bzrlib/tests/__init__.py	
@@ -326,6 +326,11 @@
         actual_mode = stat.S_IMODE(path_stat.st_mode)
         self.assertEqual(mode, actual_mode,
             'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
+
+    def assertIsInstance(self, obj, kls):
+        """Fail if obj is not an instance of kls"""
+        if not isinstance(obj, kls):
+            self.fail("%r is not an instance of %s" % (obj, kls))
 
     def _startLogFile(self):
         """Send bzr and test log messages to a temporary file.

=== modified file 'bzrlib/tests/test_selftest.py'
--- bzrlib/tests/test_selftest.py	
+++ bzrlib/tests/test_selftest.py	
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 by Canonical Ltd
+# Copyright (C) 2005, 2006 by Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2 as published by
@@ -402,3 +402,13 @@
         t = get_transport(self.get_readonly_url())
         url = t.base
         self.assertEqual(url, t.clone('..').base)
+
+
+class TestExtraAssertions(TestCase):
+    """Tests for new test assertions in bzrlib test suite"""
+
+    def test_assert_isinstance(self):
+        self.assertIsInstance(2, int)
+        self.assertIsInstance(u'', basestring)
+        self.assertRaises(AssertionError, self.assertIsInstance, None, int)
+        self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060226/e5199772/attachment.pgp 


More information about the bazaar mailing list