/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_objects.py -- tests for objects.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
22
from git.objects import (Blob,
23
                         Tree,
24
                         Commit,
25
                         )
26
27
a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
28
b_sha = '2969be3e8ee1c0222396a5611407e4769f14e54b'
29
c_sha = '954a536f7819d40e6f637f849ee187dd10066349'
30
tree_sha = '70c190eb48fa8bbb50ddc692a17b44cb781af7f6'
31
32
class BlobReadTests(unittest.TestCase):
33
  """Test decompression of blobs"""
34
35
  def get_sha_file(self, obj, base, sha):
36
    return obj.from_file(os.path.join(os.path.dirname(__file__),
37
                                      'data', base, sha))
38
39
  def get_blob(self, sha):
40
    """Return the blob named sha from the test data dir"""
41
    return self.get_sha_file(Blob, 'blobs', sha)
42
43
  def get_tree(self, sha):
44
    return self.get_sha_file(Tree, 'trees', sha)
45
46
  def get_commit(self, sha):
47
    return self.get_sha_file(Commit, 'commits', sha)
48
49
  def test_decompress_simple_blob(self):
50
    b = self.get_blob(a_sha)
51
    self.assertEqual(b.text(), 'test 1\n')
52
    self.assertEqual(b.sha().hexdigest(), a_sha)
53
54
  def test_parse_empty_blob_object(self):
55
    sha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
56
    b = self.get_blob(sha)
57
    self.assertEqual(b.text(), '')
58
    self.assertEqual(b.sha().hexdigest(), sha)
59
60
  def test_create_blob_from_string(self):
61
    string = 'test 2\n'
62
    b = Blob.from_string(string)
63
    self.assertEqual(b.text(), string)
64
    self.assertEqual(b.sha().hexdigest(), b_sha)
65
66
  def test_parse_legacy_blob(self):
67
    string = 'test 3\n'
68
    b = self.get_blob(c_sha)
69
    self.assertEqual(b.text(), string)
70
    self.assertEqual(b.sha().hexdigest(), c_sha)
71
72
  def test_read_tree_from_file(self):
73
    t = self.get_tree(tree_sha)
74
    self.assertEqual(t.entries()[0], (33188, 'a', a_sha))
75
    self.assertEqual(t.entries()[1], (33188, 'b', b_sha))
76
77
  def test_read_commit_from_file(self):
78
    sha = '60dacdc733de308bb77bb76ce0fb0f9b44c9769e'
79
    c = self.get_commit(sha)
80
    self.assertEqual(c.tree(), tree_sha)
81
    self.assertEqual(c.parents(), ['0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
82
    self.assertEqual(c.author(),
83
        'James Westby <jw+debian@jameswestby.net> 1174759230 +0000')
84
    self.assertEqual(c.committer(),
85
        'James Westby <jw+debian@jameswestby.net> 1174759230 +0000')
86
    self.assertEqual(c.message(), 'Test commit\n')
87
88
  def test_read_commit_no_parents(self):
89
    sha = '0d89f20333fbb1d2f3a94da77f4981373d8f4310'
90
    c = self.get_commit(sha)
91
    self.assertEqual(c.tree(), '90182552c4a85a45ec2a835cadc3451bebdfe870')
92
    self.assertEqual(c.parents(), [])
93
    self.assertEqual(c.author(),
94
        'James Westby <jw+debian@jameswestby.net> 1174758034 +0000')
95
    self.assertEqual(c.committer(),
96
        'James Westby <jw+debian@jameswestby.net> 1174758034 +0000')
97
    self.assertEqual(c.message(), 'Test commit\n')
98
99
  def test_read_commit_two_parents(self):
100
    sha = '5dac377bdded4c9aeb8dff595f0faeebcc8498cc'
101
    c = self.get_commit(sha)
102
    self.assertEqual(c.tree(), 'd80c186a03f423a81b39df39dc87fd269736ca86')
103
    self.assertEqual(c.parents(), ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
104
                                   '4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'])
105
    self.assertEqual(c.author(),
106
        'James Westby <jw+debian@jameswestby.net> 1174773719 +0000')
107
    self.assertEqual(c.committer(),
108
        'James Westby <jw+debian@jameswestby.net> 1174773719 +0000')
109
    self.assertEqual(c.message(), 'Merge ../b\n')
110