Removed method_missing since it was only used in one place.
[jelmer/gitpython.git] / test / git / test_blob.py
1 # test_blob.py
2 # Copyright (C) 2008 Michael Trier (mtrier@gmail.com) and contributors
3 #
4 # This module is part of GitPython and is released under
5 # the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
7 import time
8 from test.testlib import *
9 from git import *
10
11 class TestBlob(object):
12     def setup(self):
13         self.repo = Repo(GIT_REPO)
14     
15     @patch(Git, '_call_process')
16     def test_should_return_blob_contents(self, git):
17         git.return_value = fixture('cat_file_blob')
18         blob = Blob(self.repo, **{'id': 'abc'})
19         assert_equal("Hello world", blob.data)
20         assert_true(git.called)
21         assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True}))
22     
23     @patch(Git, '_call_process')
24     def test_should_cache_data(self, git):
25         git.return_value = fixture('cat_file_blob')
26         blob = Blob(self.repo, **{'id': 'abc'})
27         blob.data
28         blob.data
29         assert_true(git.called)
30         assert_equal(git.call_count, 1)
31         assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True}))
32
33     @patch(Git, '_call_process')
34     def test_should_return_file_size(self, git):
35         git.return_value = fixture('cat_file_blob_size')
36         blob = Blob(self.repo, **{'id': 'abc'})
37         assert_equal(11, blob.size)
38         assert_true(git.called)
39         assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True}))
40
41     @patch(Git, '_call_process')
42     def test_should_cache_file_size(self, git):
43         git.return_value = fixture('cat_file_blob_size')
44         blob = Blob(self.repo, **{'id': 'abc'})
45         assert_equal(11, blob.size)
46         assert_equal(11, blob.size)        
47         assert_true(git.called)
48         assert_equal(git.call_count, 1)
49         assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True}))
50   
51     def test_mime_type_should_return_mime_type_for_known_types(self):
52         blob = Blob(self.repo, **{'id': 'abc', 'name': 'foo.png'})
53         assert_equal("image/png", blob.mime_type)
54   
55     def test_mime_type_should_return_text_plain_for_unknown_types(self):
56         blob = Blob(self.repo, **{'id': 'abc'})
57         assert_equal("text/plain", blob.mime_type)
58   
59     @patch(Git, '_call_process')
60     def test_should_display_blame_information(self, git):
61         git.return_value = fixture('blame')
62         b = Blob.blame(self.repo, 'master', 'lib/git.py')
63         assert_equal(13, len(b))
64         # assert_equal(25, reduce(lambda acc, x: acc + len(x[-1]), b))
65         assert_equal(hash(b[0][0]), hash(b[9][0]))
66         c = b[0][0]
67         assert_true(git.called)
68         assert_equal(git.call_args, (('blame', 'master', '--', 'lib/git.py'), {'p': True}))
69         
70         assert_equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', c.id)
71         assert_equal('Tom Preston-Werner', c.author.name)
72         assert_equal('tom@mojombo.com', c.author.email)
73         assert_equal(time.gmtime(1191997100), c.authored_date)
74         assert_equal('Tom Preston-Werner', c.committer.name)
75         assert_equal('tom@mojombo.com', c.committer.email)
76         assert_equal(time.gmtime(1191997100), c.committed_date)
77         assert_equal('initial grit setup', c.message)
78   
79     def test_should_return_appropriate_representation(self):
80         blob = Blob(self.repo, **{'id': 'abc'})
81         assert_equal('<GitPython.Blob "abc">', repr(blob))