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 (
25
chk_bencode_serializer,
27
from bzrlib.revision import (
30
from bzrlib.tests import TestCase
32
_working_revision_bencode1 = 'd9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a77:message35:(Jelmer) Move dpush to InterBranch.10:parent-idsl50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe10:propertiesd11:branch-nick6:+trunke11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz9:timestamp14:1242300770.8448:timezone4:3600e'
34
_working_revision_bencode1_no_timestamp = 'd9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a77:message35:(Jelmer) Move dpush to InterBranch.10:parent-idsl50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe10:propertiesd11:branch-nick6:+trunke11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz9:timestamp14:1242300770.844e'
37
class TestBEncodeSerializer1(TestCase):
38
"""Test BEncode serialization"""
40
def test_unpack_revision(self):
41
"""Test unpacking a revision"""
43
rev = chk_bencode_serializer.read_revision_from_string(
44
_working_revision_bencode1)
47
"Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>")
48
eq(rev.inventory_sha1,
49
"4a2c7fb50e077699242cf6eb16a61779c7b680a7")
50
eq(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc",
51
"jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
53
eq("(Jelmer) Move dpush to InterBranch.", rev.message)
54
eq("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
56
eq({"branch-nick": u"+trunk"}, rev.properties)
57
eq(3600, rev.timezone)
59
def test_unpack_revision_no_timestamp(self):
60
rev = chk_bencode_serializer.read_revision_from_string(
61
_working_revision_bencode1_no_timestamp)
62
self.assertEquals(None, rev.timezone)
64
def assertRoundTrips(self, serializer, orig_rev):
65
text = serializer.write_revision_to_string(orig_rev)
66
new_rev = serializer.read_revision_from_string(text)
67
self.assertEquals(orig_rev, new_rev)
69
def test_roundtrips_non_ascii(self):
70
rev = Revision("revid1")
71
rev.message = u"\n\xe5me"
72
rev.committer = u'Erik B\xe5gfors'
73
rev.timestamp = 1242385452
74
rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
76
self.assertRoundTrips(chk_bencode_serializer, rev)
78
def test_roundtrips_xml_invalid_chars(self):
79
rev = Revision("revid1")
80
rev.message = "\t\ue000"
81
rev.committer = u'Erik B\xe5gfors'
82
rev.timestamp = 1242385452
84
rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
85
self.assertRoundTrips(chk_bencode_serializer, rev)