4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
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 ( |
|
4290.1.12
by Jelmer Vernooij
Use bencode rather than rio in the new revision serialiszer. |
25 |
chk_bencode_serializer, |
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
26 |
)
|
27 |
from bzrlib.revision import ( |
|
28 |
Revision, |
|
29 |
)
|
|
30 |
from bzrlib.tests import TestCase |
|
31 |
||
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
32 |
_working_revision_bencode1 = ('l' |
33 |
'l6:formati10ee'
|
|
34 |
'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
|
|
35 |
'l8:timezonei3600ee'
|
|
36 |
'l10:propertiesd11:branch-nick6:+trunkee'
|
|
37 |
'l9:timestamp14:1242300770.844e'
|
|
38 |
'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
|
|
39 |
'l10:parent-ids'
|
|
40 |
'l'
|
|
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
41 |
'50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
|
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
42 |
'48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
|
43 |
'ee'
|
|
44 |
'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
|
|
45 |
'l7:message35:(Jelmer) Move dpush to InterBranch.e'
|
|
46 |
'e') |
|
4290.1.13
by Jelmer Vernooij
Fix bencode-broken tests. |
47 |
|
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
48 |
_working_revision_bencode1_no_timezone = ('l' |
49 |
'l6:formati10ee'
|
|
50 |
'l9:committer54:Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>e'
|
|
51 |
'l9:timestamp14:1242300770.844e'
|
|
52 |
'l10:propertiesd11:branch-nick6:+trunkee'
|
|
53 |
'l11:revision-id50:pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tze'
|
|
54 |
'l10:parent-ids'
|
|
55 |
'l'
|
|
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
56 |
'50:pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc'
|
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
57 |
'48:jelmer@samba.org-20090510012654-jp9ufxquekaokbeo'
|
58 |
'ee'
|
|
59 |
'l14:inventory-sha140:4a2c7fb50e077699242cf6eb16a61779c7b680a7e'
|
|
60 |
'l7:message35:(Jelmer) Move dpush to InterBranch.e'
|
|
61 |
'e') |
|
4290.1.13
by Jelmer Vernooij
Fix bencode-broken tests. |
62 |
|
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
63 |
|
4290.1.12
by Jelmer Vernooij
Use bencode rather than rio in the new revision serialiszer. |
64 |
class TestBEncodeSerializer1(TestCase): |
65 |
"""Test BEncode serialization"""
|
|
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
66 |
|
67 |
def test_unpack_revision(self): |
|
68 |
"""Test unpacking a revision"""
|
|
4290.1.12
by Jelmer Vernooij
Use bencode rather than rio in the new revision serialiszer. |
69 |
rev = chk_bencode_serializer.read_revision_from_string( |
70 |
_working_revision_bencode1) |
|
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
71 |
self.assertEquals(rev.committer, |
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
72 |
"Canonical.com Patch Queue Manager <pqm@pqm.ubuntu.com>") |
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
73 |
self.assertEquals(rev.inventory_sha1, |
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
74 |
"4a2c7fb50e077699242cf6eb16a61779c7b680a7") |
4398.5.19
by John Arbash Meinel
Change parent_ids back to a list, because there are other tests that expect it. |
75 |
self.assertEquals(["pqm@pqm.ubuntu.com-20090514104039-kggemn7lrretzpvc", |
76 |
"jelmer@samba.org-20090510012654-jp9ufxquekaokbeo"], |
|
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
77 |
rev.parent_ids) |
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
78 |
self.assertEquals("(Jelmer) Move dpush to InterBranch.", rev.message) |
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
79 |
self.assertEquals("pqm@pqm.ubuntu.com-20090514113250-jntkkpminfn3e0tz", |
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
80 |
rev.revision_id) |
4290.1.14
by Jelmer Vernooij
Review feedback from Aaron: |
81 |
self.assertEquals({"branch-nick": u"+trunk"}, rev.properties) |
82 |
self.assertEquals(3600, rev.timezone) |
|
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
83 |
|
4398.5.5
by John Arbash Meinel
Update the CHK Serializer to do lots more validation. |
84 |
def test_written_form_matches(self): |
85 |
rev = chk_bencode_serializer.read_revision_from_string( |
|
86 |
_working_revision_bencode1) |
|
87 |
as_str = chk_bencode_serializer.write_revision_to_string(rev) |
|
88 |
self.assertEqualDiff(_working_revision_bencode1, as_str) |
|
89 |
||
90 |
def test_unpack_revision_no_timezone(self): |
|
91 |
rev = chk_bencode_serializer.read_revision_from_string( |
|
92 |
_working_revision_bencode1_no_timezone) |
|
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
93 |
self.assertEquals(None, rev.timezone) |
94 |
||
95 |
def assertRoundTrips(self, serializer, orig_rev): |
|
96 |
text = serializer.write_revision_to_string(orig_rev) |
|
97 |
new_rev = serializer.read_revision_from_string(text) |
|
98 |
self.assertEquals(orig_rev, new_rev) |
|
99 |
||
100 |
def test_roundtrips_non_ascii(self): |
|
101 |
rev = Revision("revid1") |
|
102 |
rev.message = u"\n\xe5me" |
|
103 |
rev.committer = u'Erik B\xe5gfors' |
|
104 |
rev.timestamp = 1242385452 |
|
105 |
rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" |
|
106 |
rev.timezone = 3600 |
|
4290.1.12
by Jelmer Vernooij
Use bencode rather than rio in the new revision serialiszer. |
107 |
self.assertRoundTrips(chk_bencode_serializer, rev) |
4290.1.11
by Jelmer Vernooij
Add some simple tests for the CHKRioSerializer to make sure the format doesn't change. |
108 |
|
109 |
def test_roundtrips_xml_invalid_chars(self): |
|
110 |
rev = Revision("revid1") |
|
111 |
rev.message = "\t\ue000" |
|
112 |
rev.committer = u'Erik B\xe5gfors' |
|
113 |
rev.timestamp = 1242385452 |
|
114 |
rev.timezone = 3600 |
|
115 |
rev.inventory_sha1 = "4a2c7fb50e077699242cf6eb16a61779c7b680a7" |
|
4290.1.12
by Jelmer Vernooij
Use bencode rather than rio in the new revision serialiszer. |
116 |
self.assertRoundTrips(chk_bencode_serializer, rev) |