/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-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from cStringIO import StringIO
18
 
 
19
 
from bzrlib import (
20
 
    errors,
21
 
    revision,
22
 
    serializer,
23
 
    )
24
 
from bzrlib.chk_serializer import (
 
17
from ..bzr.chk_serializer import (
25
18
    chk_bencode_serializer,
26
19
    )
27
 
from bzrlib.revision import (
 
20
from ..revision import (
28
21
    Revision,
29
22
    )
30
 
from bzrlib.tests import TestCase
31
 
 
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'
41
 
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
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')
47
 
 
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'
56
 
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
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')
 
23
from . import TestCase
 
24
 
 
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
 
 
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')
62
55
 
63
56
 
64
57
class TestBEncodeSerializer1(TestCase):
67
60
    def test_unpack_revision(self):
68
61
        """Test unpacking a revision"""
69
62
        rev = chk_bencode_serializer.read_revision_from_string(
70
 
                _working_revision_bencode1)
71
 
        self.assertEquals(rev.committer,
72
 
           "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
73
 
        self.assertEquals(rev.inventory_sha1,
74
 
           "4a2c7fb50e077699242cf6eb16a61779c7b680a7")
75
 
        self.assertEquals(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
76
 
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
77
 
            rev.parent_ids)
78
 
        self.assertEquals("(Jelmer) Move dpush to InterBranch.", rev.message)
79
 
        self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
80
 
           rev.revision_id)
81
 
        self.assertEquals({"branch-nick": u"+trunk"}, rev.properties)
82
 
        self.assertEquals(3600, rev.timezone)
 
63
            _working_revision_bencode1)
 
64
        self.assertEqual(rev.committer,
 
65
                         "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
 
66
        self.assertEqual(rev.inventory_sha1,
 
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
        self.assertEqual("(Jelmer) Move dpush to InterBranch.", rev.message)
 
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
        self.assertEqual(3600, rev.timezone)
83
76
 
84
77
    def test_written_form_matches(self):
85
78
        rev = chk_bencode_serializer.read_revision_from_string(
86
 
                _working_revision_bencode1)
 
79
            _working_revision_bencode1)
87
80
        as_str = chk_bencode_serializer.write_revision_to_string(rev)
88
81
        self.assertEqualDiff(_working_revision_bencode1, as_str)
89
82
 
90
83
    def test_unpack_revision_no_timezone(self):
91
84
        rev = chk_bencode_serializer.read_revision_from_string(
92
85
            _working_revision_bencode1_no_timezone)
93
 
        self.assertEquals(None, rev.timezone)
 
86
        self.assertEqual(None, rev.timezone)
94
87
 
95
88
    def assertRoundTrips(self, serializer, orig_rev):
96
 
        text = serializer.write_revision_to_string(orig_rev)
97
 
        new_rev = serializer.read_revision_from_string(text)
98
 
        self.assertEquals(orig_rev, new_rev)
 
89
        lines = serializer.write_revision_to_lines(orig_rev)
 
90
        new_rev = serializer.read_revision_from_string(b''.join(lines))
 
91
        self.assertEqual(orig_rev, new_rev)
99
92
 
100
93
    def test_roundtrips_non_ascii(self):
101
 
        rev = Revision("revid1")
 
94
        rev = Revision(b"revid1")
102
95
        rev.message = u"\n\xe5me"
103
96
        rev.committer = u'Erik B\xe5gfors'
104
97
        rev.timestamp = 1242385452
105
 
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
98
        rev.inventory_sha1 = b"4a2c7fb50e077699242cf6eb16a61779c7b680a7"
106
99
        rev.timezone = 3600
107
100
        self.assertRoundTrips(chk_bencode_serializer, rev)
108
101
 
109
102
    def test_roundtrips_xml_invalid_chars(self):
110
 
        rev = Revision("revid1")
 
103
        rev = Revision(b"revid1")
111
104
        rev.message = "\t\ue000"
112
105
        rev.committer = u'Erik B\xe5gfors'
113
106
        rev.timestamp = 1242385452
114
107
        rev.timezone = 3600
115
 
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
108
        rev.inventory_sha1 = b"4a2c7fb50e077699242cf6eb16a61779c7b680a7"
116
109
        self.assertRoundTrips(chk_bencode_serializer, rev)