~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_serializer.py

  • Committer: Jelmer Vernooij
  • Date: 2009-05-15 11:05:44 UTC
  • mto: (4398.5.2 bencode_serializer)
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: jelmer@samba.org-20090515110544-m2k6s02p4evg25i6
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
from cStringIO import StringIO
 
18
 
 
19
from bzrlib import (
 
20
    errors,
 
21
    revision,
 
22
    serializer,
 
23
    )
 
24
from bzrlib.chk_serializer import (
 
25
    chk_rio_serializer,
 
26
    )
 
27
from bzrlib.revision import (
 
28
    Revision,
 
29
    )
 
30
from bzrlib.tests import TestCase
 
31
 
 
32
_working_revision_rio1 = """revision-id: pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz
 
33
timestamp: 1242300770.844
 
34
parent-id: pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc
 
35
parent-id: jelmer@samba.org-20090510012654-jp9ufxquekaokbeo
 
36
inventory-sha1: 4a2c7fb50e077699242cf6eb16a61779c7b680a7
 
37
committer: Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>
 
38
timezone: 3600
 
39
property-branch-nick: +trunk
 
40
message: (Jelmer) Move dpush to InterBranch.
 
41
"""
 
42
 
 
43
_working_revision_rio1_no_timestamp = """revision-id: pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz
 
44
timestamp: 1242300770.844
 
45
parent-id: pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc
 
46
parent-id: jelmer@samba.org-20090510012654-jp9ufxquekaokbeo
 
47
inventory-sha1: 4a2c7fb50e077699242cf6eb16a61779c7b680a7
 
48
committer: Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>
 
49
property-branch-nick: +trunk
 
50
message: (Jelmer) Move dpush to InterBranch.
 
51
"""
 
52
 
 
53
class TestRIOSerializer1(TestCase):
 
54
    """Test RIO serialization"""
 
55
 
 
56
    def test_unpack_revision(self):
 
57
        """Test unpacking a revision"""
 
58
        inp = StringIO()
 
59
        rev = chk_rio_serializer.read_revision_from_string(
 
60
                _working_revision_rio1)
 
61
        eq = self.assertEqual
 
62
        eq(rev.committer,
 
63
           "Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
 
64
        eq(rev.inventory_sha1,
 
65
           "4a2c7fb50e077699242cf6eb16a61779c7b680a7")
 
66
        eq(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
 
67
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
 
68
            rev.parent_ids)
 
69
        eq("(Jelmer) Move dpush to InterBranch.", rev.message)
 
70
        eq("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz", 
 
71
           rev.revision_id)
 
72
        eq({"branch-nick": u"+trunk"}, rev.properties)
 
73
        eq(3600, rev.timezone)
 
74
 
 
75
    def test_unpack_revision_no_timestamp(self):
 
76
        rev = chk_rio_serializer.read_revision_from_string(
 
77
            _working_revision_rio1_no_timestamp)
 
78
        self.assertEquals(None, rev.timezone)
 
79
 
 
80
    def assertRoundTrips(self, serializer, orig_rev):
 
81
        text = serializer.write_revision_to_string(orig_rev)
 
82
        new_rev = serializer.read_revision_from_string(text)
 
83
        self.assertEquals(orig_rev, new_rev)
 
84
 
 
85
    def test_roundtrips_non_ascii(self):
 
86
        rev = Revision("revid1")
 
87
        rev.message = u"\n\xe5me"
 
88
        rev.committer = u'Erik B\xe5gfors'
 
89
        rev.timestamp = 1242385452
 
90
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
91
        rev.timezone = 3600
 
92
        self.assertRoundTrips(chk_rio_serializer, rev)
 
93
 
 
94
    def test_roundtrips_xml_invalid_chars(self):
 
95
        rev = Revision("revid1")
 
96
        rev.message = "\t\ue000"
 
97
        rev.committer = u'Erik B\xe5gfors'
 
98
        rev.timestamp = 1242385452
 
99
        rev.timezone = 3600
 
100
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
101
        self.assertRoundTrips(chk_rio_serializer, rev)