~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack.py

Merge more bzr.dev, addressing some bugs. [still broken]

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        self.assertEqual('Bazaar pack format 1 (introduced in 0.18)\n',
41
41
                         output.getvalue())
42
42
 
 
43
    def test_zero_records_written_after_begin(self):
 
44
        """After begin is written, 0 records have been written."""
 
45
        output = StringIO()
 
46
        writer = pack.ContainerWriter(output.write)
 
47
        writer.begin()
 
48
        self.assertEqual(0, writer.records_written)
 
49
 
43
50
    def test_end(self):
44
51
        """The end() method writes an End Marker record."""
45
52
        output = StringIO()
49
56
        self.assertEqual('Bazaar pack format 1 (introduced in 0.18)\nE',
50
57
                         output.getvalue())
51
58
 
 
59
    def test_empty_end_does_not_add_a_record_to_records_written(self):
 
60
        """The end() method does not count towards the records written."""
 
61
        output = StringIO()
 
62
        writer = pack.ContainerWriter(output.write)
 
63
        writer.begin()
 
64
        writer.end()
 
65
        self.assertEqual(0, writer.records_written)
 
66
 
 
67
    def test_non_empty_end_does_not_add_a_record_to_records_written(self):
 
68
        """The end() method does not count towards the records written."""
 
69
        output = StringIO()
 
70
        writer = pack.ContainerWriter(output.write)
 
71
        writer.begin()
 
72
        writer.add_bytes_record('foo', names=[])
 
73
        writer.end()
 
74
        self.assertEqual(1, writer.records_written)
 
75
 
52
76
    def test_add_bytes_record_no_name(self):
53
77
        """Add a bytes record with no name."""
54
78
        output = StringIO()
131
155
            errors.InvalidRecordError,
132
156
            writer.add_bytes_record, 'abc', names=[('bad name', )])
133
157
 
 
158
    def test_add_bytes_records_add_to_records_written(self):
 
159
        """Adding a Bytes record increments the records_written counter."""
 
160
        output = StringIO()
 
161
        writer = pack.ContainerWriter(output.write)
 
162
        writer.begin()
 
163
        writer.add_bytes_record('foo', names=[])
 
164
        self.assertEqual(1, writer.records_written)
 
165
        writer.add_bytes_record('foo', names=[])
 
166
        self.assertEqual(2, writer.records_written)
 
167
 
134
168
 
135
169
class TestContainerReader(tests.TestCase):
136
170