~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_pack.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for bzrlib.pack."""
18
18
 
42
42
        serialiser = pack.ContainerSerialiser()
43
43
        record = serialiser.bytes_record('bytes', [])
44
44
        self.assertEqual('B5\n\nbytes', record)
45
 
        
 
45
 
46
46
    def test_bytes_record_one_name_with_one_part(self):
47
47
        serialiser = pack.ContainerSerialiser()
48
48
        record = serialiser.bytes_record('bytes', [('name',)])
49
49
        self.assertEqual('B5\nname\n\nbytes', record)
50
 
        
 
50
 
51
51
    def test_bytes_record_one_name_with_two_parts(self):
52
52
        serialiser = pack.ContainerSerialiser()
53
53
        record = serialiser.bytes_record('bytes', [('part1', 'part2')])
54
54
        self.assertEqual('B5\npart1\x00part2\n\nbytes', record)
55
 
        
 
55
 
56
56
    def test_bytes_record_two_names(self):
57
57
        serialiser = pack.ContainerSerialiser()
58
58
        record = serialiser.bytes_record('bytes', [('name1',), ('name2',)])
68
68
class TestContainerWriter(tests.TestCase):
69
69
 
70
70
    def setUp(self):
 
71
        tests.TestCase.setUp(self)
71
72
        self.output = StringIO()
72
73
        self.writer = pack.ContainerWriter(self.output.write)
73
74
 
79
80
 
80
81
    def test_construct(self):
81
82
        """Test constructing a ContainerWriter.
82
 
        
 
83
 
83
84
        This uses None as the output stream to show that the constructor
84
85
        doesn't try to use the output stream.
85
86
        """
205
206
 
206
207
    def test_construct(self):
207
208
        """Test constructing a ContainerReader.
208
 
        
 
209
 
209
210
        This uses None as the output stream to show that the constructor doesn't
210
211
        try to use the input stream.
211
212
        """
243
244
 
244
245
    def test_container_with_one_unnamed_record(self):
245
246
        """Read a container with one Bytes record.
246
 
        
 
247
 
247
248
        Parsing Bytes records is more thoroughly exercised by
248
249
        TestBytesRecordReader.  This test is here to ensure that
249
250
        ContainerReader's integration with BytesRecordReader is working.
326
327
        reader = self.get_reader_for(
327
328
            "Bazaar pack format 1 (introduced in 0.18)\nB0\n\xcc\n\nE")
328
329
        self.assertRaises(errors.InvalidRecordError, reader.validate)
329
 
        
 
330
 
330
331
 
331
332
class TestBytesRecordReader(tests.TestCase):
332
333
    """Tests for reading and validating Bytes records with
333
334
    BytesRecordReader.
334
 
    
 
335
 
335
336
    Like TestContainerReader, this explicitly tests the reading of format 1
336
337
    data.  If a new version of the format is added, then a separate set of
337
338
    tests for reading that format should be added.
385
386
    def test_early_eof(self):
386
387
        """Tests for premature EOF occuring during parsing Bytes records with
387
388
        BytesRecordReader.
388
 
        
 
389
 
389
390
        A incomplete container might be interrupted at any point.  The
390
391
        BytesRecordReader needs to cope with the input stream running out no
391
392
        matter where it is in the parsing process.
518
519
    """Tests of the ReadVFile class.
519
520
 
520
521
    Error cases are deliberately undefined: this code adapts the underlying
521
 
    transport interface to a single 'streaming read' interface as 
 
522
    transport interface to a single 'streaming read' interface as
522
523
    ContainerReader needs.
523
524
    """
524
525
 
584
585
        parsed_records = parser.read_pending_records()
585
586
        self.assertEqual([expected_record], parsed_records)
586
587
 
587
 
        
 
588
 
588
589
class TestContainerPushParser(PushParserTestCase):
589
590
    """Tests for ContainerPushParser.
590
 
    
 
591
 
591
592
    The ContainerPushParser reads format 1 containers, so these tests
592
593
    explicitly test how it reacts to format 1 data.  If a new version of the
593
594
    format is added, then separate tests for that format should be added.
609
610
            [([('name1',)], 'body1'), ([('name2',)], 'body2')],
610
611
            parser.read_pending_records())
611
612
 
 
613
    def test_multiple_empty_records_at_once(self):
 
614
        """If multiple empty records worth of data are fed to the parser in one
 
615
        string, the parser will correctly parse all the records.
 
616
 
 
617
        (A naive implementation might stop after parsing the first empty
 
618
        record, because the buffer size had not changed.)
 
619
        """
 
620
        parser = self.make_parser_expecting_record_type()
 
621
        parser.accept_bytes("B0\nname1\n\nB0\nname2\n\n")
 
622
        self.assertEqual(
 
623
            [([('name1',)], ''), ([('name2',)], '')],
 
624
            parser.read_pending_records())
 
625
 
612
626
 
613
627
class TestContainerPushParserBytesParsing(PushParserTestCase):
614
628
    """Tests for reading Bytes records with ContainerPushParser.
615
 
    
 
629
 
616
630
    The ContainerPushParser reads format 1 containers, so these tests
617
631
    explicitly test how it reacts to format 1 data.  If a new version of the
618
632
    format is added, then separate tests for that format should be added.