/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_chk_serializer.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    )
23
23
from . import TestCase
24
24
 
25
 
_working_revision_bencode1 = ('l'
26
 
    'l6:formati10ee'
27
 
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
28
 
    'l8:timezonei3600ee'
29
 
    'l10:propertiesd11:branch-nick6:+trunkee'
30
 
    'l9:timestamp14:1242300770.844e'
31
 
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
32
 
    'l10:parent-ids'
33
 
        'l'
34
 
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
35
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
36
 
        'ee'
37
 
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
38
 
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
39
 
    'e')
 
25
_working_revision_bencode1 = (b'l'
 
26
                              b'l6:formati10ee'
 
27
                              b'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
 
28
                              b'l8:timezonei3600ee'
 
29
                              b'l10:propertiesd11:branch-nick6:+trunkee'
 
30
                              b'l9:timestamp14:1242300770.844e'
 
31
                              b'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
 
32
                              b'l10:parent-ids'
 
33
                              b'l'
 
34
                              b'50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
 
35
                              b'48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
 
36
                              b'ee'
 
37
                              b'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
 
38
                              b'l7:message35:(Jelmer) Move dpush to InterBranch.e'
 
39
                              b'e')
40
40
 
41
 
_working_revision_bencode1_no_timezone = ('l'
42
 
    'l6:formati10ee'
43
 
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
44
 
    'l9:timestamp14:1242300770.844e'
45
 
    'l10:propertiesd11:branch-nick6:+trunkee'
46
 
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
47
 
    'l10:parent-ids'
48
 
        'l'
49
 
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
50
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
51
 
        'ee'
52
 
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
53
 
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
54
 
    'e')
 
41
_working_revision_bencode1_no_timezone = (b'l'
 
42
                                          b'l6:formati10ee'
 
43
                                          b'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
 
44
                                          b'l9:timestamp14:1242300770.844e'
 
45
                                          b'l10:propertiesd11:branch-nick6:+trunkee'
 
46
                                          b'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
 
47
                                          b'l10:parent-ids'
 
48
                                          b'l'
 
49
                                          b'50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
 
50
                                          b'48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
 
51
                                          b'ee'
 
52
                                          b'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
 
53
                                          b'l7:message35:(Jelmer) Move dpush to InterBranch.e'
 
54
                                          b'e')
55
55
 
56
56
 
57
57
class TestBEncodeSerializer1(TestCase):
60
60
    def test_unpack_revision(self):
61
61
        """Test unpacking a revision"""
62
62
        rev = chk_bencode_serializer.read_revision_from_string(
63
 
                _working_revision_bencode1)
 
63
            _working_revision_bencode1)
64
64
        self.assertEqual(rev.committer,
65
 
           "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
 
65
                         "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
66
66
        self.assertEqual(rev.inventory_sha1,
67
 
           "4a2c7fb50e077699242cf6eb16a61779c7b680a7")
68
 
        self.assertEqual(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
69
 
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
70
 
            rev.parent_ids)
 
67
                         b"4a2c7fb50e077699242cf6eb16a61779c7b680a7")
 
68
        self.assertEqual([b"pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
 
69
                          b"jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
 
70
                         rev.parent_ids)
71
71
        self.assertEqual("(Jelmer) Move dpush to InterBranch.", rev.message)
72
 
        self.assertEqual("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
73
 
           rev.revision_id)
74
 
        self.assertEqual({"branch-nick": u"+trunk"}, rev.properties)
 
72
        self.assertEqual(b"pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
 
73
                         rev.revision_id)
 
74
        self.assertEqual({u"branch-nick": u"+trunk"}, rev.properties)
75
75
        self.assertEqual(3600, rev.timezone)
76
76
 
77
77
    def test_written_form_matches(self):
78
78
        rev = chk_bencode_serializer.read_revision_from_string(
79
 
                _working_revision_bencode1)
 
79
            _working_revision_bencode1)
80
80
        as_str = chk_bencode_serializer.write_revision_to_string(rev)
81
81
        self.assertEqualDiff(_working_revision_bencode1, as_str)
82
82
 
86
86
        self.assertEqual(None, rev.timezone)
87
87
 
88
88
    def assertRoundTrips(self, serializer, orig_rev):
89
 
        text = serializer.write_revision_to_string(orig_rev)
90
 
        new_rev = serializer.read_revision_from_string(text)
 
89
        lines = serializer.write_revision_to_lines(orig_rev)
 
90
        new_rev = serializer.read_revision_from_string(b''.join(lines))
91
91
        self.assertEqual(orig_rev, new_rev)
92
92
 
93
93
    def test_roundtrips_non_ascii(self):
94
 
        rev = Revision("revid1")
 
94
        rev = Revision(b"revid1")
95
95
        rev.message = u"\n\xe5me"
96
96
        rev.committer = u'Erik B\xe5gfors'
97
97
        rev.timestamp = 1242385452
98
 
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
98
        rev.inventory_sha1 = b"4a2c7fb50e077699242cf6eb16a61779c7b680a7"
99
99
        rev.timezone = 3600
100
100
        self.assertRoundTrips(chk_bencode_serializer, rev)
101
101
 
102
102
    def test_roundtrips_xml_invalid_chars(self):
103
 
        rev = Revision("revid1")
 
103
        rev = Revision(b"revid1")
104
104
        rev.message = "\t\ue000"
105
105
        rev.committer = u'Erik B\xe5gfors'
106
106
        rev.timestamp = 1242385452
107
107
        rev.timezone = 3600
108
 
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
108
        rev.inventory_sha1 = b"4a2c7fb50e077699242cf6eb16a61779c7b680a7"
109
109
        self.assertRoundTrips(chk_bencode_serializer, rev)