1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# test_objects.py -- tests for objects.py
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import os
import unittest
from git.objects import (Blob,
Tree,
Commit,
)
a_sha = '6f670c0fb53f9463760b7295fbb814e965fb20c8'
b_sha = '2969be3e8ee1c0222396a5611407e4769f14e54b'
c_sha = '954a536f7819d40e6f637f849ee187dd10066349'
tree_sha = '70c190eb48fa8bbb50ddc692a17b44cb781af7f6'
class BlobReadTests(unittest.TestCase):
"""Test decompression of blobs"""
def get_sha_file(self, obj, base, sha):
return obj.from_file(os.path.join(os.path.dirname(__file__),
'data', base, sha))
def get_blob(self, sha):
"""Return the blob named sha from the test data dir"""
return self.get_sha_file(Blob, 'blobs', sha)
def get_tree(self, sha):
return self.get_sha_file(Tree, 'trees', sha)
def get_commit(self, sha):
return self.get_sha_file(Commit, 'commits', sha)
def test_decompress_simple_blob(self):
b = self.get_blob(a_sha)
self.assertEqual(b.text(), 'test 1\n')
self.assertEqual(b.sha().hexdigest(), a_sha)
def test_parse_empty_blob_object(self):
sha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
b = self.get_blob(sha)
self.assertEqual(b.text(), '')
self.assertEqual(b.sha().hexdigest(), sha)
def test_create_blob_from_string(self):
string = 'test 2\n'
b = Blob.from_string(string)
self.assertEqual(b.text(), string)
self.assertEqual(b.sha().hexdigest(), b_sha)
def test_parse_legacy_blob(self):
string = 'test 3\n'
b = self.get_blob(c_sha)
self.assertEqual(b.text(), string)
self.assertEqual(b.sha().hexdigest(), c_sha)
def test_read_tree_from_file(self):
t = self.get_tree(tree_sha)
self.assertEqual(t.entries()[0], (33188, 'a', a_sha))
self.assertEqual(t.entries()[1], (33188, 'b', b_sha))
def test_read_commit_from_file(self):
sha = '60dacdc733de308bb77bb76ce0fb0f9b44c9769e'
c = self.get_commit(sha)
self.assertEqual(c.tree(), tree_sha)
self.assertEqual(c.parents(), ['0d89f20333fbb1d2f3a94da77f4981373d8f4310'])
self.assertEqual(c.author(),
'James Westby <jw+debian@jameswestby.net> 1174759230 +0000')
self.assertEqual(c.committer(),
'James Westby <jw+debian@jameswestby.net> 1174759230 +0000')
self.assertEqual(c.message(), 'Test commit\n')
def test_read_commit_no_parents(self):
sha = '0d89f20333fbb1d2f3a94da77f4981373d8f4310'
c = self.get_commit(sha)
self.assertEqual(c.tree(), '90182552c4a85a45ec2a835cadc3451bebdfe870')
self.assertEqual(c.parents(), [])
self.assertEqual(c.author(),
'James Westby <jw+debian@jameswestby.net> 1174758034 +0000')
self.assertEqual(c.committer(),
'James Westby <jw+debian@jameswestby.net> 1174758034 +0000')
self.assertEqual(c.message(), 'Test commit\n')
def test_read_commit_two_parents(self):
sha = '5dac377bdded4c9aeb8dff595f0faeebcc8498cc'
c = self.get_commit(sha)
self.assertEqual(c.tree(), 'd80c186a03f423a81b39df39dc87fd269736ca86')
self.assertEqual(c.parents(), ['ab64bbdcc51b170d21588e5c5d391ee5c0c96dfd',
'4cffe90e0a41ad3f5190079d7c8f036bde29cbe6'])
self.assertEqual(c.author(),
'James Westby <jw+debian@jameswestby.net> 1174773719 +0000')
self.assertEqual(c.committer(),
'James Westby <jw+debian@jameswestby.net> 1174773719 +0000')
self.assertEqual(c.message(), 'Merge ../b\n')
|