/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 bzrlib/tests/test_chk_serializer.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-03 01:43:22 UTC
  • mfrom: (4290.1.13 bencode)
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: john@arbash-meinel.com-20090603014322-luyawuzu5f9v1llt
Merge the chk serializer, and update it for the new bencode locations.

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_bencode_serializer,
 
26
    )
 
27
from bzrlib.revision import (
 
28
    Revision,
 
29
    )
 
30
from bzrlib.tests import TestCase
 
31
 
 
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'
 
33
 
 
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'
 
35
 
 
36
 
 
37
class TestBEncodeSerializer1(TestCase):
 
38
    """Test BEncode serialization"""
 
39
 
 
40
    def test_unpack_revision(self):
 
41
        """Test unpacking a revision"""
 
42
        inp = StringIO()
 
43
        rev = chk_bencode_serializer.read_revision_from_string(
 
44
                _working_revision_bencode1)
 
45
        eq = self.assertEqual
 
46
        eq(rev.committer,
 
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"],
 
52
            rev.parent_ids)
 
53
        eq("(Jelmer) Move dpush to InterBranch.", rev.message)
 
54
        eq("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz", 
 
55
           rev.revision_id)
 
56
        eq({"branch-nick": u"+trunk"}, rev.properties)
 
57
        eq(3600, rev.timezone)
 
58
 
 
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)
 
63
 
 
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)
 
68
 
 
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"
 
75
        rev.timezone = 3600
 
76
        self.assertRoundTrips(chk_bencode_serializer, rev)
 
77
 
 
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
 
83
        rev.timezone = 3600
 
84
        rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7"
 
85
        self.assertRoundTrips(chk_bencode_serializer, rev)