3434import os
3535from datetime import datetime
3636from git .objects .util import tzoffset , utc
37+ from mock import Mock
3738
3839
3940def assert_commit_serialization (rwrepo , commit_id , print_performance_info = False ):
@@ -342,7 +343,9 @@ def test_gpgsig(self):
342343 cstream = BytesIO ()
343344 cmt ._serialize (cstream )
344345 assert re .search (r"^gpgsig <test\n dummy\n sig>$" , cstream .getvalue ().decode ('ascii' ), re .MULTILINE )
345-
346+
347+ self .assert_gpgsig_deserialization (cstream )
348+
346349 cstream .seek (0 )
347350 cmt .gpgsig = None
348351 cmt ._deserialize (cstream )
@@ -352,6 +355,31 @@ def test_gpgsig(self):
352355 cstream = BytesIO ()
353356 cmt ._serialize (cstream )
354357 assert not re .search (r"^gpgsig " , cstream .getvalue ().decode ('ascii' ), re .MULTILINE )
358+
359+ def assert_gpgsig_deserialization (self , cstream ):
360+ assert 'gpgsig' in 'precondition: need gpgsig'
361+
362+ class RepoMock :
363+ def __init__ (self , bytestr ):
364+ self .bytestr = bytestr
365+
366+ @property
367+ def odb (self ):
368+ class ODBMock :
369+ def __init__ (self , bytestr ):
370+ self .bytestr = bytestr
371+
372+ def stream (self , * args ):
373+ stream = Mock (spec_set = ['read' ], return_value = self .bytestr )
374+ stream .read .return_value = self .bytestr
375+ return ('binsha' , 'typename' , 'size' , stream )
376+
377+ return ODBMock (self .bytestr )
378+
379+ repo_mock = RepoMock (cstream .getvalue ())
380+ for field in Commit .__slots__ :
381+ c = Commit (repo_mock , b'x' * 20 )
382+ assert getattr (c , field ) is not None
355383
356384 def test_datetimes (self ):
357385 commit = self .rorepo .commit ('4251bd5' )
0 commit comments