Rev 4145: (robertc) New assertLength method based on one Martin has squirreled in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Mar 16 02:40:49 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4145
revision-id: pqm at pqm.ubuntu.com-20090316024046-58qc87pfdgu2ugok
parent: pqm at pqm.ubuntu.com-20090313062142-ndr3o27uwgysx9dv
parent: robertc at robertcollins.net-20090316015618-rnbq60s0w5rr8ta8
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-03-16 02:40:46 +0000
message:
(robertc) New assertLength method based on one Martin has squirreled
away somewhere. (Robert Collins, Martin Pool)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
------------------------------------------------------------
revno: 4144.1.1
revision-id: robertc at robertcollins.net-20090316015618-rnbq60s0w5rr8ta8
parent: pqm at pqm.ubuntu.com-20090313062142-ndr3o27uwgysx9dv
committer: Robert Collins <robertc at robertcollins.net>
branch nick: assertLength
timestamp: Mon 2009-03-16 12:56:18 +1100
message:
New assertLength method based on one Martin has squirreled away somewhere.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
=== modified file 'NEWS'
--- a/NEWS 2009-03-13 05:05:50 +0000
+++ b/NEWS 2009-03-16 01:56:18 +0000
@@ -69,6 +69,9 @@
INTERNALS:
+ * New ``assertLength`` method based on one Martin has squirreled away
+ somewhere. (Robert Collins, Martin Pool)
+
bzr 1.13rc1 "paraskavedekatriaphobia" 2009-03-10
------------------------------------------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-03-12 12:00:49 +0000
+++ b/bzrlib/tests/__init__.py 2009-03-16 01:56:18 +0000
@@ -902,6 +902,12 @@
self.assertEqual(expected.st_ino, actual.st_ino)
self.assertEqual(expected.st_mode, actual.st_mode)
+ def assertLength(self, length, obj_with_len):
+ """Assert that obj_with_len is of length length."""
+ if len(obj_with_len) != length:
+ self.fail("Incorrect length: wanted %d, got %d for %r" % (
+ length, len(obj_with_len), obj_with_len))
+
def assertPositive(self, val):
"""Assert that val is greater than 0."""
self.assertTrue(val > 0, 'expected a positive value, but got %s' % val)
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2009-03-07 06:58:17 +0000
+++ b/bzrlib/tests/test_selftest.py 2009-03-16 01:56:18 +0000
@@ -1352,6 +1352,25 @@
class TestTestCase(TestCase):
"""Tests that test the core bzrlib TestCase."""
+ def test_assertLength_matches_empty(self):
+ a_list = []
+ self.assertLength(0, a_list)
+
+ def test_assertLength_matches_nonempty(self):
+ a_list = [1, 2, 3]
+ self.assertLength(3, a_list)
+
+ def test_assertLength_fails_different(self):
+ a_list = []
+ self.assertRaises(AssertionError, self.assertLength, 1, a_list)
+
+ def test_assertLength_shows_sequence_in_failure(self):
+ a_list = [1, 2, 3]
+ exception = self.assertRaises(AssertionError, self.assertLength, 2,
+ a_list)
+ self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
+ exception.args[0])
+
def test_debug_flags_sanitised(self):
"""The bzrlib debug flags should be sanitised by setUp."""
if 'allow_debug' in tests.selftest_debug_flags:
More information about the bazaar-commits
mailing list