~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__static_tuple.py

  • Committer: John Arbash Meinel
  • Date: 2009-11-28 21:54:08 UTC
  • mto: This revision was merged to the branch mainline in revision 4842.
  • Revision ID: john@arbash-meinel.com-20091128215408-d9jtxbxyiklmiurh
Add a static_tuple.as_tuples() helper.

It will pass over an iterable, and ensure that it and all children
are simple tuples. Useful for formatting.
Also fix a small bug in the reference checking code that assumes
the values passed in are the same type, but sometimes they are a
list rather than a tuple.

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
        k = self.module.StaticTuple('foo')
149
149
        t = k.as_tuple()
150
150
        self.assertEqual(('foo',), t)
 
151
        self.assertIsInstance(t, tuple)
 
152
        self.assertFalse(isinstance(t, self.module.StaticTuple))
151
153
        k = self.module.StaticTuple('foo', 'bar')
152
154
        t = k.as_tuple()
153
155
        self.assertEqual(('foo', 'bar'), t)
 
156
        k2 = self.module.StaticTuple(1, k)
 
157
        t = k2.as_tuple()
 
158
        self.assertIsInstance(t, tuple)
 
159
        # For pickling to work, we need to keep the sub-items as StaticTuple so
 
160
        # that it knows that they also need to be converted.
 
161
        self.assertIsInstance(t[1], self.module.StaticTuple)
 
162
        self.assertEqual((1, ('foo', 'bar')), t)
 
163
 
 
164
    def test_as_tuples(self):
 
165
        k1 = self.module.StaticTuple('foo', 'bar')
 
166
        t = static_tuple.as_tuples(k1)
 
167
        self.assertIsInstance(t, tuple)
 
168
        self.assertEqual(('foo', 'bar'), t)
 
169
        k2 = self.module.StaticTuple(1, k1)
 
170
        t = static_tuple.as_tuples(k2)
 
171
        self.assertIsInstance(t, tuple)
 
172
        self.assertIsInstance(t[1], tuple)
 
173
        self.assertEqual((1, ('foo', 'bar')), t)
 
174
        mixed = (1, k1)
 
175
        t = static_tuple.as_tuples(mixed)
 
176
        self.assertIsInstance(t, tuple)
 
177
        self.assertIsInstance(t[1], tuple)
 
178
        self.assertEqual((1, ('foo', 'bar')), t)
154
179
 
155
180
    def test_len(self):
156
181
        k = self.module.StaticTuple()