/brz/remove-bazaar

To get this branch, use:
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.6 by James Westby
Error when a commit isn't found to avoid problems later.
22
from git import errors
0.211.1 by James Westby
Start the python-git project.
23
from git.repository import Repository
24
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
25
missing_sha = 'b91fa4d900g17e99b433218e988c4eb4a3e9a097'
26
0.211.1 by James Westby
Start the python-git project.
27
class RepositoryTests(unittest.TestCase):
28
29
  def open_repo(self, name):
30
    return Repository(os.path.join(os.path.dirname(__file__),
31
                      'data/repos', name, '.git'))
32
33
  def test_simple_props(self):
34
    r = self.open_repo('a')
35
    basedir = os.path.join(os.path.dirname(__file__), 'data/repos/a/.git')
36
    self.assertEqual(r.basedir(), basedir)
37
    self.assertEqual(r.object_dir(), os.path.join(basedir, 'objects'))
38
39
  def test_ref(self):
40
    r = self.open_repo('a')
41
    self.assertEqual(r.ref('master'),
42
                     'a90fa2d900a17e99b433217e988c4eb4a2e9a097')
43
44
  def test_head(self):
45
    r = self.open_repo('a')
46
    self.assertEqual(r.head(), 'a90fa2d900a17e99b433217e988c4eb4a2e9a097')
47
48
  def test_get_object(self):
49
    r = self.open_repo('a')
50
    obj = r.get_object(r.head())
51
    self.assertEqual(obj._type, 'commit')
52
53
  def test_get_object_non_existant(self):
54
    r = self.open_repo('a')
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
55
    obj = r.get_object(missing_sha)
0.211.1 by James Westby
Start the python-git project.
56
    self.assertEqual(obj, None)
57
0.211.4 by James Westby
Add methods to repo to get objects of a certain type.
58
  def test_get_commit(self):
59
    r = self.open_repo('a')
60
    obj = r.get_commit(r.head())
61
    self.assertEqual(obj._type, 'commit')
62
63
  def test_get_commit_not_commit(self):
64
    r = self.open_repo('a')
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
65
    self.assertRaises(errors.NotCommitError,
0.211.4 by James Westby
Add methods to repo to get objects of a certain type.
66
                      r.get_commit, '4f2e6529203aa6d44b5af6e3292c837ceda003f9')
67
68
  def test_get_tree(self):
69
    r = self.open_repo('a')
70
    commit = r.get_commit(r.head())
71
    tree = r.get_tree(commit.tree())
72
    self.assertEqual(tree._type, 'tree')
73
    self.assertEqual(tree.sha().hexdigest(), commit.tree())
74
75
  def test_get_tree_not_tree(self):
76
    r = self.open_repo('a')
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
77
    self.assertRaises(errors.NotTreeError, r.get_tree, r.head())
0.211.4 by James Westby
Add methods to repo to get objects of a certain type.
78
79
  def test_get_blob(self):
80
    r = self.open_repo('a')
81
    commit = r.get_commit(r.head())
82
    tree = r.get_tree(commit.tree())
83
    blob_sha = tree.entries()[0][2]
84
    blob = r.get_blob(blob_sha)
85
    self.assertEqual(blob._type, 'blob')
86
    self.assertEqual(blob.sha().hexdigest(), blob_sha)
87
88
  def test_get_blob(self):
89
    r = self.open_repo('a')
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
90
    self.assertRaises(errors.NotBlobError, r.get_blob, r.head())
0.211.4 by James Westby
Add methods to repo to get objects of a certain type.
91
0.211.5 by James Westby
Add support for getting the revision graph from a head.
92
  def test_linear_history(self):
93
    r = self.open_repo('a')
94
    history = r.revision_history(r.head())
95
    shas = [c.sha().hexdigest() for c in history]
96
    self.assertEqual(shas, [r.head(),
97
                            '2a72d929692c41d8554c07f6301757ba18a65d91'])
98
99
  def test_merge_history(self):
100
    r = self.open_repo('simple_merge')
101
    history = r.revision_history(r.head())
102
    shas = [c.sha().hexdigest() for c in history]
103
    self.assertEqual(shas, ['5dac377bdded4c9aeb8dff595f0faeebcc8498cc',
104
                            'ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
105
                            '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6',
106
                            '60dacdc733de308bb77bb76ce0fb0f9b44c9769e',
107
                            '0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
108
0.211.6 by James Westby
Error when a commit isn't found to avoid problems later.
109
  def test_revision_history_missing_commit(self):
110
    r = self.open_repo('simple_merge')
111
    self.assertRaises(errors.MissingCommitError, r.revision_history,
112
                      missing_sha)
0.211.5 by James Westby
Add support for getting the revision graph from a head.
113