22
22
from git .repo .fun import touch
23
23
from git .test .lib import (
24
24
TestBase ,
25
- assert_equal ,
26
25
assert_not_equal ,
27
26
with_rw_repo ,
28
27
fixture_path ,
34
33
import os .path as osp
35
34
36
35
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 ):
43
37
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
47
44
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
55
48
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 )
58
56
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' ))
63
59
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 )
70
64
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 )
76
71
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
81
77
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
86
82
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
87
87
88
- class TestCommit (TestBase ):
88
+
89
+ class TestCommit (TestCommitSerialization ):
89
90
90
91
def test_bake (self ):
91
92
@@ -94,8 +95,8 @@ def test_bake(self):
94
95
self .assertRaises (AttributeError , setattr , commit , 'someattr' , 1 )
95
96
commit .author # bake
96
97
97
- assert_equal ("Sebastian Thiel" , commit .author .name )
98
- assert_equal (
"[email protected] " ,
commit .
author .
email )
98
+ self . assertEqual ("Sebastian Thiel" , commit .author .name )
99
+ self . assertEqual (
"[email protected] " ,
commit .
author .
email )
99
100
self .assertEqual (commit .author , commit .committer )
100
101
assert isinstance (commit .authored_date , int ) and isinstance (commit .committed_date , int )
101
102
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):
220
221
'933d23bf95a5bd1624fbcdf328d904e1fa173474'
221
222
)
222
223
for sha1 , commit in zip (expected_ids , commits ):
223
- assert_equal (sha1 , commit .hexsha )
224
+ self . assertEqual (sha1 , commit .hexsha )
224
225
225
226
@with_rw_directory
226
227
def test_ambiguous_arg_iteration (self , rw_dir ):
@@ -242,17 +243,17 @@ def test_list(self):
242
243
243
244
def test_str (self ):
244
245
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 ))
246
247
247
248
def test_repr (self ):
248
249
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 ))
250
251
251
252
def test_equality (self ):
252
253
commit1 = Commit (self .rorepo , Commit .NULL_BIN_SHA )
253
254
commit2 = Commit (self .rorepo , Commit .NULL_BIN_SHA )
254
255
commit3 = Commit (self .rorepo , "\1 " * 20 )
255
- assert_equal (commit1 , commit2 )
256
+ self . assertEqual (commit1 , commit2 )
256
257
assert_not_equal (commit2 , commit3 )
257
258
258
259
def test_iter_parents (self ):
@@ -272,7 +273,7 @@ def test_name_rev(self):
272
273
@with_rw_repo ('HEAD' , bare = True )
273
274
def test_serialization (self , rwrepo ):
274
275
# create all commits of our repo
275
- assert_commit_serialization (rwrepo , '0.1.6' )
276
+ self . assert_commit_serialization (rwrepo , '0.1.6' )
276
277
277
278
def test_serialization_unicode_support (self ):
278
279
self .assertEqual (Commit .default_encoding .lower (), 'utf-8' )
0 commit comments