From 101fb1df36f29469ee8f4e0b9e7846d856b87daa Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 17:15:07 +0200 Subject: blob tests fixed to deal with changes to the Blob type --- lib/git/blob.py | 6 +++--- test/git/test_blob.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/git/blob.py b/lib/git/blob.py index d1b928cd..c6fb9c1d 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -43,10 +43,10 @@ class Blob(base.Object): Returns git.Blob """ - super(Blob,self).__init__(repo, id, "blob") + super(Blob,self).__init__(repo, id) self.mode = mode self.path = path - self._data_stored = None + self._data_stored = type(None) # serves as marker to prevent baking in this case @property def data(self): @@ -59,7 +59,7 @@ class Blob(base.Object): NOTE The data will be cached after the first access. """ - self._data_stored = self._data_stored or self.repo.git.cat_file(self.id, p=True, with_raw_output=True) + self._data_stored = ( self._data_stored is not type(None) and self._data_stored ) or self.repo.git.cat_file(self.id, p=True, with_raw_output=True) return self._data_stored @property diff --git a/test/git/test_blob.py b/test/git/test_blob.py index e2ac22e1..94d3a33b 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -31,12 +31,13 @@ class TestBlob(object): @patch_object(Git, '_call_process') def test_should_cache_data(self, git): git.return_value = fixture('cat_file_blob') - blob = Blob(self.repo, **{'id': 'abc'}) + bid = '787b92b63f629398f3d2ceb20f7f0c2578259e84' + blob = Blob(self.repo, bid) blob.data blob.data assert_true(git.called) assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + assert_equal(git.call_args, (('cat_file', bid), {'p': True, 'with_raw_output': True})) @patch_object(Git, '_call_process') def test_should_return_file_size(self, git): @@ -61,7 +62,7 @@ class TestBlob(object): assert_equal("image/png", blob.mime_type) def test_mime_type_should_return_text_plain_for_unknown_types(self): - blob = Blob(self.repo, **{'id': 'abc'}) + blob = Blob(self.repo, **{'id': 'abc','path': 'something'}) assert_equal("text/plain", blob.mime_type) @patch_object(Git, '_call_process') -- cgit v1.2.1