~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_serializer.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-03 14:47:56 UTC
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: john@arbash-meinel.com-20090603144756-biptv8wwy4rybhze
Update the CHK Serializer to do lots more validation.
We now validate the types of the objects being read, and we mutate
the values appropriately.
We assert that we have enough values in the stream, and that we don't
have any duplicates, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    )
30
30
from bzrlib.tests import TestCase
31
31
 
32
 
_working_revision_bencode1 = ('d'
33
 
    '9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>'
34
 
    '14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7'
35
 
    '7:message35:(Jelmer) Move dpush to InterBranch.'
36
 
    '10:parent-idsl'
 
32
_working_revision_bencode1 = ('l'
 
33
    'l6:formati10ee'
 
34
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
 
35
    'l8:timezonei3600ee'
 
36
    'l10:propertiesd11:branch-nick6:+trunkee'
 
37
    'l9:timestamp14:1242300770.844e'
 
38
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
 
39
    'l10:parent-ids'
 
40
        'l'
37
41
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
38
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe'
39
 
    '10:propertiesd11:branch-nick6:+trunke'
40
 
    '11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz'
41
 
    '9:timestamp14:1242300770.8448:timezonei3600ee')
 
42
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
 
43
        'ee'
 
44
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
 
45
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
 
46
    'e')
42
47
 
43
 
_working_revision_bencode1_no_timestamp = ('d'
44
 
    '9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>'
45
 
    '14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7'
46
 
    '7:message35:(Jelmer) Move dpush to InterBranch.'
47
 
    '10:parent-idsl'
 
48
_working_revision_bencode1_no_timezone = ('l'
 
49
    'l6:formati10ee'
 
50
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
 
51
    'l9:timestamp14:1242300770.844e'
 
52
    'l10:propertiesd11:branch-nick6:+trunkee'
 
53
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
 
54
    'l10:parent-ids'
 
55
        'l'
48
56
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
49
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe'
50
 
    '10:propertiesd11:branch-nick6:+trunke'
51
 
    '11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz'
52
 
    '9:timestamp14:1242300770.844e')
 
57
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
 
58
        'ee'
 
59
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
 
60
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
 
61
    'e')
53
62
 
54
63
 
55
64
class TestBEncodeSerializer1(TestCase):
57
66
 
58
67
    def test_unpack_revision(self):
59
68
        """Test unpacking a revision"""
60
 
        inp = StringIO()
61
69
        rev = chk_bencode_serializer.read_revision_from_string(
62
70
                _working_revision_bencode1)
63
71
        self.assertEquals(rev.committer,
64
72
           "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
65
73
        self.assertEquals(rev.inventory_sha1,
66
74
           "4a2c7fb50e077699242cf6eb16a61779c7b680a7")
67
 
        self.assertEquals(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
68
 
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
 
75
        self.assertEquals(("pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
 
76
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"),
69
77
            rev.parent_ids)
70
78
        self.assertEquals("(Jelmer) Move dpush to InterBranch.", rev.message)
71
 
        self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz", 
 
79
        self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
72
80
           rev.revision_id)
73
81
        self.assertEquals({"branch-nick": u"+trunk"}, rev.properties)
74
82
        self.assertEquals(3600, rev.timezone)
75
83
 
76
 
    def test_unpack_revision_no_timestamp(self):
77
 
        rev = chk_bencode_serializer.read_revision_from_string(
78
 
            _working_revision_bencode1_no_timestamp)
 
84
    def test_written_form_matches(self):
 
85
        rev = chk_bencode_serializer.read_revision_from_string(
 
86
                _working_revision_bencode1)
 
87
        as_str = chk_bencode_serializer.write_revision_to_string(rev)
 
88
        self.assertEqualDiff(_working_revision_bencode1, as_str)
 
89
 
 
90
    def test_unpack_revision_no_timezone(self):
 
91
        rev = chk_bencode_serializer.read_revision_from_string(
 
92
            _working_revision_bencode1_no_timezone)
79
93
        self.assertEquals(None, rev.timezone)
80
94
 
81
95
    def assertRoundTrips(self, serializer, orig_rev):