2222from git .repo .fun import touch
2323from git .test .lib import (
2424 TestBase ,
25- assert_equal ,
2625 assert_not_equal ,
2726 with_rw_repo ,
2827 fixture_path ,
3433import os .path as osp
3534
3635
37- def assert_commit_serialization (rwrepo , commit_id , print_performance_info = False ):
38- """traverse all commits in the history of commit identified by commit_id and check
39- if the serialization works.
40- :param print_performance_info: if True, we will show how fast we are"""
41- ns = 0 # num serializations
42- nds = 0 # num deserializations
36+ class TestCommitSerialization (TestBase ):
4337
44- st = time .time ()
45- for cm in rwrepo .commit (commit_id ).traverse ():
46- nds += 1
38+ def assert_commit_serialization (self , rwrepo , commit_id , print_performance_info = False ):
39+ """traverse all commits in the history of commit identified by commit_id and check
40+ if the serialization works.
41+ :param print_performance_info: if True, we will show how fast we are"""
42+ ns = 0 # num serializations
43+ nds = 0 # num deserializations
4744
48- # assert that we deserialize commits correctly, hence we get the same
49- # sha on serialization
50- stream = BytesIO ()
51- cm ._serialize (stream )
52- ns += 1
53- streamlen = stream .tell ()
54- stream .seek (0 )
45+ st = time .time ()
46+ for cm in rwrepo .commit (commit_id ).traverse ():
47+ nds += 1
5548
56- istream = rwrepo .odb .store (IStream (Commit .type , streamlen , stream ))
57- assert_equal (istream .hexsha , cm .hexsha .encode ('ascii' ))
49+ # assert that we deserialize commits correctly, hence we get the same
50+ # sha on serialization
51+ stream = BytesIO ()
52+ cm ._serialize (stream )
53+ ns += 1
54+ streamlen = stream .tell ()
55+ stream .seek (0 )
5856
59- nc = Commit (rwrepo , Commit .NULL_BIN_SHA , cm .tree ,
60- cm .author , cm .authored_date , cm .author_tz_offset ,
61- cm .committer , cm .committed_date , cm .committer_tz_offset ,
62- cm .message , cm .parents , cm .encoding )
57+ istream = rwrepo .odb .store (IStream (Commit .type , streamlen , stream ))
58+ self .assertEqual (istream .hexsha , cm .hexsha .encode ('ascii' ))
6359
64- assert_equal (nc .parents , cm .parents )
65- stream = BytesIO ()
66- nc ._serialize (stream )
67- ns += 1
68- streamlen = stream .tell ()
69- stream .seek (0 )
60+ nc = Commit (rwrepo , Commit .NULL_BIN_SHA , cm .tree ,
61+ cm .author , cm .authored_date , cm .author_tz_offset ,
62+ cm .committer , cm .committed_date , cm .committer_tz_offset ,
63+ cm .message , cm .parents , cm .encoding )
7064
71- # reuse istream
72- istream .size = streamlen
73- istream .stream = stream
74- istream .binsha = None
75- nc .binsha = rwrepo .odb .store (istream ).binsha
65+ self .assertEqual (nc .parents , cm .parents )
66+ stream = BytesIO ()
67+ nc ._serialize (stream )
68+ ns += 1
69+ streamlen = stream .tell ()
70+ stream .seek (0 )
7671
77- # if it worked, we have exactly the same contents !
78- assert_equal (nc .hexsha , cm .hexsha )
79- # END check commits
80- elapsed = time .time () - st
72+ # reuse istream
73+ istream .size = streamlen
74+ istream .stream = stream
75+ istream .binsha = None
76+ nc .binsha = rwrepo .odb .store (istream ).binsha
8177
82- if print_performance_info :
83- print ( "Serialized %i and deserialized %i commits in %f s ( (%f, %f) commits / s"
84- % ( ns , nds , elapsed , ns / elapsed , nds / elapsed ), file = sys . stderr )
85- # END handle performance info
78+ # if it worked, we have exactly the same contents !
79+ self . assertEqual ( nc . hexsha , cm . hexsha )
80+ # END check commits
81+ elapsed = time . time () - st
8682
83+ if print_performance_info :
84+ print ("Serialized %i and deserialized %i commits in %f s ( (%f, %f) commits / s"
85+ % (ns , nds , elapsed , ns / elapsed , nds / elapsed ), file = sys .stderr )
86+ # END handle performance info
8787
88- class TestCommit (TestBase ):
88+
89+ class TestCommit (TestCommitSerialization ):
8990
9091 def test_bake (self ):
9192
@@ -94,8 +95,8 @@ def test_bake(self):
9495 self .assertRaises (AttributeError , setattr , commit , 'someattr' , 1 )
9596 commit .author # bake
9697
97- assert_equal ("Sebastian Thiel" , commit .author .name )
98- assert_equal ("byronimo@gmail.com" , commit .author .email )
98+ self . assertEqual ("Sebastian Thiel" , commit .author .name )
99+ self . assertEqual ("byronimo@gmail.com" , commit .author .email )
99100 self .assertEqual (commit .author , commit .committer )
100101 assert isinstance (commit .authored_date , int ) and isinstance (commit .committed_date , int )
101102 assert isinstance (commit .author_tz_offset , int ) and isinstance (commit .committer_tz_offset , int )
@@ -220,7 +221,7 @@ def test_rev_list_bisect_all(self):
220221 '933d23bf95a5bd1624fbcdf328d904e1fa173474'
221222 )
222223 for sha1 , commit in zip (expected_ids , commits ):
223- assert_equal (sha1 , commit .hexsha )
224+ self . assertEqual (sha1 , commit .hexsha )
224225
225226 @with_rw_directory
226227 def test_ambiguous_arg_iteration (self , rw_dir ):
@@ -242,17 +243,17 @@ def test_list(self):
242243
243244 def test_str (self ):
244245 commit = Commit (self .rorepo , Commit .NULL_BIN_SHA )
245- assert_equal (Commit .NULL_HEX_SHA , str (commit ))
246+ self . assertEqual (Commit .NULL_HEX_SHA , str (commit ))
246247
247248 def test_repr (self ):
248249 commit = Commit (self .rorepo , Commit .NULL_BIN_SHA )
249- assert_equal ('<git.Commit "%s">' % Commit .NULL_HEX_SHA , repr (commit ))
250+ self . assertEqual ('<git.Commit "%s">' % Commit .NULL_HEX_SHA , repr (commit ))
250251
251252 def test_equality (self ):
252253 commit1 = Commit (self .rorepo , Commit .NULL_BIN_SHA )
253254 commit2 = Commit (self .rorepo , Commit .NULL_BIN_SHA )
254255 commit3 = Commit (self .rorepo , "\1 " * 20 )
255- assert_equal (commit1 , commit2 )
256+ self . assertEqual (commit1 , commit2 )
256257 assert_not_equal (commit2 , commit3 )
257258
258259 def test_iter_parents (self ):
@@ -272,7 +273,7 @@ def test_name_rev(self):
272273 @with_rw_repo ('HEAD' , bare = True )
273274 def test_serialization (self , rwrepo ):
274275 # create all commits of our repo
275- assert_commit_serialization (rwrepo , '0.1.6' )
276+ self . assert_commit_serialization (rwrepo , '0.1.6' )
276277
277278 def test_serialization_unicode_support (self ):
278279 self .assertEqual (Commit .default_encoding .lower (), 'utf-8' )
0 commit comments