~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_serializer.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-03 14:14:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: john@arbash-meinel.com-20090603141431-zeurvzs2iezwzdn5
A bit of code restructuring.
Move bzrlib/_bencode_py.py back to bzrlib/util/_bencode_py.py
Leaving it as _bencode_py.py so that people don't accidentally
import the old version.
Renaming _bencode_c.pyx => _bencode_pyx.pyx to conform to new naming scheme.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2009 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
    )
17
24
from bzrlib.chk_serializer import (
18
25
    chk_bencode_serializer,
19
26
    )
22
29
    )
23
30
from bzrlib.tests import TestCase
24
31
 
25
 
_working_revision_bencode1 = ('l'
26
 
    'l6:formati10ee'
27
 
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
28
 
    'l8:timezonei3600ee'
29
 
    'l10:propertiesd11:branch-nick6:+trunkee'
30
 
    'l9:timestamp14:1242300770.844e'
31
 
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
32
 
    'l10:parent-ids'
33
 
        'l'
 
32
_working_revision_bencode1 = ('d'
 
33
    '9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>'
 
34
    '14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7'
 
35
    '7:message35:(Jelmer) Move dpush to InterBranch.'
 
36
    '10:parent-idsl'
34
37
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
35
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
36
 
        'ee'
37
 
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
38
 
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
39
 
    'e')
 
38
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe'
 
39
    '10:propertiesd11:branch-nick6:+trunke'
 
40
    '11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz'
 
41
    '9:timestamp14:1242300770.8448:timezonei3600ee')
40
42
 
41
 
_working_revision_bencode1_no_timezone = ('l'
42
 
    'l6:formati10ee'
43
 
    'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
44
 
    'l9:timestamp14:1242300770.844e'
45
 
    'l10:propertiesd11:branch-nick6:+trunkee'
46
 
    'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
47
 
    'l10:parent-ids'
48
 
        'l'
 
43
_working_revision_bencode1_no_timestamp = ('d'
 
44
    '9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>'
 
45
    '14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7'
 
46
    '7:message35:(Jelmer) Move dpush to InterBranch.'
 
47
    '10:parent-idsl'
49
48
        '50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
50
 
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
51
 
        'ee'
52
 
    'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
53
 
    'l7:message35:(Jelmer) Move dpush to InterBranch.e'
54
 
    'e')
 
49
        '48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeoe'
 
50
    '10:propertiesd11:branch-nick6:+trunke'
 
51
    '11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz'
 
52
    '9:timestamp14:1242300770.844e')
55
53
 
56
54
 
57
55
class TestBEncodeSerializer1(TestCase):
59
57
 
60
58
    def test_unpack_revision(self):
61
59
        """Test unpacking a revision"""
 
60
        inp = StringIO()
62
61
        rev = chk_bencode_serializer.read_revision_from_string(
63
62
                _working_revision_bencode1)
64
63
        self.assertEquals(rev.committer,
69
68
            "jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"],
70
69
            rev.parent_ids)
71
70
        self.assertEquals("(Jelmer) Move dpush to InterBranch.", rev.message)
72
 
        self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz",
 
71
        self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz", 
73
72
           rev.revision_id)
74
73
        self.assertEquals({"branch-nick": u"+trunk"}, rev.properties)
75
74
        self.assertEquals(3600, rev.timezone)
76
75
 
77
 
    def test_written_form_matches(self):
78
 
        rev = chk_bencode_serializer.read_revision_from_string(
79
 
                _working_revision_bencode1)
80
 
        as_str = chk_bencode_serializer.write_revision_to_string(rev)
81
 
        self.assertEqualDiff(_working_revision_bencode1, as_str)
82
 
 
83
 
    def test_unpack_revision_no_timezone(self):
84
 
        rev = chk_bencode_serializer.read_revision_from_string(
85
 
            _working_revision_bencode1_no_timezone)
 
76
    def test_unpack_revision_no_timestamp(self):
 
77
        rev = chk_bencode_serializer.read_revision_from_string(
 
78
            _working_revision_bencode1_no_timestamp)
86
79
        self.assertEquals(None, rev.timezone)
87
80
 
88
81
    def assertRoundTrips(self, serializer, orig_rev):