Skip to content

Commit 7cf0ca8

Browse files
committed
Replace deprecated failUnlessRaises alias with assertRaises in tests
1 parent 2c429fc commit 7cf0ca8

15 files changed

+123
-123
lines changed

git/test/lib/helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class TestBase(TestCase):
331331
332332
- Utility functions provided by the TestCase base of the unittest method such as::
333333
self.fail("todo")
334-
self.failUnlessRaises(...)
334+
self.assertRaises(...)
335335
336336
- Class level repository which is considered read-only as it is shared among
337337
all test cases in your type.

git/test/test_blob.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def test_mime_type_should_return_text_plain_for_unknown_types(self):
2222
assert_equal("text/plain", blob.mime_type)
2323

2424
def test_nodict(self):
25-
self.failUnlessRaises(AttributeError, setattr, self.rorepo.tree()['AUTHORS'], 'someattr', 2)
25+
self.assertRaises(AttributeError, setattr, self.rorepo.tree()['AUTHORS'], 'someattr', 2)

git/test/test_commit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_bake(self):
9696

9797
commit = self.rorepo.commit('2454ae89983a4496a445ce347d7a41c0bb0ea7ae')
9898
# commits have no dict
99-
self.failUnlessRaises(AttributeError, setattr, commit, 'someattr', 1)
99+
self.assertRaises(AttributeError, setattr, commit, 'someattr', 1)
100100
commit.author # bake
101101

102102
assert_equal("Sebastian Thiel", commit.author.name)
@@ -180,7 +180,7 @@ def test_traversal(self):
180180
self.assertEqual(next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)), p1)
181181

182182
# traversal should stop when the beginning is reached
183-
self.failUnlessRaises(StopIteration, next, first.traverse())
183+
self.assertRaises(StopIteration, next, first.traverse())
184184

185185
# parents of the first commit should be empty ( as the only parent has a null
186186
# sha )
@@ -206,7 +206,7 @@ def test_iteration(self):
206206

207207
def test_iter_items(self):
208208
# pretty not allowed
209-
self.failUnlessRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw")
209+
self.assertRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw")
210210

211211
def test_rev_list_bisect_all(self):
212212
"""

git/test/test_db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def test_base(self):
2424

2525
# fails with BadObject
2626
for invalid_rev in ("0000", "bad/ref", "super bad"):
27-
self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev)
27+
self.assertRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev)

git/test/test_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_references_and_objects(self, rw_dir):
232232
# [6-test_references_and_objects]
233233
new_tag = repo.create_tag('my_new_tag', message='my message')
234234
# You cannot change the commit a tag points to. Tags need to be re-created
235-
self.failUnlessRaises(AttributeError, setattr, new_tag, 'commit', repo.commit('HEAD~1'))
235+
self.assertRaises(AttributeError, setattr, new_tag, 'commit', repo.commit('HEAD~1'))
236236
repo.delete_tag(new_tag)
237237
# ![6-test_references_and_objects]
238238

@@ -441,7 +441,7 @@ def test_references_and_objects(self, rw_dir):
441441

442442
# [30-test_references_and_objects]
443443
# checkout the branch using git-checkout. It will fail as the working tree appears dirty
444-
self.failUnlessRaises(git.GitCommandError, repo.heads.master.checkout)
444+
self.assertRaises(git.GitCommandError, repo.heads.master.checkout)
445445
repo.heads.past_branch.checkout()
446446
# ![30-test_references_and_objects]
447447

git/test/test_fun.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_aggressive_tree_merge(self):
7070
self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
7171

7272
# too many trees
73-
self.failUnlessRaises(ValueError, aggressive_tree_merge, odb, trees * 2)
73+
self.assertRaises(ValueError, aggressive_tree_merge, odb, trees * 2)
7474

7575
def mktree(self, odb, entries):
7676
"""create a tree from the given tree entries and safe it to the database"""

git/test/test_git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_cmd_override(self):
175175
# set it to something that doens't exist, assure it raises
176176
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = osp.join(
177177
"some", "path", "which", "doesn't", "exist", "gitbinary")
178-
self.failUnlessRaises(exc, self.git.version)
178+
self.assertRaises(exc, self.git.version)
179179
finally:
180180
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
181181
# END undo adjustment
@@ -219,7 +219,7 @@ def test_change_to_transform_kwargs_does_not_break_command_options(self):
219219

220220
def test_insert_after_kwarg_raises(self):
221221
# This isn't a complete add command, which doesn't matter here
222-
self.failUnlessRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo')
222+
self.assertRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo')
223223

224224
def test_env_vars_passed_to_git(self):
225225
editor = 'non_existent_editor'

git/test/test_index.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_index_file_from_tree(self, rw_repo):
205205
assert blob.path.startswith(prefix)
206206

207207
# writing a tree should fail with an unmerged index
208-
self.failUnlessRaises(UnmergedEntriesError, three_way_index.write_tree)
208+
self.assertRaises(UnmergedEntriesError, three_way_index.write_tree)
209209

210210
# removed unmerged entries
211211
unmerged_blob_map = three_way_index.unmerged_blobs()
@@ -265,13 +265,13 @@ def test_index_merge_tree(self, rw_repo):
265265
# a three way merge would result in a conflict and fails as the command will
266266
# not overwrite any entries in our index and hence leave them unmerged. This is
267267
# mainly a protection feature as the current index is not yet in a tree
268-
self.failUnlessRaises(GitCommandError, index.merge_tree, next_commit, base=parent_commit)
268+
self.assertRaises(GitCommandError, index.merge_tree, next_commit, base=parent_commit)
269269

270270
# the only way to get the merged entries is to safe the current index away into a tree,
271271
# which is like a temporary commit for us. This fails as well as the NULL sha deos not
272272
# have a corresponding object
273273
# NOTE: missing_ok is not a kwarg anymore, missing_ok is always true
274-
# self.failUnlessRaises(GitCommandError, index.write_tree)
274+
# self.assertRaises(GitCommandError, index.write_tree)
275275

276276
# if missing objects are okay, this would work though ( they are always okay now )
277277
# As we can't read back the tree with NULL_SHA, we rather set it to something else
@@ -326,7 +326,7 @@ def test_index_file_diffing(self, rw_repo):
326326
assert wdiff != odiff
327327

328328
# against something unusual
329-
self.failUnlessRaises(ValueError, index.diff, int)
329+
self.assertRaises(ValueError, index.diff, int)
330330

331331
# adjust the index to match an old revision
332332
cur_branch = rw_repo.active_branch
@@ -375,8 +375,8 @@ def test_index_file_diffing(self, rw_repo):
375375
assert osp.exists(test_file)
376376

377377
# checking out non-existing file throws
378-
self.failUnlessRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that")
379-
self.failUnlessRaises(CheckoutError, index.checkout, paths=["doesnt/exist"])
378+
self.assertRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that")
379+
self.assertRaises(CheckoutError, index.checkout, paths=["doesnt/exist"])
380380

381381
# checkout file with modifications
382382
append_data = b"hello"
@@ -474,12 +474,12 @@ def mixed_iterator():
474474
self.assertEqual(self._count_existing(rw_repo, deleted_files), len(deleted_files))
475475

476476
# invalid type
477-
self.failUnlessRaises(TypeError, index.remove, [1])
477+
self.assertRaises(TypeError, index.remove, [1])
478478

479479
# absolute path
480480
deleted_files = index.remove([osp.join(rw_repo.working_tree_dir, "lib")], r=True)
481481
assert len(deleted_files) > 1
482-
self.failUnlessRaises(ValueError, index.remove, ["/doesnt/exists"])
482+
self.assertRaises(ValueError, index.remove, ["/doesnt/exists"])
483483

484484
# TEST COMMITTING
485485
# commit changed index
@@ -571,7 +571,7 @@ def mixed_iterator():
571571
self.assertEqual(len(entries), 2)
572572

573573
# missing path
574-
self.failUnlessRaises(OSError, index.reset(new_commit).add, ['doesnt/exist/must/raise'])
574+
self.assertRaises(OSError, index.reset(new_commit).add, ['doesnt/exist/must/raise'])
575575

576576
# blob from older revision overrides current index revision
577577
old_blob = new_commit.parents[0].tree.blobs[0]
@@ -584,7 +584,7 @@ def mixed_iterator():
584584
# mode 0 not allowed
585585
null_hex_sha = Diff.NULL_HEX_SHA
586586
null_bin_sha = b"\0" * 20
587-
self.failUnlessRaises(ValueError, index.reset(
587+
self.assertRaises(ValueError, index.reset(
588588
new_commit).add, [BaseIndexEntry((0, null_bin_sha, 0, "doesntmatter"))])
589589

590590
# add new file
@@ -668,10 +668,10 @@ def assert_mv_rval(rval):
668668
# END for each renamed item
669669
# END move assertion utility
670670

671-
self.failUnlessRaises(ValueError, index.move, ['just_one_path'])
671+
self.assertRaises(ValueError, index.move, ['just_one_path'])
672672
# file onto existing file
673673
files = ['AUTHORS', 'LICENSE']
674-
self.failUnlessRaises(GitCommandError, index.move, files)
674+
self.assertRaises(GitCommandError, index.move, files)
675675

676676
# again, with force
677677
assert_mv_rval(index.move(files, f=True))

git/test/test_reflog.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_reflogentry(self):
2323
actor = Actor('name', 'email')
2424
msg = "message"
2525

26-
self.failUnlessRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, 'noactor', 0, 0, "")
26+
self.assertRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, 'noactor', 0, 0, "")
2727
e = RefLogEntry.new(nullhexsha, hexsha, actor, 0, 1, msg)
2828

2929
assert e.oldhexsha == nullhexsha
@@ -59,11 +59,11 @@ def test_base(self):
5959
# TODO: Try multiple corrupted ones !
6060
pp = 'reflog_invalid_'
6161
for suffix in ('oldsha', 'newsha', 'email', 'date', 'sep'):
62-
self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp + suffix))
62+
self.assertRaises(ValueError, RefLog.from_file, fixture_path(pp + suffix))
6363
# END for each invalid file
6464

6565
# cannot write an uninitialized reflog
66-
self.failUnlessRaises(ValueError, RefLog().write)
66+
self.assertRaises(ValueError, RefLog().write)
6767

6868
# test serialize and deserialize - results must match exactly
6969
binsha = hex_to_bin(('f' * 40).encode('ascii'))
@@ -91,7 +91,7 @@ def test_base(self):
9191

9292
# index entry
9393
# raises on invalid index
94-
self.failUnlessRaises(IndexError, RefLog.entry_at, rlp, 10000)
94+
self.assertRaises(IndexError, RefLog.entry_at, rlp, 10000)
9595

9696
# indices can be positive ...
9797
assert isinstance(RefLog.entry_at(rlp, 0), RefLogEntry)

git/test/test_refs.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_from_path(self):
4040
# END for each type
4141

4242
# invalid path
43-
self.failUnlessRaises(ValueError, TagReference, self.rorepo, "refs/invalid/tag")
43+
self.assertRaises(ValueError, TagReference, self.rorepo, "refs/invalid/tag")
4444
# works without path check
4545
TagReference(self.rorepo, "refs/invalid/tag", check_path=False)
4646

@@ -54,7 +54,7 @@ def test_tag_base(self):
5454
tag_object_refs.append(tag)
5555
tagobj = tag.tag
5656
# have no dict
57-
self.failUnlessRaises(AttributeError, setattr, tagobj, 'someattr', 1)
57+
self.assertRaises(AttributeError, setattr, tagobj, 'someattr', 1)
5858
assert isinstance(tagobj, TagObject)
5959
assert tagobj.tag == tag.name
6060
assert isinstance(tagobj.tagger, Actor)
@@ -63,7 +63,7 @@ def test_tag_base(self):
6363
assert tagobj.message
6464
assert tag.object == tagobj
6565
# can't assign the object
66-
self.failUnlessRaises(AttributeError, setattr, tag, 'object', tagobj)
66+
self.assertRaises(AttributeError, setattr, tag, 'object', tagobj)
6767
# END if we have a tag object
6868
# END for tag in repo-tags
6969
assert tag_object_refs
@@ -201,7 +201,7 @@ def test_head_reset(self, rw_repo):
201201
cur_head.reset(new_head_commit, index=True) # index only
202202
assert cur_head.reference.commit == new_head_commit
203203

204-
self.failUnlessRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True)
204+
self.assertRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True)
205205
new_head_commit = new_head_commit.parents[0]
206206
cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt
207207
assert cur_head.reference.commit == new_head_commit
@@ -211,7 +211,7 @@ def test_head_reset(self, rw_repo):
211211
cur_head.reset(cur_head, paths="test")
212212
cur_head.reset(new_head_commit, paths="lib")
213213
# hard resets with paths don't work, its all or nothing
214-
self.failUnlessRaises(GitCommandError, cur_head.reset, new_head_commit, working_tree=True, paths="lib")
214+
self.assertRaises(GitCommandError, cur_head.reset, new_head_commit, working_tree=True, paths="lib")
215215

216216
# we can do a mixed reset, and then checkout from the index though
217217
cur_head.reset(new_head_commit)
@@ -235,7 +235,7 @@ def test_head_reset(self, rw_repo):
235235
cur_head.reference = curhead_commit
236236
assert cur_head.commit == curhead_commit
237237
assert cur_head.is_detached
238-
self.failUnlessRaises(TypeError, getattr, cur_head, "reference")
238+
self.assertRaises(TypeError, getattr, cur_head, "reference")
239239

240240
# tags are references, hence we can point to them
241241
some_tag = rw_repo.tags[0]
@@ -248,7 +248,7 @@ def test_head_reset(self, rw_repo):
248248
cur_head.reference = active_head
249249

250250
# type check
251-
self.failUnlessRaises(ValueError, setattr, cur_head, "reference", "that")
251+
self.assertRaises(ValueError, setattr, cur_head, "reference", "that")
252252

253253
# head handling
254254
commit = 'HEAD'
@@ -263,7 +263,7 @@ def test_head_reset(self, rw_repo):
263263
Head.create(rw_repo, new_name, new_head.commit)
264264

265265
# its not fine with a different value
266-
self.failUnlessRaises(OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0])
266+
self.assertRaises(OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0])
267267

268268
# force it
269269
new_head = Head.create(rw_repo, new_name, actual_commit, force=True)
@@ -276,7 +276,7 @@ def test_head_reset(self, rw_repo):
276276

277277
# rename with force
278278
tmp_head = Head.create(rw_repo, "tmphead")
279-
self.failUnlessRaises(GitCommandError, tmp_head.rename, new_head)
279+
self.assertRaises(GitCommandError, tmp_head.rename, new_head)
280280
tmp_head.rename(new_head, force=True)
281281
assert tmp_head == new_head and tmp_head.object == new_head.object
282282

@@ -289,12 +289,12 @@ def test_head_reset(self, rw_repo):
289289
assert tmp_head not in heads and new_head not in heads
290290
# force on deletion testing would be missing here, code looks okay though ;)
291291
# END for each new head name
292-
self.failUnlessRaises(TypeError, RemoteReference.create, rw_repo, "some_name")
292+
self.assertRaises(TypeError, RemoteReference.create, rw_repo, "some_name")
293293

294294
# tag ref
295295
tag_name = "5.0.2"
296296
TagReference.create(rw_repo, tag_name)
297-
self.failUnlessRaises(GitCommandError, TagReference.create, rw_repo, tag_name)
297+
self.assertRaises(GitCommandError, TagReference.create, rw_repo, tag_name)
298298
light_tag = TagReference.create(rw_repo, tag_name, "HEAD~1", force=True)
299299
assert isinstance(light_tag, TagReference)
300300
assert light_tag.name == tag_name
@@ -354,13 +354,13 @@ def test_head_reset(self, rw_repo):
354354

355355
# setting a non-commit as commit fails, but succeeds as object
356356
head_tree = head.commit.tree
357-
self.failUnlessRaises(ValueError, setattr, head, 'commit', head_tree)
357+
self.assertRaises(ValueError, setattr, head, 'commit', head_tree)
358358
assert head.commit == old_commit # and the ref did not change
359359
# we allow heds to point to any object
360360
head.object = head_tree
361361
assert head.object == head_tree
362362
# cannot query tree as commit
363-
self.failUnlessRaises(TypeError, getattr, head, 'commit')
363+
self.assertRaises(TypeError, getattr, head, 'commit')
364364

365365
# set the commit directly using the head. This would never detach the head
366366
assert not cur_head.is_detached
@@ -397,7 +397,7 @@ def test_head_reset(self, rw_repo):
397397

398398
# create a new branch that is likely to touch the file we changed
399399
far_away_head = rw_repo.create_head("far_head", 'HEAD~100')
400-
self.failUnlessRaises(GitCommandError, far_away_head.checkout)
400+
self.assertRaises(GitCommandError, far_away_head.checkout)
401401
assert active_branch == active_branch.checkout(force=True)
402402
assert rw_repo.head.reference != far_away_head
403403

@@ -408,7 +408,7 @@ def test_head_reset(self, rw_repo):
408408
assert ref.path == full_ref
409409
assert ref.object == rw_repo.head.commit
410410

411-
self.failUnlessRaises(OSError, Reference.create, rw_repo, full_ref, 'HEAD~20')
411+
self.assertRaises(OSError, Reference.create, rw_repo, full_ref, 'HEAD~20')
412412
# it works if it is at the same spot though and points to the same reference
413413
assert Reference.create(rw_repo, full_ref, 'HEAD').path == full_ref
414414
Reference.delete(rw_repo, full_ref)
@@ -434,11 +434,11 @@ def test_head_reset(self, rw_repo):
434434
# END for each name type
435435

436436
# References that don't exist trigger an error if we want to access them
437-
self.failUnlessRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), 'commit')
437+
self.assertRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), 'commit')
438438

439439
# exists, fail unless we force
440440
ex_ref_path = far_away_head.path
441-
self.failUnlessRaises(OSError, ref.rename, ex_ref_path)
441+
self.assertRaises(OSError, ref.rename, ex_ref_path)
442442
# if it points to the same commit it works
443443
far_away_head.commit = ref.commit
444444
ref.rename(ex_ref_path)
@@ -451,7 +451,7 @@ def test_head_reset(self, rw_repo):
451451
assert symref.path == symref_path
452452
assert symref.reference == cur_head.reference
453453

454-
self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit)
454+
self.assertRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit)
455455
# it works if the new ref points to the same reference
456456
SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path # @NoEffect
457457
SymbolicReference.delete(rw_repo, symref)
@@ -541,7 +541,7 @@ def test_head_reset(self, rw_repo):
541541
# if the assignment raises, the ref doesn't exist
542542
Reference.delete(ref.repo, ref.path)
543543
assert not ref.is_valid()
544-
self.failUnlessRaises(ValueError, setattr, ref, 'commit', "nonsense")
544+
self.assertRaises(ValueError, setattr, ref, 'commit', "nonsense")
545545
assert not ref.is_valid()
546546

547547
# I am sure I had my reason to make it a class method at first, but
@@ -555,7 +555,7 @@ def test_head_reset(self, rw_repo):
555555

556556
Reference.delete(ref.repo, ref.path)
557557
assert not ref.is_valid()
558-
self.failUnlessRaises(ValueError, setattr, ref, 'object', "nonsense")
558+
self.assertRaises(ValueError, setattr, ref, 'object', "nonsense")
559559
assert not ref.is_valid()
560560

561561
# END for each path

0 commit comments

Comments
 (0)