Rev 4761: Update _static_tuple_py.py with the same concatenation behavior in http://bazaar.launchpad.net/~jameinel/bzr/2.1-st-concat
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 21 04:49:20 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-st-concat
------------------------------------------------------------
revno: 4761
revision-id: john at arbash-meinel.com-20091021034903-0ut5l1rxnlrdjdi4
parent: john at arbash-meinel.com-20091021034136-kj285v0bd7g92wb6
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-st-concat
timestamp: Tue 2009-10-20 22:49:03 -0500
message:
Update _static_tuple_py.py with the same concatenation behavior
And add some tests that it works like we want.
-------------- next part --------------
=== modified file 'bzrlib/_static_tuple_py.py'
--- a/bzrlib/_static_tuple_py.py 2009-10-13 18:00:16 +0000
+++ b/bzrlib/_static_tuple_py.py 2009-10-21 03:49:03 +0000
@@ -45,6 +45,10 @@
def __repr__(self):
return '%s%s' % (self.__class__.__name__, tuple.__repr__(self))
+ def __add__(self, other):
+ """Concatenate self with other"""
+ return StaticTuple.from_sequence(tuple.__add__(self,other))
+
def as_tuple(self):
return self
=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py 2009-10-17 00:34:28 +0000
+++ b/bzrlib/tests/test__static_tuple.py 2009-10-21 03:49:03 +0000
@@ -105,6 +105,42 @@
self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
# not a string
self.assertRaises(TypeError, self.module.StaticTuple, 10)
+
+ def test_concat(self):
+ st1 = self.module.StaticTuple('foo')
+ st2 = self.module.StaticTuple('bar')
+ st3 = self.module.StaticTuple('foo', 'bar')
+ st4 = st1 + st2
+ self.assertEqual(st3, st4)
+ self.assertIsInstance(st4, self.module.StaticTuple)
+
+ def test_concat_with_tuple(self):
+ st1 = self.module.StaticTuple('foo')
+ t2 = ('bar',)
+ st3 = self.module.StaticTuple('foo', 'bar')
+ st4 = self.module.StaticTuple('bar', 'foo')
+ st5 = st1 + t2
+ st6 = t2 + st1
+ self.assertEqual(st3, st5)
+ self.assertIsInstance(st5, self.module.StaticTuple)
+ self.assertEqual(st4, st6)
+ if self.module is _static_tuple_py:
+ # _static_tuple_py has StaticTuple(tuple), so tuple thinks it
+ # already knows how to concatenate, as such we can't "inject" our
+ # own concatenation...
+ self.assertIsInstance(st6, tuple)
+ else:
+ self.assertIsInstance(st6, self.module.StaticTuple)
+
+ def test_concat_with_bad_tuple(self):
+ st1 = self.module.StaticTuple('foo')
+ t2 = (object(),)
+ try:
+ st3 = st1 + t2
+ except TypeError:
+ pass
+ else:
+ self.fail('TypeError not raised')
def test_as_tuple(self):
k = self.module.StaticTuple('foo')
More information about the bazaar-commits
mailing list