Skip to content

Commit ab361cf

Browse files
committed
Replace assert_equal with assertEqual
Also change TestActor to subclass TestBase rather than object and create and use base TestCommitSerialization class for assert_commit_serialization method
1 parent 99471bb commit ab361cf

File tree

10 files changed

+135
-145
lines changed

10 files changed

+135
-145
lines changed

git/test/lib/asserts.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
from unittest.mock import patch
88

99
from nose.tools import (
10-
assert_equal, # @UnusedImport
1110
assert_not_equal, # @UnusedImport
1211
assert_raises, # @UnusedImport
1312
raises, # @UnusedImport
1413
assert_true, # @UnusedImport
1514
assert_false # @UnusedImport
1615
)
1716

18-
__all__ = ['assert_equal', 'assert_not_equal', 'assert_raises', 'patch', 'raises',
17+
__all__ = ['assert_not_equal', 'assert_raises', 'patch', 'raises',
1918
'assert_true', 'assert_false']

git/test/performance/test_commit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from .lib import TestBigRepoRW
1212
from git import Commit
1313
from gitdb import IStream
14-
from git.test.test_commit import assert_commit_serialization
14+
from git.test.test_commit import TestCommitSerialization
1515

1616

17-
class TestPerformance(TestBigRepoRW):
17+
class TestPerformance(TestBigRepoRW, TestCommitSerialization):
1818

1919
def tearDown(self):
2020
import gc
@@ -79,7 +79,7 @@ def test_commit_iteration(self):
7979
% (nc, elapsed_time, nc / elapsed_time), file=sys.stderr)
8080

8181
def test_commit_serialization(self):
82-
assert_commit_serialization(self.gitrwrepo, '58c78e6', True)
82+
self.assert_commit_serialization(self.gitrwrepo, '58c78e6', True)
8383

8484
rwrepo = self.gitrwrepo
8585
make_object = rwrepo.odb.store

git/test/test_actor.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.test.lib import assert_equal
7+
from git.test.lib import TestBase
88
from git import Actor
99

1010

11-
class TestActor(object):
11+
class TestActor(TestBase):
1212

1313
def test_from_string_should_separate_name_and_email(self):
1414
a = Actor._from_string("Michael Trier <[email protected]>")
15-
assert_equal("Michael Trier", a.name)
16-
assert_equal("[email protected]", a.email)
15+
self.assertEqual("Michael Trier", a.name)
16+
self.assertEqual("[email protected]", a.email)
1717

1818
# base type capabilities
1919
assert a == a
@@ -25,13 +25,13 @@ def test_from_string_should_separate_name_and_email(self):
2525

2626
def test_from_string_should_handle_just_name(self):
2727
a = Actor._from_string("Michael Trier")
28-
assert_equal("Michael Trier", a.name)
29-
assert_equal(None, a.email)
28+
self.assertEqual("Michael Trier", a.name)
29+
self.assertEqual(None, a.email)
3030

3131
def test_should_display_representation(self):
3232
a = Actor._from_string("Michael Trier <[email protected]>")
33-
assert_equal('<git.Actor "Michael Trier <[email protected]>">', repr(a))
33+
self.assertEqual('<git.Actor "Michael Trier <[email protected]>">', repr(a))
3434

3535
def test_str_should_alias_name(self):
3636
a = Actor._from_string("Michael Trier <[email protected]>")
37-
assert_equal(a.name, str(a))
37+
self.assertEqual(a.name, str(a))

git/test/test_blob.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.test.lib import (
8-
TestBase,
9-
assert_equal
10-
)
7+
from git.test.lib import TestBase
118
from git import Blob
129

1310

1411
class TestBlob(TestBase):
1512

1613
def test_mime_type_should_return_mime_type_for_known_types(self):
1714
blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA, 'path': 'foo.png'})
18-
assert_equal("image/png", blob.mime_type)
15+
self.assertEqual("image/png", blob.mime_type)
1916

2017
def test_mime_type_should_return_text_plain_for_unknown_types(self):
2118
blob = Blob(self.rorepo, **{'binsha': Blob.NULL_BIN_SHA, 'path': 'something'})
22-
assert_equal("text/plain", blob.mime_type)
19+
self.assertEqual("text/plain", blob.mime_type)
2320

2421
def test_nodict(self):
2522
self.assertRaises(AttributeError, setattr, self.rorepo.tree()['AUTHORS'], 'someattr', 2)

git/test/test_commit.py

+51-50
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from git.repo.fun import touch
2323
from git.test.lib import (
2424
TestBase,
25-
assert_equal,
2625
assert_not_equal,
2726
with_rw_repo,
2827
fixture_path,
@@ -34,58 +33,60 @@
3433
import 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("[email protected]", commit.author.email)
98+
self.assertEqual("Sebastian Thiel", commit.author.name)
99+
self.assertEqual("[email protected]", 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')

git/test/test_diff.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
TestBase,
2121
StringProcessAdapter,
2222
fixture,
23-
assert_equal,
2423
assert_true,
2524
)
2625
from git.test.lib import with_rw_directory
@@ -95,23 +94,23 @@ def test_list_from_string_new_mode(self):
9594
diffs = Diff._index_from_patch_format(self.rorepo, output)
9695
self._assert_diff_format(diffs)
9796

98-
assert_equal(1, len(diffs))
99-
assert_equal(8, len(diffs[0].diff.splitlines()))
97+
self.assertEqual(1, len(diffs))
98+
self.assertEqual(8, len(diffs[0].diff.splitlines()))
10099

101100
def test_diff_with_rename(self):
102101
output = StringProcessAdapter(fixture('diff_rename'))
103102
diffs = Diff._index_from_patch_format(self.rorepo, output)
104103
self._assert_diff_format(diffs)
105104

106-
assert_equal(1, len(diffs))
105+
self.assertEqual(1, len(diffs))
107106

108107
diff = diffs[0]
109108
assert_true(diff.renamed_file)
110109
assert_true(diff.renamed)
111-
assert_equal(diff.rename_from, u'Jérôme')
112-
assert_equal(diff.rename_to, u'müller')
113-
assert_equal(diff.raw_rename_from, b'J\xc3\xa9r\xc3\xb4me')
114-
assert_equal(diff.raw_rename_to, b'm\xc3\xbcller')
110+
self.assertEqual(diff.rename_from, u'Jérôme')
111+
self.assertEqual(diff.rename_to, u'müller')
112+
self.assertEqual(diff.raw_rename_from, b'J\xc3\xa9r\xc3\xb4me')
113+
self.assertEqual(diff.raw_rename_to, b'm\xc3\xbcller')
115114
assert isinstance(str(diff), str)
116115

117116
output = StringProcessAdapter(fixture('diff_rename_raw'))
@@ -131,7 +130,7 @@ def test_diff_with_copied_file(self):
131130
diffs = Diff._index_from_patch_format(self.rorepo, output)
132131
self._assert_diff_format(diffs)
133132

134-
assert_equal(1, len(diffs))
133+
self.assertEqual(1, len(diffs))
135134

136135
diff = diffs[0]
137136
assert_true(diff.copied_file)
@@ -153,17 +152,17 @@ def test_diff_with_change_in_type(self):
153152
output = StringProcessAdapter(fixture('diff_change_in_type'))
154153
diffs = Diff._index_from_patch_format(self.rorepo, output)
155154
self._assert_diff_format(diffs)
156-
assert_equal(2, len(diffs))
155+
self.assertEqual(2, len(diffs))
157156

158157
diff = diffs[0]
159158
self.assertIsNotNone(diff.deleted_file)
160-
assert_equal(diff.a_path, 'this')
161-
assert_equal(diff.b_path, 'this')
159+
self.assertEqual(diff.a_path, 'this')
160+
self.assertEqual(diff.b_path, 'this')
162161
assert isinstance(str(diff), str)
163162

164163
diff = diffs[1]
165-
assert_equal(diff.a_path, None)
166-
assert_equal(diff.b_path, 'this')
164+
self.assertEqual(diff.a_path, None)
165+
self.assertEqual(diff.b_path, 'this')
167166
self.assertIsNotNone(diff.new_file)
168167
assert isinstance(str(diff), str)
169168

0 commit comments

Comments
 (0)