gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / dulwich / tests / test_objectspec.py @ 959
History | View | Annotate | Download (6.36 KB)
1 |
# test_objectspec.py -- tests for objectspec.py
|
---|---|
2 |
# Copyright (C) 2014 Jelmer Vernooij <jelmer@samba.org>
|
3 |
#
|
4 |
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
|
5 |
# General Public License as public by the Free Software Foundation; version 2.0
|
6 |
# or (at your option) any later version. You can redistribute it and/or
|
7 |
# modify it under the terms of either of these two licenses.
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
#
|
15 |
# You should have received a copy of the licenses; if not, see
|
16 |
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
|
17 |
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
|
18 |
# License, Version 2.0.
|
19 |
#
|
20 |
|
21 |
"""Tests for revision spec parsing."""
|
22 |
|
23 |
# TODO: Round-trip parse-serialize-parse and serialize-parse-serialize tests.
|
24 |
|
25 |
|
26 |
from dulwich.objects import ( |
27 |
Blob, |
28 |
) |
29 |
from dulwich.objectspec import ( |
30 |
parse_object, |
31 |
parse_commit_range, |
32 |
parse_ref, |
33 |
parse_refs, |
34 |
parse_reftuple, |
35 |
parse_reftuples, |
36 |
) |
37 |
from dulwich.repo import MemoryRepo |
38 |
from dulwich.tests import ( |
39 |
TestCase, |
40 |
) |
41 |
from dulwich.tests.utils import ( |
42 |
build_commit_graph, |
43 |
) |
44 |
|
45 |
|
46 |
class ParseObjectTests(TestCase): |
47 |
"""Test parse_object."""
|
48 |
|
49 |
def test_nonexistent(self): |
50 |
r = MemoryRepo() |
51 |
self.assertRaises(KeyError, parse_object, r, "thisdoesnotexist") |
52 |
|
53 |
def test_blob_by_sha(self): |
54 |
r = MemoryRepo() |
55 |
b = Blob.from_string(b"Blah")
|
56 |
r.object_store.add_object(b) |
57 |
self.assertEqual(b, parse_object(r, b.id))
|
58 |
|
59 |
|
60 |
class ParseCommitRangeTests(TestCase): |
61 |
"""Test parse_commit_range."""
|
62 |
|
63 |
def test_nonexistent(self): |
64 |
r = MemoryRepo() |
65 |
self.assertRaises(KeyError, parse_commit_range, r, "thisdoesnotexist") |
66 |
|
67 |
def test_commit_by_sha(self): |
68 |
r = MemoryRepo() |
69 |
c1, c2, c3 = build_commit_graph(r.object_store, [[1], [2, 1], |
70 |
[3, 1, 2]]) |
71 |
self.assertEqual([c1], list(parse_commit_range(r, c1.id))) |
72 |
|
73 |
|
74 |
class ParseRefTests(TestCase): |
75 |
def test_nonexistent(self): |
76 |
r = {} |
77 |
self.assertRaises(KeyError, parse_ref, r, b"thisdoesnotexist") |
78 |
|
79 |
def test_ambiguous_ref(self): |
80 |
r = {b"ambig1": 'bla', |
81 |
b"refs/ambig1": 'bla', |
82 |
b"refs/tags/ambig1": 'bla', |
83 |
b"refs/heads/ambig1": 'bla', |
84 |
b"refs/remotes/ambig1": 'bla', |
85 |
b"refs/remotes/ambig1/HEAD": "bla"} |
86 |
self.assertEqual(b"ambig1", parse_ref(r, b"ambig1")) |
87 |
|
88 |
def test_ambiguous_ref2(self): |
89 |
r = {b"refs/ambig2": 'bla', |
90 |
b"refs/tags/ambig2": 'bla', |
91 |
b"refs/heads/ambig2": 'bla', |
92 |
b"refs/remotes/ambig2": 'bla', |
93 |
b"refs/remotes/ambig2/HEAD": "bla"} |
94 |
self.assertEqual(b"refs/ambig2", parse_ref(r, b"ambig2")) |
95 |
|
96 |
def test_ambiguous_tag(self): |
97 |
r = {b"refs/tags/ambig3": 'bla', |
98 |
b"refs/heads/ambig3": 'bla', |
99 |
b"refs/remotes/ambig3": 'bla', |
100 |
b"refs/remotes/ambig3/HEAD": "bla"} |
101 |
self.assertEqual(b"refs/tags/ambig3", parse_ref(r, b"ambig3")) |
102 |
|
103 |
def test_ambiguous_head(self): |
104 |
r = {b"refs/heads/ambig4": 'bla', |
105 |
b"refs/remotes/ambig4": 'bla', |
106 |
b"refs/remotes/ambig4/HEAD": "bla"} |
107 |
self.assertEqual(b"refs/heads/ambig4", parse_ref(r, b"ambig4")) |
108 |
|
109 |
def test_ambiguous_remote(self): |
110 |
r = {b"refs/remotes/ambig5": 'bla', |
111 |
b"refs/remotes/ambig5/HEAD": "bla"} |
112 |
self.assertEqual(b"refs/remotes/ambig5", parse_ref(r, b"ambig5")) |
113 |
|
114 |
def test_ambiguous_remote_head(self): |
115 |
r = {b"refs/remotes/ambig6/HEAD": "bla"} |
116 |
self.assertEqual(b"refs/remotes/ambig6/HEAD", parse_ref(r, b"ambig6")) |
117 |
|
118 |
def test_heads_full(self): |
119 |
r = {b"refs/heads/foo": "bla"} |
120 |
self.assertEqual(b"refs/heads/foo", parse_ref(r, b"refs/heads/foo")) |
121 |
|
122 |
def test_heads_partial(self): |
123 |
r = {b"refs/heads/foo": "bla"} |
124 |
self.assertEqual(b"refs/heads/foo", parse_ref(r, b"heads/foo")) |
125 |
|
126 |
def test_tags_partial(self): |
127 |
r = {b"refs/tags/foo": "bla"} |
128 |
self.assertEqual(b"refs/tags/foo", parse_ref(r, b"tags/foo")) |
129 |
|
130 |
|
131 |
class ParseRefsTests(TestCase): |
132 |
|
133 |
def test_nonexistent(self): |
134 |
r = {} |
135 |
self.assertRaises(KeyError, parse_refs, r, [b"thisdoesnotexist"]) |
136 |
|
137 |
def test_head(self): |
138 |
r = {b"refs/heads/foo": "bla"} |
139 |
self.assertEqual([b"refs/heads/foo"], parse_refs(r, [b"foo"])) |
140 |
|
141 |
def test_full(self): |
142 |
r = {b"refs/heads/foo": "bla"} |
143 |
self.assertEqual([b"refs/heads/foo"], parse_refs(r, b"refs/heads/foo")) |
144 |
|
145 |
|
146 |
class ParseReftupleTests(TestCase): |
147 |
|
148 |
def test_nonexistent(self): |
149 |
r = {} |
150 |
self.assertRaises(KeyError, parse_reftuple, r, r, b"thisdoesnotexist") |
151 |
|
152 |
def test_head(self): |
153 |
r = {b"refs/heads/foo": "bla"} |
154 |
self.assertEqual((b"refs/heads/foo", b"refs/heads/foo", False), |
155 |
parse_reftuple(r, r, b"foo"))
|
156 |
self.assertEqual((b"refs/heads/foo", b"refs/heads/foo", True), |
157 |
parse_reftuple(r, r, b"+foo"))
|
158 |
self.assertEqual((b"refs/heads/foo", b"refs/heads/foo", True), |
159 |
parse_reftuple(r, {}, b"+foo"))
|
160 |
|
161 |
def test_full(self): |
162 |
r = {b"refs/heads/foo": "bla"} |
163 |
self.assertEqual((b"refs/heads/foo", b"refs/heads/foo", False), |
164 |
parse_reftuple(r, r, b"refs/heads/foo"))
|
165 |
|
166 |
def test_no_left_ref(self): |
167 |
r = {b"refs/heads/foo": "bla"} |
168 |
self.assertEqual((None, b"refs/heads/foo", False), |
169 |
parse_reftuple(r, r, b":refs/heads/foo"))
|
170 |
|
171 |
def test_no_right_ref(self): |
172 |
r = {b"refs/heads/foo": "bla"} |
173 |
self.assertEqual((b"refs/heads/foo", None, False), |
174 |
parse_reftuple(r, r, b"refs/heads/foo:"))
|
175 |
|
176 |
|
177 |
class ParseReftuplesTests(TestCase): |
178 |
|
179 |
def test_nonexistent(self): |
180 |
r = {} |
181 |
self.assertRaises(KeyError, parse_reftuples, r, r, |
182 |
[b"thisdoesnotexist"])
|
183 |
|
184 |
def test_head(self): |
185 |
r = {b"refs/heads/foo": "bla"} |
186 |
self.assertEqual([(b"refs/heads/foo", b"refs/heads/foo", False)], |
187 |
parse_reftuples(r, r, [b"foo"]))
|
188 |
|
189 |
def test_full(self): |
190 |
r = {b"refs/heads/foo": "bla"} |
191 |
self.assertEqual([(b"refs/heads/foo", b"refs/heads/foo", False)], |
192 |
parse_reftuples(r, r, b"refs/heads/foo"))
|