1
# Copyright (C) 2009 Canonical Ltd
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.
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.
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
17
from cStringIO import StringIO
24
from bzrlib.chk_serializer import (
27
from bzrlib.revision import (
30
from bzrlib.tests import TestCase
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>
39
property-branch-nick: +trunk
40
message: (Jelmer) Move dpush to InterBranch.
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.
53
class TestRIOSerializer1(TestCase):
54
"""Test RIO serialization"""
56
def test_unpack_revision(self):
57
"""Test unpacking a revision"""
59
rev = chk_rio_serializer.read_revision_from_string(
60
_working_revision_rio1)
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"],
69
eq("(Jelmer) Move dpush to InterBranch.", rev.message)
70
eq("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
72
eq({"branch-nick": u"+trunk"}, rev.properties)
73
eq(3600, rev.timezone)
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)
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)
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"
92
self.assertRoundTrips(chk_rio_serializer, rev)
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
100
rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
101
self.assertRoundTrips(chk_rio_serializer, rev)