~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack.py

  • Committer: Patch Queue Manager
  • Date: 2012-10-25 11:13:27 UTC
  • mfrom: (6570.1.6 rubberstamp)
  • Revision ID: pqm@pqm.ubuntu.com-20121025111327-p0ylql0nh9fla0rs
(gz) Set approved revision and vote "Approve" when using lp-propose
 --approve (Jonathan Lange)

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
            errors.InvalidRecordError,
65
65
            serialiser.bytes_record, 'bytes', [('bad name',)])
66
66
 
 
67
    def test_bytes_record_header(self):
 
68
        serialiser = pack.ContainerSerialiser()
 
69
        record = serialiser.bytes_header(32, [('name1',), ('name2',)])
 
70
        self.assertEqual('B32\nname1\nname2\n\n', record)
 
71
 
67
72
 
68
73
class TestContainerWriter(tests.TestCase):
69
74
 
70
75
    def setUp(self):
71
 
        tests.TestCase.setUp(self)
 
76
        super(TestContainerWriter, self).setUp()
72
77
        self.output = StringIO()
73
78
        self.writer = pack.ContainerWriter(self.output.write)
74
79
 
126
131
    def test_add_bytes_record_one_name(self):
127
132
        """Add a bytes record with one name."""
128
133
        self.writer.begin()
 
134
 
129
135
        offset, length = self.writer.add_bytes_record(
130
136
            'abc', names=[('name1', )])
131
137
        self.assertEqual((42, 13), (offset, length))
133
139
            'Bazaar pack format 1 (introduced in 0.18)\n'
134
140
            'B3\nname1\n\nabc')
135
141
 
 
142
    def test_add_bytes_record_split_writes(self):
 
143
        """Write a large record which does multiple IOs"""
 
144
 
 
145
        writes = []
 
146
        real_write = self.writer.write_func
 
147
 
 
148
        def record_writes(bytes):
 
149
            writes.append(bytes)
 
150
            return real_write(bytes)
 
151
 
 
152
        self.writer.write_func = record_writes
 
153
        self.writer._JOIN_WRITES_THRESHOLD = 2
 
154
 
 
155
        self.writer.begin()
 
156
        offset, length = self.writer.add_bytes_record(
 
157
            'abcabc', names=[('name1', )])
 
158
        self.assertEqual((42, 16), (offset, length))
 
159
        self.assertOutput(
 
160
            'Bazaar pack format 1 (introduced in 0.18)\n'
 
161
            'B6\nname1\n\nabcabc')
 
162
 
 
163
        self.assertEquals([
 
164
            'Bazaar pack format 1 (introduced in 0.18)\n',
 
165
            'B6\nname1\n\n',
 
166
            'abcabc'],
 
167
            writes)
 
168
 
136
169
    def test_add_bytes_record_two_names(self):
137
170
        """Add a bytes record with two names."""
138
171
        self.writer.begin()
207
240
    def test_construct(self):
208
241
        """Test constructing a ContainerReader.
209
242
 
210
 
        This uses None as the output stream to show that the constructor doesn't
211
 
        try to use the input stream.
 
243
        This uses None as the output stream to show that the constructor
 
244
        doesn't try to use the input stream.
212
245
        """
213
246
        reader = pack.ContainerReader(None)
214
247
 
259
292
 
260
293
    def test_validate_empty_container(self):
261
294
        """validate does not raise an error for a container with no records."""
262
 
        reader = self.get_reader_for("Bazaar pack format 1 (introduced in 0.18)\nE")
 
295
        reader = self.get_reader_for(
 
296
            "Bazaar pack format 1 (introduced in 0.18)\nE")
263
297
        # No exception raised
264
298
        reader.validate()
265
299
 
705
739
        parser.accept_bytes("6\n\nabcdef")
706
740
        self.assertEqual([([], 'abcdef')], parser.read_pending_records())
707
741
        self.assertEqual([], parser.read_pending_records())
708
 
 
709