34
34
import os
35
35
from datetime import datetime
36
36
from git .objects .util import tzoffset , utc
37
+ from mock import Mock
37
38
38
39
39
40
def assert_commit_serialization (rwrepo , commit_id , print_performance_info = False ):
@@ -342,7 +343,9 @@ def test_gpgsig(self):
342
343
cstream = BytesIO ()
343
344
cmt ._serialize (cstream )
344
345
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
+
346
349
cstream .seek (0 )
347
350
cmt .gpgsig = None
348
351
cmt ._deserialize (cstream )
@@ -352,6 +355,32 @@ def test_gpgsig(self):
352
355
cstream = BytesIO ()
353
356
cmt ._serialize (cstream )
354
357
assert not re .search (r"^gpgsig " , cstream .getvalue ().decode ('ascii' ), re .MULTILINE )
358
+
359
+
360
+ def assert_gpgsig_deserialization (self , cstream ):
361
+ assert 'gpgsig' in 'precondition: need gpgsig'
362
+
363
+ class RepoMock :
364
+ def __init__ (self , bytestr ):
365
+ self .bytestr = bytestr
366
+
367
+ @property
368
+ def odb (self ):
369
+ class ODBMock :
370
+ def __init__ (self , bytestr ):
371
+ self .bytestr = bytestr
372
+
373
+ def stream (self , * args ):
374
+ stream = Mock (spec_set = ['read' ], return_value = self .bytestr )
375
+ stream .read .return_value = self .bytestr
376
+ return ('binsha' , 'typename' , 'size' , stream )
377
+
378
+ return ODBMock (self .bytestr )
379
+
380
+ repo_mock = RepoMock (cstream .getvalue ())
381
+ for field in Commit .__slots__ :
382
+ c = Commit (repo_mock , b'x' * 20 )
383
+ assert getattr (c , field ) is not None
355
384
356
385
def test_datetimes (self ):
357
386
commit = self .rorepo .commit ('4251bd5' )
0 commit comments