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_utils.py @ 959
History | View | Annotate | Download (3.35 KB)
1 |
# test_utils.py -- Tests for git test utilities.
|
---|---|
2 |
# Copyright (C) 2010 Google, Inc.
|
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 git test utilities."""
|
22 |
|
23 |
from dulwich.object_store import ( |
24 |
MemoryObjectStore, |
25 |
) |
26 |
from dulwich.objects import ( |
27 |
Blob, |
28 |
) |
29 |
from dulwich.tests import ( |
30 |
TestCase, |
31 |
) |
32 |
from dulwich.tests.utils import ( |
33 |
make_object, |
34 |
build_commit_graph, |
35 |
) |
36 |
|
37 |
|
38 |
class BuildCommitGraphTest(TestCase): |
39 |
|
40 |
def setUp(self): |
41 |
super(BuildCommitGraphTest, self).setUp() |
42 |
self.store = MemoryObjectStore()
|
43 |
|
44 |
def test_linear(self): |
45 |
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]]) |
46 |
for obj_id in [c1.id, c2.id, c1.tree, c2.tree]: |
47 |
self.assertTrue(obj_id in self.store) |
48 |
self.assertEqual([], c1.parents)
|
49 |
self.assertEqual([c1.id], c2.parents)
|
50 |
self.assertEqual(c1.tree, c2.tree)
|
51 |
self.assertEqual([], self.store[c1.tree].items()) |
52 |
self.assertTrue(c2.commit_time > c1.commit_time)
|
53 |
|
54 |
def test_merge(self): |
55 |
c1, c2, c3, c4 = build_commit_graph(self.store,
|
56 |
[[1], [2, 1], [3, 1], [4, 2, 3]]) |
57 |
self.assertEqual([c2.id, c3.id], c4.parents)
|
58 |
self.assertTrue(c4.commit_time > c2.commit_time)
|
59 |
self.assertTrue(c4.commit_time > c3.commit_time)
|
60 |
|
61 |
def test_missing_parent(self): |
62 |
self.assertRaises(ValueError, build_commit_graph, self.store, |
63 |
[[1], [3, 2], [2, 1]]) |
64 |
|
65 |
def test_trees(self): |
66 |
a1 = make_object(Blob, data=b'aaa1')
|
67 |
a2 = make_object(Blob, data=b'aaa2')
|
68 |
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]], |
69 |
trees={1: [(b'a', a1)], |
70 |
2: [(b'a', a2, 0o100644)]}) |
71 |
self.assertEqual((0o100644, a1.id), self.store[c1.tree][b'a']) |
72 |
self.assertEqual((0o100644, a2.id), self.store[c2.tree][b'a']) |
73 |
|
74 |
def test_attrs(self): |
75 |
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]], |
76 |
attrs={1: {'message': b'Hooray!'}}) |
77 |
self.assertEqual(b'Hooray!', c1.message) |
78 |
self.assertEqual(b'Commit 2', c2.message) |
79 |
|
80 |
def test_commit_time(self): |
81 |
c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]], |
82 |
attrs={1: {'commit_time': 124}, |
83 |
2: {'commit_time': 123}}) |
84 |
self.assertEqual(124, c1.commit_time) |
85 |
self.assertEqual(123, c2.commit_time) |
86 |
self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)
|