bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.211.2
by James Westby
Make it more like a real project. |
1 |
# test_repository.py -- tests for repository.py
|
2 |
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; version 2
|
|
7 |
# of the License.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
17 |
# MA 02110-1301, USA.
|
|
18 |
||
|
0.211.1
by James Westby
Start the python-git project. |
19 |
import os |
20 |
import unittest |
|
21 |
||
|
0.211.4
by James Westby
Add methods to repo to get objects of a certain type. |
22 |
from git.errors import (NotCommitError, |
23 |
NotTreeError, |
|
24 |
NotBlobError, |
|
25 |
)
|
|
|
0.211.1
by James Westby
Start the python-git project. |
26 |
from git.repository import Repository |
27 |
||
28 |
class RepositoryTests(unittest.TestCase): |
|
29 |
||
30 |
def open_repo(self, name): |
|
31 |
return Repository(os.path.join(os.path.dirname(__file__), |
|
32 |
'data/repos', name, '.git')) |
|
33 |
||
34 |
def test_simple_props(self): |
|
35 |
r = self.open_repo('a') |
|
36 |
basedir = os.path.join(os.path.dirname(__file__), 'data/repos/a/.git') |
|
37 |
self.assertEqual(r.basedir(), basedir) |
|
38 |
self.assertEqual(r.object_dir(), os.path.join(basedir, 'objects')) |
|
39 |
||
40 |
def test_ref(self): |
|
41 |
r = self.open_repo('a') |
|
42 |
self.assertEqual(r.ref('master'), |
|
43 |
'a90fa2d900a17e99b433217e988c4eb4a2e9a097') |
|
44 |
||
45 |
def test_head(self): |
|
46 |
r = self.open_repo('a') |
|
47 |
self.assertEqual(r.head(), 'a90fa2d900a17e99b433217e988c4eb4a2e9a097') |
|
48 |
||
49 |
def test_get_object(self): |
|
50 |
r = self.open_repo('a') |
|
51 |
obj = r.get_object(r.head()) |
|
52 |
self.assertEqual(obj._type, 'commit') |
|
53 |
||
54 |
def test_get_object_non_existant(self): |
|
55 |
r = self.open_repo('a') |
|
56 |
obj = r.get_object('b91fa4d900g17e99b433218e988c4eb4a3e9a097') |
|
57 |
self.assertEqual(obj, None) |
|
58 |
||
|
0.211.4
by James Westby
Add methods to repo to get objects of a certain type. |
59 |
def test_get_commit(self): |
60 |
r = self.open_repo('a') |
|
61 |
obj = r.get_commit(r.head()) |
|
62 |
self.assertEqual(obj._type, 'commit') |
|
63 |
||
64 |
def test_get_commit_not_commit(self): |
|
65 |
r = self.open_repo('a') |
|
66 |
self.assertRaises(NotCommitError, |
|
67 |
r.get_commit, '4f2e6529203aa6d44b5af6e3292c837ceda003f9') |
|
68 |
||
69 |
def test_get_tree(self): |
|
70 |
r = self.open_repo('a') |
|
71 |
commit = r.get_commit(r.head()) |
|
72 |
tree = r.get_tree(commit.tree()) |
|
73 |
self.assertEqual(tree._type, 'tree') |
|
74 |
self.assertEqual(tree.sha().hexdigest(), commit.tree()) |
|
75 |
||
76 |
def test_get_tree_not_tree(self): |
|
77 |
r = self.open_repo('a') |
|
78 |
self.assertRaises(NotTreeError, r.get_tree, r.head()) |
|
79 |
||
80 |
def test_get_blob(self): |
|
81 |
r = self.open_repo('a') |
|
82 |
commit = r.get_commit(r.head()) |
|
83 |
tree = r.get_tree(commit.tree()) |
|
84 |
blob_sha = tree.entries()[0][2] |
|
85 |
blob = r.get_blob(blob_sha) |
|
86 |
self.assertEqual(blob._type, 'blob') |
|
87 |
self.assertEqual(blob.sha().hexdigest(), blob_sha) |
|
88 |
||
89 |
def test_get_blob(self): |
|
90 |
r = self.open_repo('a') |
|
91 |
self.assertRaises(NotBlobError, r.get_blob, r.head()) |
|
92 |