diff options
author | Harmon <Harmon758@gmail.com> | 2020-02-16 13:46:25 -0600 |
---|---|---|
committer | Harmon <Harmon758@gmail.com> | 2020-02-16 13:52:26 -0600 |
commit | 7cf0ca8b94dc815598e354d17d87ca77f499cae6 (patch) | |
tree | 4f6804ce8fdd8a9f13a83d3516037be0fe8cda7a | |
parent | 2c429fc0382868c22b56e70047b01c0567c0ba31 (diff) | |
download | gitpython-7cf0ca8b94dc815598e354d17d87ca77f499cae6.tar.gz |
Replace deprecated failUnlessRaises alias with assertRaises in tests
-rw-r--r-- | git/test/lib/helper.py | 2 | ||||
-rw-r--r-- | git/test/test_blob.py | 2 | ||||
-rw-r--r-- | git/test/test_commit.py | 6 | ||||
-rw-r--r-- | git/test/test_db.py | 2 | ||||
-rw-r--r-- | git/test/test_docs.py | 4 | ||||
-rw-r--r-- | git/test/test_fun.py | 2 | ||||
-rw-r--r-- | git/test/test_git.py | 4 | ||||
-rw-r--r-- | git/test/test_index.py | 24 | ||||
-rw-r--r-- | git/test/test_reflog.py | 8 | ||||
-rw-r--r-- | git/test/test_refs.py | 40 | ||||
-rw-r--r-- | git/test/test_remote.py | 22 | ||||
-rw-r--r-- | git/test/test_repo.py | 36 | ||||
-rw-r--r-- | git/test/test_submodule.py | 70 | ||||
-rw-r--r-- | git/test/test_tree.py | 2 | ||||
-rw-r--r-- | git/test/test_util.py | 22 |
15 files changed, 123 insertions, 123 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 9418a9f8..8de66e8a 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -331,7 +331,7 @@ class TestBase(TestCase): - Utility functions provided by the TestCase base of the unittest method such as:: self.fail("todo") - self.failUnlessRaises(...) + self.assertRaises(...) - Class level repository which is considered read-only as it is shared among all test cases in your type. diff --git a/git/test/test_blob.py b/git/test/test_blob.py index b529e80f..4c7f0055 100644 --- a/git/test/test_blob.py +++ b/git/test/test_blob.py @@ -22,4 +22,4 @@ class TestBlob(TestBase): assert_equal("text/plain", blob.mime_type) def test_nodict(self): - self.failUnlessRaises(AttributeError, setattr, self.rorepo.tree()['AUTHORS'], 'someattr', 2) + self.assertRaises(AttributeError, setattr, self.rorepo.tree()['AUTHORS'], 'someattr', 2) diff --git a/git/test/test_commit.py b/git/test/test_commit.py index e41e80bb..28f03c1c 100644 --- a/git/test/test_commit.py +++ b/git/test/test_commit.py @@ -96,7 +96,7 @@ class TestCommit(TestBase): commit = self.rorepo.commit('2454ae89983a4496a445ce347d7a41c0bb0ea7ae') # commits have no dict - self.failUnlessRaises(AttributeError, setattr, commit, 'someattr', 1) + self.assertRaises(AttributeError, setattr, commit, 'someattr', 1) commit.author # bake assert_equal("Sebastian Thiel", commit.author.name) @@ -180,7 +180,7 @@ class TestCommit(TestBase): self.assertEqual(next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)), p1) # traversal should stop when the beginning is reached - self.failUnlessRaises(StopIteration, next, first.traverse()) + self.assertRaises(StopIteration, next, first.traverse()) # parents of the first commit should be empty ( as the only parent has a null # sha ) @@ -206,7 +206,7 @@ class TestCommit(TestBase): def test_iter_items(self): # pretty not allowed - self.failUnlessRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw") + self.assertRaises(ValueError, Commit.iter_items, self.rorepo, 'master', pretty="raw") def test_rev_list_bisect_all(self): """ diff --git a/git/test/test_db.py b/git/test/test_db.py index 8f67dd48..bd16452d 100644 --- a/git/test/test_db.py +++ b/git/test/test_db.py @@ -24,4 +24,4 @@ class TestDB(TestBase): # fails with BadObject for invalid_rev in ("0000", "bad/ref", "super bad"): - self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev) + self.assertRaises(BadObject, gdb.partial_to_complete_sha_hex, invalid_rev) diff --git a/git/test/test_docs.py b/git/test/test_docs.py index a393ded8..57921613 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -232,7 +232,7 @@ class Tutorials(TestBase): # [6-test_references_and_objects] new_tag = repo.create_tag('my_new_tag', message='my message') # You cannot change the commit a tag points to. Tags need to be re-created - self.failUnlessRaises(AttributeError, setattr, new_tag, 'commit', repo.commit('HEAD~1')) + self.assertRaises(AttributeError, setattr, new_tag, 'commit', repo.commit('HEAD~1')) repo.delete_tag(new_tag) # ![6-test_references_and_objects] @@ -441,7 +441,7 @@ class Tutorials(TestBase): # [30-test_references_and_objects] # checkout the branch using git-checkout. It will fail as the working tree appears dirty - self.failUnlessRaises(git.GitCommandError, repo.heads.master.checkout) + self.assertRaises(git.GitCommandError, repo.heads.master.checkout) repo.heads.past_branch.checkout() # ![30-test_references_and_objects] diff --git a/git/test/test_fun.py b/git/test/test_fun.py index 612c4c5d..594e8fab 100644 --- a/git/test/test_fun.py +++ b/git/test/test_fun.py @@ -70,7 +70,7 @@ class TestFun(TestBase): self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) # too many trees - self.failUnlessRaises(ValueError, aggressive_tree_merge, odb, trees * 2) + self.assertRaises(ValueError, aggressive_tree_merge, odb, trees * 2) def mktree(self, odb, entries): """create a tree from the given tree entries and safe it to the database""" diff --git a/git/test/test_git.py b/git/test/test_git.py index e6bc19d1..54057f49 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -175,7 +175,7 @@ class TestGit(TestBase): # set it to something that doens't exist, assure it raises type(self.git).GIT_PYTHON_GIT_EXECUTABLE = osp.join( "some", "path", "which", "doesn't", "exist", "gitbinary") - self.failUnlessRaises(exc, self.git.version) + self.assertRaises(exc, self.git.version) finally: type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd # END undo adjustment @@ -219,7 +219,7 @@ class TestGit(TestBase): def test_insert_after_kwarg_raises(self): # This isn't a complete add command, which doesn't matter here - self.failUnlessRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo') + self.assertRaises(ValueError, self.git.remote, 'add', insert_kwargs_after='foo') def test_env_vars_passed_to_git(self): editor = 'non_existent_editor' diff --git a/git/test/test_index.py b/git/test/test_index.py index 0a2309f9..0b830281 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -205,7 +205,7 @@ class TestIndex(TestBase): assert blob.path.startswith(prefix) # writing a tree should fail with an unmerged index - self.failUnlessRaises(UnmergedEntriesError, three_way_index.write_tree) + self.assertRaises(UnmergedEntriesError, three_way_index.write_tree) # removed unmerged entries unmerged_blob_map = three_way_index.unmerged_blobs() @@ -265,13 +265,13 @@ class TestIndex(TestBase): # a three way merge would result in a conflict and fails as the command will # not overwrite any entries in our index and hence leave them unmerged. This is # mainly a protection feature as the current index is not yet in a tree - self.failUnlessRaises(GitCommandError, index.merge_tree, next_commit, base=parent_commit) + self.assertRaises(GitCommandError, index.merge_tree, next_commit, base=parent_commit) # the only way to get the merged entries is to safe the current index away into a tree, # which is like a temporary commit for us. This fails as well as the NULL sha deos not # have a corresponding object # NOTE: missing_ok is not a kwarg anymore, missing_ok is always true - # self.failUnlessRaises(GitCommandError, index.write_tree) + # self.assertRaises(GitCommandError, index.write_tree) # if missing objects are okay, this would work though ( they are always okay now ) # As we can't read back the tree with NULL_SHA, we rather set it to something else @@ -326,7 +326,7 @@ class TestIndex(TestBase): assert wdiff != odiff # against something unusual - self.failUnlessRaises(ValueError, index.diff, int) + self.assertRaises(ValueError, index.diff, int) # adjust the index to match an old revision cur_branch = rw_repo.active_branch @@ -375,8 +375,8 @@ class TestIndex(TestBase): assert osp.exists(test_file) # checking out non-existing file throws - self.failUnlessRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that") - self.failUnlessRaises(CheckoutError, index.checkout, paths=["doesnt/exist"]) + self.assertRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that") + self.assertRaises(CheckoutError, index.checkout, paths=["doesnt/exist"]) # checkout file with modifications append_data = b"hello" @@ -474,12 +474,12 @@ class TestIndex(TestBase): self.assertEqual(self._count_existing(rw_repo, deleted_files), len(deleted_files)) # invalid type - self.failUnlessRaises(TypeError, index.remove, [1]) + self.assertRaises(TypeError, index.remove, [1]) # absolute path deleted_files = index.remove([osp.join(rw_repo.working_tree_dir, "lib")], r=True) assert len(deleted_files) > 1 - self.failUnlessRaises(ValueError, index.remove, ["/doesnt/exists"]) + self.assertRaises(ValueError, index.remove, ["/doesnt/exists"]) # TEST COMMITTING # commit changed index @@ -571,7 +571,7 @@ class TestIndex(TestBase): self.assertEqual(len(entries), 2) # missing path - self.failUnlessRaises(OSError, index.reset(new_commit).add, ['doesnt/exist/must/raise']) + self.assertRaises(OSError, index.reset(new_commit).add, ['doesnt/exist/must/raise']) # blob from older revision overrides current index revision old_blob = new_commit.parents[0].tree.blobs[0] @@ -584,7 +584,7 @@ class TestIndex(TestBase): # mode 0 not allowed null_hex_sha = Diff.NULL_HEX_SHA null_bin_sha = b"\0" * 20 - self.failUnlessRaises(ValueError, index.reset( + self.assertRaises(ValueError, index.reset( new_commit).add, [BaseIndexEntry((0, null_bin_sha, 0, "doesntmatter"))]) # add new file @@ -668,10 +668,10 @@ class TestIndex(TestBase): # END for each renamed item # END move assertion utility - self.failUnlessRaises(ValueError, index.move, ['just_one_path']) + self.assertRaises(ValueError, index.move, ['just_one_path']) # file onto existing file files = ['AUTHORS', 'LICENSE'] - self.failUnlessRaises(GitCommandError, index.move, files) + self.assertRaises(GitCommandError, index.move, files) # again, with force assert_mv_rval(index.move(files, f=True)) diff --git a/git/test/test_reflog.py b/git/test/test_reflog.py index 20495be1..db5f2783 100644 --- a/git/test/test_reflog.py +++ b/git/test/test_reflog.py @@ -23,7 +23,7 @@ class TestRefLog(TestBase): actor = Actor('name', 'email') msg = "message" - self.failUnlessRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, 'noactor', 0, 0, "") + self.assertRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, 'noactor', 0, 0, "") e = RefLogEntry.new(nullhexsha, hexsha, actor, 0, 1, msg) assert e.oldhexsha == nullhexsha @@ -59,11 +59,11 @@ class TestRefLog(TestBase): # TODO: Try multiple corrupted ones ! pp = 'reflog_invalid_' for suffix in ('oldsha', 'newsha', 'email', 'date', 'sep'): - self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp + suffix)) + self.assertRaises(ValueError, RefLog.from_file, fixture_path(pp + suffix)) # END for each invalid file # cannot write an uninitialized reflog - self.failUnlessRaises(ValueError, RefLog().write) + self.assertRaises(ValueError, RefLog().write) # test serialize and deserialize - results must match exactly binsha = hex_to_bin(('f' * 40).encode('ascii')) @@ -91,7 +91,7 @@ class TestRefLog(TestBase): # index entry # raises on invalid index - self.failUnlessRaises(IndexError, RefLog.entry_at, rlp, 10000) + self.assertRaises(IndexError, RefLog.entry_at, rlp, 10000) # indices can be positive ... assert isinstance(RefLog.entry_at(rlp, 0), RefLogEntry) diff --git a/git/test/test_refs.py b/git/test/test_refs.py index 348c3d48..4a0ebfde 100644 --- a/git/test/test_refs.py +++ b/git/test/test_refs.py @@ -40,7 +40,7 @@ class TestRefs(TestBase): # END for each type # invalid path - self.failUnlessRaises(ValueError, TagReference, self.rorepo, "refs/invalid/tag") + self.assertRaises(ValueError, TagReference, self.rorepo, "refs/invalid/tag") # works without path check TagReference(self.rorepo, "refs/invalid/tag", check_path=False) @@ -54,7 +54,7 @@ class TestRefs(TestBase): tag_object_refs.append(tag) tagobj = tag.tag # have no dict - self.failUnlessRaises(AttributeError, setattr, tagobj, 'someattr', 1) + self.assertRaises(AttributeError, setattr, tagobj, 'someattr', 1) assert isinstance(tagobj, TagObject) assert tagobj.tag == tag.name assert isinstance(tagobj.tagger, Actor) @@ -63,7 +63,7 @@ class TestRefs(TestBase): assert tagobj.message assert tag.object == tagobj # can't assign the object - self.failUnlessRaises(AttributeError, setattr, tag, 'object', tagobj) + self.assertRaises(AttributeError, setattr, tag, 'object', tagobj) # END if we have a tag object # END for tag in repo-tags assert tag_object_refs @@ -201,7 +201,7 @@ class TestRefs(TestBase): cur_head.reset(new_head_commit, index=True) # index only assert cur_head.reference.commit == new_head_commit - self.failUnlessRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True) + self.assertRaises(ValueError, cur_head.reset, new_head_commit, index=False, working_tree=True) new_head_commit = new_head_commit.parents[0] cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt assert cur_head.reference.commit == new_head_commit @@ -211,7 +211,7 @@ class TestRefs(TestBase): cur_head.reset(cur_head, paths="test") cur_head.reset(new_head_commit, paths="lib") # hard resets with paths don't work, its all or nothing - self.failUnlessRaises(GitCommandError, cur_head.reset, new_head_commit, working_tree=True, paths="lib") + self.assertRaises(GitCommandError, cur_head.reset, new_head_commit, working_tree=True, paths="lib") # we can do a mixed reset, and then checkout from the index though cur_head.reset(new_head_commit) @@ -235,7 +235,7 @@ class TestRefs(TestBase): cur_head.reference = curhead_commit assert cur_head.commit == curhead_commit assert cur_head.is_detached - self.failUnlessRaises(TypeError, getattr, cur_head, "reference") + self.assertRaises(TypeError, getattr, cur_head, "reference") # tags are references, hence we can point to them some_tag = rw_repo.tags[0] @@ -248,7 +248,7 @@ class TestRefs(TestBase): cur_head.reference = active_head # type check - self.failUnlessRaises(ValueError, setattr, cur_head, "reference", "that") + self.assertRaises(ValueError, setattr, cur_head, "reference", "that") # head handling commit = 'HEAD' @@ -263,7 +263,7 @@ class TestRefs(TestBase): Head.create(rw_repo, new_name, new_head.commit) # its not fine with a different value - self.failUnlessRaises(OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0]) + self.assertRaises(OSError, Head.create, rw_repo, new_name, new_head.commit.parents[0]) # force it new_head = Head.create(rw_repo, new_name, actual_commit, force=True) @@ -276,7 +276,7 @@ class TestRefs(TestBase): # rename with force tmp_head = Head.create(rw_repo, "tmphead") - self.failUnlessRaises(GitCommandError, tmp_head.rename, new_head) + self.assertRaises(GitCommandError, tmp_head.rename, new_head) tmp_head.rename(new_head, force=True) assert tmp_head == new_head and tmp_head.object == new_head.object @@ -289,12 +289,12 @@ class TestRefs(TestBase): assert tmp_head not in heads and new_head not in heads # force on deletion testing would be missing here, code looks okay though ;) # END for each new head name - self.failUnlessRaises(TypeError, RemoteReference.create, rw_repo, "some_name") + self.assertRaises(TypeError, RemoteReference.create, rw_repo, "some_name") # tag ref tag_name = "5.0.2" TagReference.create(rw_repo, tag_name) - self.failUnlessRaises(GitCommandError, TagReference.create, rw_repo, tag_name) + self.assertRaises(GitCommandError, TagReference.create, rw_repo, tag_name) light_tag = TagReference.create(rw_repo, tag_name, "HEAD~1", force=True) assert isinstance(light_tag, TagReference) assert light_tag.name == tag_name @@ -354,13 +354,13 @@ class TestRefs(TestBase): # setting a non-commit as commit fails, but succeeds as object head_tree = head.commit.tree - self.failUnlessRaises(ValueError, setattr, head, 'commit', head_tree) + self.assertRaises(ValueError, setattr, head, 'commit', head_tree) assert head.commit == old_commit # and the ref did not change # we allow heds to point to any object head.object = head_tree assert head.object == head_tree # cannot query tree as commit - self.failUnlessRaises(TypeError, getattr, head, 'commit') + self.assertRaises(TypeError, getattr, head, 'commit') # set the commit directly using the head. This would never detach the head assert not cur_head.is_detached @@ -397,7 +397,7 @@ class TestRefs(TestBase): # create a new branch that is likely to touch the file we changed far_away_head = rw_repo.create_head("far_head", 'HEAD~100') - self.failUnlessRaises(GitCommandError, far_away_head.checkout) + self.assertRaises(GitCommandError, far_away_head.checkout) assert active_branch == active_branch.checkout(force=True) assert rw_repo.head.reference != far_away_head @@ -408,7 +408,7 @@ class TestRefs(TestBase): assert ref.path == full_ref assert ref.object == rw_repo.head.commit - self.failUnlessRaises(OSError, Reference.create, rw_repo, full_ref, 'HEAD~20') + self.assertRaises(OSError, Reference.create, rw_repo, full_ref, 'HEAD~20') # it works if it is at the same spot though and points to the same reference assert Reference.create(rw_repo, full_ref, 'HEAD').path == full_ref Reference.delete(rw_repo, full_ref) @@ -434,11 +434,11 @@ class TestRefs(TestBase): # END for each name type # References that don't exist trigger an error if we want to access them - self.failUnlessRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), 'commit') + self.assertRaises(ValueError, getattr, Reference(rw_repo, "refs/doesntexist"), 'commit') # exists, fail unless we force ex_ref_path = far_away_head.path - self.failUnlessRaises(OSError, ref.rename, ex_ref_path) + self.assertRaises(OSError, ref.rename, ex_ref_path) # if it points to the same commit it works far_away_head.commit = ref.commit ref.rename(ex_ref_path) @@ -451,7 +451,7 @@ class TestRefs(TestBase): assert symref.path == symref_path assert symref.reference == cur_head.reference - self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit) + self.assertRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit) # it works if the new ref points to the same reference SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path # @NoEffect SymbolicReference.delete(rw_repo, symref) @@ -541,7 +541,7 @@ class TestRefs(TestBase): # if the assignment raises, the ref doesn't exist Reference.delete(ref.repo, ref.path) assert not ref.is_valid() - self.failUnlessRaises(ValueError, setattr, ref, 'commit', "nonsense") + self.assertRaises(ValueError, setattr, ref, 'commit', "nonsense") assert not ref.is_valid() # I am sure I had my reason to make it a class method at first, but @@ -555,7 +555,7 @@ class TestRefs(TestBase): Reference.delete(ref.repo, ref.path) assert not ref.is_valid() - self.failUnlessRaises(ValueError, setattr, ref, 'object', "nonsense") + self.assertRaises(ValueError, setattr, ref, 'object', "nonsense") assert not ref.is_valid() # END for each path diff --git a/git/test/test_remote.py b/git/test/test_remote.py index 2194daec..13828489 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -152,8 +152,8 @@ class TestRemote(TestBase): # END for each info def _do_test_fetch_info(self, repo): - self.failUnlessRaises(ValueError, FetchInfo._from_line, repo, "nonsense", '') - self.failUnlessRaises( + self.assertRaises(ValueError, FetchInfo._from_line, repo, "nonsense", '') + self.assertRaises( ValueError, FetchInfo._from_line, repo, "? [up to date] 0.1.7RC -> origin/0.1.7RC", '') def _commit_random_file(self, repo): @@ -221,7 +221,7 @@ class TestRemote(TestBase): Head.delete(new_remote_branch.repo, new_remote_branch) res = fetch_and_test(remote) # deleted remote will not be fetched - self.failUnlessRaises(IndexError, get_info, res, remote, new_remote_branch) + self.assertRaises(IndexError, get_info, res, remote, new_remote_branch) # prune stale tracking branches stale_refs = remote.stale_refs @@ -267,7 +267,7 @@ class TestRemote(TestBase): # delete remote tag - local one will stay TagReference.delete(remote_repo, rtag) res = fetch_and_test(remote, tags=True) - self.failUnlessRaises(IndexError, get_info, res, remote, str(rtag)) + self.assertRaises(IndexError, get_info, res, remote, str(rtag)) # provoke to receive actual objects to see what kind of output we have to # expect. For that we need a remote transport protocol @@ -318,7 +318,7 @@ class TestRemote(TestBase): # push without spec should fail ( without further configuration ) # well, works nicely - # self.failUnlessRaises(GitCommandError, remote.push) + # self.assertRaises(GitCommandError, remote.push) # simple file push self._commit_random_file(rw_repo) @@ -342,7 +342,7 @@ class TestRemote(TestBase): self._do_test_push_result(res, remote) # invalid refspec - self.failUnlessRaises(GitCommandError, remote.push, "hellothere") + self.assertRaises(GitCommandError, remote.push, "hellothere") # push new tags progress = TestRemoteProgress() @@ -439,7 +439,7 @@ class TestRemote(TestBase): assert reader.get_value(opt, None) == val # unable to write with a reader - self.failUnlessRaises(IOError, reader.set, opt, "test") + self.assertRaises(IOError, reader.set, opt, "test") # change value with remote.config_writer as writer: @@ -510,7 +510,7 @@ class TestRemote(TestBase): self.assertTrue(remote.exists()) # create same one again - self.failUnlessRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list) + self.assertRaises(GitCommandError, Remote.create, bare_rw_repo, *arg_list) Remote.remove(bare_rw_repo, new_name) self.assertTrue(remote.exists()) # We still have a cache that doesn't know we were deleted by name @@ -532,9 +532,9 @@ class TestRemote(TestBase): fetch_info_line_fmt += "git://github.com/gitpython-developers/GitPython" remote_info_line_fmt = "* [new branch] nomatter -> %s" - self.failUnlessRaises(ValueError, FetchInfo._from_line, self.rorepo, - remote_info_line_fmt % "refs/something/branch", - "269c498e56feb93e408ed4558c8138d750de8893\t\t/Users/ben/test/foo\n") + self.assertRaises(ValueError, FetchInfo._from_line, self.rorepo, + remote_info_line_fmt % "refs/something/branch", + "269c498e56feb93e408ed4558c8138d750de8893\t\t/Users/ben/test/foo\n") fi = FetchInfo._from_line(self.rorepo, remote_info_line_fmt % "local/master", diff --git a/git/test/test_repo.py b/git/test/test_repo.py index f27521a8..58741b44 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -129,7 +129,7 @@ class TestRepo(TestBase): self.assertEqual(self.rorepo.tree(tree), tree) # try from invalid revision that does not exist - self.failUnlessRaises(BadName, self.rorepo.tree, 'hello world') + self.assertRaises(BadName, self.rorepo.tree, 'hello world') def test_pickleable(self): pickle.loads(pickle.dumps(self.rorepo)) @@ -755,8 +755,8 @@ class TestRepo(TestBase): commit = rev_parse(first_rev) self.assertEqual(len(commit.parents), 0) self.assertEqual(commit.hexsha, first_rev) - self.failUnlessRaises(BadName, rev_parse, first_rev + "~") - self.failUnlessRaises(BadName, rev_parse, first_rev + "^") + self.assertRaises(BadName, rev_parse, first_rev + "~") + self.assertRaises(BadName, rev_parse, first_rev + "^") # short SHA1 commit2 = rev_parse(first_rev[:20]) @@ -784,17 +784,17 @@ class TestRepo(TestBase): # END for each binsha in repo # missing closing brace commit^{tree - self.failUnlessRaises(ValueError, rev_parse, '0.1.4^{tree') + self.assertRaises(ValueError, rev_parse, '0.1.4^{tree') # missing starting brace - self.failUnlessRaises(ValueError, rev_parse, '0.1.4^tree}') + self.assertRaises(ValueError, rev_parse, '0.1.4^tree}') # REVLOG ####### head = self.rorepo.head # need to specify a ref when using the @ syntax - self.failUnlessRaises(BadObject, rev_parse, "%s@{0}" % head.commit.hexsha) + self.assertRaises(BadObject, rev_parse, "%s@{0}" % head.commit.hexsha) # uses HEAD.ref by default self.assertEqual(rev_parse('@{0}'), head.commit) @@ -807,10 +807,10 @@ class TestRepo(TestBase): # END operate on non-detached head # position doesn't exist - self.failUnlessRaises(IndexError, rev_parse, '@{10000}') + self.assertRaises(IndexError, rev_parse, '@{10000}') # currently, nothing more is supported - self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}") + self.assertRaises(NotImplementedError, rev_parse, "@{1 week ago}") # the last position assert rev_parse('@{1}') != head.commit @@ -824,13 +824,13 @@ class TestRepo(TestBase): self.assertGreaterEqual(len(list(self.rorepo.iter_submodules())), 2) self.assertIsInstance(self.rorepo.submodule("gitdb"), Submodule) - self.failUnlessRaises(ValueError, self.rorepo.submodule, "doesn't exist") + self.assertRaises(ValueError, self.rorepo.submodule, "doesn't exist") @with_rw_repo('HEAD', bare=False) def test_submodule_update(self, rwrepo): # fails in bare mode rwrepo._bare = True - self.failUnlessRaises(InvalidGitRepositoryError, rwrepo.submodule_update) + self.assertRaises(InvalidGitRepositoryError, rwrepo.submodule_update) rwrepo._bare = False # test create submodule @@ -877,7 +877,7 @@ class TestRepo(TestBase): # end for each iteration def test_remote_method(self): - self.failUnlessRaises(ValueError, self.rorepo.remote, 'foo-blue') + self.assertRaises(ValueError, self.rorepo.remote, 'foo-blue') self.assertIsInstance(self.rorepo.remote(name='origin'), Remote) @with_rw_directory @@ -885,16 +885,16 @@ class TestRepo(TestBase): """Assure we can handle empty repositories""" r = Repo.init(rw_dir, mkdir=False) # It's ok not to be able to iterate a commit, as there is none - self.failUnlessRaises(ValueError, r.iter_commits) + self.assertRaises(ValueError, r.iter_commits) self.assertEqual(r.active_branch.name, 'master') assert not r.active_branch.is_valid(), "Branch is yet to be born" # actually, when trying to create a new branch without a commit, git itself fails # We should, however, not fail ungracefully - self.failUnlessRaises(BadName, r.create_head, 'foo') - self.failUnlessRaises(BadName, r.create_head, 'master') + self.assertRaises(BadName, r.create_head, 'foo') + self.assertRaises(BadName, r.create_head, 'master') # It's expected to not be able to access a tree - self.failUnlessRaises(ValueError, r.tree) + self.assertRaises(ValueError, r.tree) new_file_path = osp.join(rw_dir, "new_file.ext") touch(new_file_path) @@ -921,8 +921,8 @@ class TestRepo(TestBase): c1 = 'f6aa8d1' c2 = repo.commit('d46e3fe') c3 = '763ef75' - self.failUnlessRaises(ValueError, repo.merge_base) - self.failUnlessRaises(ValueError, repo.merge_base, 'foo') + self.assertRaises(ValueError, repo.merge_base) + self.assertRaises(ValueError, repo.merge_base, 'foo') # two commit merge-base res = repo.merge_base(c1, c2) @@ -938,7 +938,7 @@ class TestRepo(TestBase): # end for each keyword signalling all merge-bases to be returned # Test for no merge base - can't do as we have - self.failUnlessRaises(GitCommandError, repo.merge_base, c1, 'ffffff') + self.assertRaises(GitCommandError, repo.merge_base, c1, 'ffffff') def test_is_ancestor(self): git = self.rorepo.git diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 0d306edc..9dd43934 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -54,7 +54,7 @@ class TestSubmodule(TestBase): # manual instantiation smm = Submodule(rwrepo, "\0" * 20) # name needs to be set in advance - self.failUnlessRaises(AttributeError, getattr, smm, 'name') + self.assertRaises(AttributeError, getattr, smm, 'name') # iterate - 1 submodule sms = Submodule.list_items(rwrepo, self.k_subm_current) @@ -73,10 +73,10 @@ class TestSubmodule(TestBase): # size is always 0 assert sm.size == 0 # the module is not checked-out yet - self.failUnlessRaises(InvalidGitRepositoryError, sm.module) + self.assertRaises(InvalidGitRepositoryError, sm.module) # which is why we can't get the branch either - it points into the module() repository - self.failUnlessRaises(InvalidGitRepositoryError, getattr, sm, 'branch') + self.assertRaises(InvalidGitRepositoryError, getattr, sm, 'branch') # branch_path works, as its just a string assert isinstance(sm.branch_path, str) @@ -117,14 +117,14 @@ class TestSubmodule(TestBase): # END handle bare repo # make the old into a new - this doesn't work as the name changed - self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_subm_current) + self.assertRaises(ValueError, smold.set_parent_commit, self.k_subm_current) # the sha is properly updated smold.set_parent_commit(self.k_subm_changed + "~1") assert smold.binsha != sm.binsha # raises if the sm didn't exist in new parent - it keeps its # parent_commit unchanged - self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_no_subm_tag) + self.assertRaises(ValueError, smold.set_parent_commit, self.k_no_subm_tag) # TEST TODO: if a path in the gitmodules file, but not in the index, it raises @@ -132,12 +132,12 @@ class TestSubmodule(TestBase): ############## # module retrieval is not always possible if rwrepo.bare: - self.failUnlessRaises(InvalidGitRepositoryError, sm.module) - self.failUnlessRaises(InvalidGitRepositoryError, sm.remove) - self.failUnlessRaises(InvalidGitRepositoryError, sm.add, rwrepo, 'here', 'there') + self.assertRaises(InvalidGitRepositoryError, sm.module) + self.assertRaises(InvalidGitRepositoryError, sm.remove) + self.assertRaises(InvalidGitRepositoryError, sm.add, rwrepo, 'here', 'there') else: # its not checked out in our case - self.failUnlessRaises(InvalidGitRepositoryError, sm.module) + self.assertRaises(InvalidGitRepositoryError, sm.module) assert not sm.module_exists() # currently there is only one submodule @@ -152,7 +152,7 @@ class TestSubmodule(TestBase): assert sma.path == sm.path # no url and no module at path fails - self.failUnlessRaises(ValueError, Submodule.add, rwrepo, "newsubm", "pathtorepo", url=None) + self.assertRaises(ValueError, Submodule.add, rwrepo, "newsubm", "pathtorepo", url=None) # CONTINUE UPDATE ################# @@ -162,7 +162,7 @@ class TestSubmodule(TestBase): os.makedirs(newdir) # update fails if the path already exists non-empty - self.failUnlessRaises(OSError, sm.update) + self.assertRaises(OSError, sm.update) os.rmdir(newdir) # dry-run does nothing @@ -179,7 +179,7 @@ class TestSubmodule(TestBase): ##################### # url must match the one in the existing repository ( if submodule name suggests a new one ) # or we raise - self.failUnlessRaises(ValueError, Submodule.add, rwrepo, "newsubm", sm.path, "git://someurl/repo.git") + self.assertRaises(ValueError, Submodule.add, rwrepo, "newsubm", sm.path, "git://someurl/repo.git") # CONTINUE UPDATE ################# @@ -230,13 +230,13 @@ class TestSubmodule(TestBase): # END for each repo to reset # dry run does nothing - self.failUnlessRaises(RepositoryDirtyError, sm.update, recursive=True, dry_run=True, progress=prog) + self.assertRaises(RepositoryDirtyError, sm.update, recursive=True, dry_run=True, progress=prog) sm.update(recursive=True, dry_run=True, progress=prog, force=True) for repo in smods: assert repo.head.commit != repo.head.ref.tracking_branch().commit # END for each repo to check - self.failUnlessRaises(RepositoryDirtyError, sm.update, recursive=True, to_latest_revision=True) + self.assertRaises(RepositoryDirtyError, sm.update, recursive=True, to_latest_revision=True) sm.update(recursive=True, to_latest_revision=True, force=True) for repo in smods: assert repo.head.commit == repo.head.ref.tracking_branch().commit @@ -262,7 +262,7 @@ class TestSubmodule(TestBase): # REMOVAL OF REPOSITOTRY ######################## # must delete something - self.failUnlessRaises(ValueError, csm.remove, module=False, configuration=False) + self.assertRaises(ValueError, csm.remove, module=False, configuration=False) # module() is supposed to point to gitdb, which has a child-submodule whose URL is still pointing # to GitHub. To save time, we will change it to @@ -280,11 +280,11 @@ class TestSubmodule(TestBase): writer.set_value("somekey", "somevalue") with csm.config_writer() as writer: writer.set_value("okey", "ovalue") - self.failUnlessRaises(InvalidGitRepositoryError, sm.remove) + self.assertRaises(InvalidGitRepositoryError, sm.remove) # if we remove the dirty index, it would work sm.module().index.reset() # still, we have the file modified - self.failUnlessRaises(InvalidGitRepositoryError, sm.remove, dry_run=True) + self.assertRaises(InvalidGitRepositoryError, sm.remove, dry_run=True) sm.module().index.reset(working_tree=True) # enforce the submodule to be checked out at the right spot as well. @@ -303,11 +303,11 @@ class TestSubmodule(TestBase): fn = join_path_native(csm.module().working_tree_dir, "newfile") with open(fn, 'w') as fd: fd.write("hi") - self.failUnlessRaises(InvalidGitRepositoryError, sm.remove) + self.assertRaises(InvalidGitRepositoryError, sm.remove) # forcibly delete the child repository prev_count = len(sm.children()) - self.failUnlessRaises(ValueError, csm.remove, force=True) + self.assertRaises(ValueError, csm.remove, force=True) # We removed sm, which removed all submodules. However, the instance we # have still points to the commit prior to that, where it still existed csm.set_parent_commit(csm.repo.commit(), check=False) @@ -330,7 +330,7 @@ class TestSubmodule(TestBase): sm.remove() assert not sm.exists() assert not sm.module_exists() - self.failUnlessRaises(ValueError, getattr, sm, 'path') + self.assertRaises(ValueError, getattr, sm, 'path') assert len(rwrepo.submodules) == 0 @@ -368,7 +368,7 @@ class TestSubmodule(TestBase): # MOVE MODULE ############# # invalid input - self.failUnlessRaises(ValueError, nsm.move, 'doesntmatter', module=False, configuration=False) + self.assertRaises(ValueError, nsm.move, 'doesntmatter', module=False, configuration=False) # renaming to the same path does nothing assert nsm.move(sm_path) is nsm @@ -385,7 +385,7 @@ class TestSubmodule(TestBase): mpath = 'newsubmodule' absmpath = join_path_native(rwrepo.working_tree_dir, mpath) open(absmpath, 'w').write('') - self.failUnlessRaises(ValueError, nsm.move, mpath) + self.assertRaises(ValueError, nsm.move, mpath) os.remove(absmpath) # now it works, as we just move it back @@ -402,11 +402,11 @@ class TestSubmodule(TestBase): for remote in osmod.remotes: remote.remove(osmod, remote.name) assert not osm.exists() - self.failUnlessRaises(ValueError, Submodule.add, rwrepo, osmid, csm_repopath, url=None) + self.assertRaises(ValueError, Submodule.add, rwrepo, osmid, csm_repopath, url=None) # END handle bare mode # Error if there is no submodule file here - self.failUnlessRaises(IOError, Submodule._config_parser, rwrepo, rwrepo.commit(self.k_no_subm_tag), True) + self.assertRaises(IOError, Submodule._config_parser, rwrepo, rwrepo.commit(self.k_no_subm_tag), True) # @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, ## ACTUALLY skipped by `git.submodule.base#L869`. # "FIXME: fails with: PermissionError: [WinError 32] The process cannot access the file because" @@ -450,7 +450,7 @@ class TestSubmodule(TestBase): assert len(rsmsp) >= 2 # gitdb and async [and smmap], async being a child of gitdb # cannot set the parent commit as root module's path didn't exist - self.failUnlessRaises(ValueError, rm.set_parent_commit, 'HEAD') + self.assertRaises(ValueError, rm.set_parent_commit, 'HEAD') # TEST UPDATE ############# @@ -485,7 +485,7 @@ class TestSubmodule(TestBase): # move it properly - doesn't work as it its path currently points to an indexentry # which doesn't exist ( move it to some path, it doesn't matter here ) - self.failUnlessRaises(InvalidGitRepositoryError, sm.move, pp) + self.assertRaises(InvalidGitRepositoryError, sm.move, pp) # reset the path(cache) to where it was, now it works sm.path = prep sm.move(fp, module=False) # leave it at the old location @@ -535,7 +535,7 @@ class TestSubmodule(TestBase): # when removing submodules, we may get new commits as nested submodules are auto-committing changes # to allow deletions without force, as the index would be dirty otherwise. # QUESTION: Why does this seem to work in test_git_submodule_compatibility() ? - self.failUnlessRaises(InvalidGitRepositoryError, rm.update, recursive=False, force_remove=False) + self.assertRaises(InvalidGitRepositoryError, rm.update, recursive=False, force_remove=False) rm.update(recursive=False, force_remove=True) assert not osp.isdir(smp) @@ -643,9 +643,9 @@ class TestSubmodule(TestBase): rwrepo.index.commit("Added submodule " + sm_name) # end for each submodule path to add - self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail', osp.expanduser('~')) - self.failUnlessRaises(ValueError, rwrepo.create_submodule, 'fail-too', - rwrepo.working_tree_dir + osp.sep) + self.assertRaises(ValueError, rwrepo.create_submodule, 'fail', osp.expanduser('~')) + self.assertRaises(ValueError, rwrepo.create_submodule, 'fail-too', + rwrepo.working_tree_dir + osp.sep) @with_rw_directory def test_add_empty_repo(self, rwdir): @@ -656,8 +656,8 @@ class TestSubmodule(TestBase): for checkout_mode in range(2): name = 'empty' + str(checkout_mode) - self.failUnlessRaises(ValueError, parent.create_submodule, name, name, - url=empty_repo_dir, no_checkout=checkout_mode and True or False) + self.assertRaises(ValueError, parent.create_submodule, name, name, + url=empty_repo_dir, no_checkout=checkout_mode and True or False) # end for each checkout mode @with_rw_directory @@ -789,7 +789,7 @@ class TestSubmodule(TestBase): assert_exists(csm) # Fails because there are new commits, compared to the remote we cloned from - self.failUnlessRaises(InvalidGitRepositoryError, sm.remove, dry_run=True) + self.assertRaises(InvalidGitRepositoryError, sm.remove, dry_run=True) assert_exists(sm) assert sm.module().commit() == sm_head_commit assert_exists(csm) @@ -811,7 +811,7 @@ class TestSubmodule(TestBase): csm.repo.index.commit("Have to commit submodule change for algorithm to pick it up") assert csm.url == 'bar' - self.failUnlessRaises(Exception, rsm.update, recursive=True, to_latest_revision=True, progress=prog) + self.assertRaises(Exception, rsm.update, recursive=True, to_latest_revision=True, progress=prog) assert_exists(csm) rsm.update(recursive=True, to_latest_revision=True, progress=prog, keep_going=True) @@ -922,7 +922,7 @@ class TestSubmodule(TestBase): sm_mod.head.ref.name == sm_pfb.name, "should have been switched to past head" sm_mod.commit() == sm_fb.commit, "Head wasn't reset" - self.failUnlessRaises(RepositoryDirtyError, parent_repo.submodule_update, to_latest_revision=True) + self.assertRaises(RepositoryDirtyError, parent_repo.submodule_update, to_latest_revision=True) parent_repo.submodule_update(to_latest_revision=True, force_reset=True) assert sm_mod.commit() == sm_pfb.commit, "Now head should have been reset" assert sm_mod.head.ref.name == sm_pfb.name diff --git a/git/test/test_tree.py b/git/test/test_tree.py index dc23f29c..213e7a95 100644 --- a/git/test/test_tree.py +++ b/git/test/test_tree.py @@ -34,7 +34,7 @@ class TestTree(TestBase): # END skip non-trees tree = item # trees have no dict - self.failUnlessRaises(AttributeError, setattr, tree, 'someattr', 1) + self.assertRaises(AttributeError, setattr, tree, 'someattr', 1) orig_data = tree.data_stream.read() orig_cache = tree._cache diff --git a/git/test/test_util.py b/git/test/test_util.py index 5faeeacb..1560affb 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -143,13 +143,13 @@ class TestUtils(TestBase): # concurrent access other_lock_file = LockFile(my_file) assert not other_lock_file._has_lock() - self.failUnlessRaises(IOError, other_lock_file._obtain_lock_or_raise) + self.assertRaises(IOError, other_lock_file._obtain_lock_or_raise) lock_file._release_lock() assert not lock_file._has_lock() other_lock_file._obtain_lock_or_raise() - self.failUnlessRaises(IOError, lock_file._obtain_lock_or_raise) + self.assertRaises(IOError, lock_file._obtain_lock_or_raise) # auto-release on destruction del(other_lock_file) @@ -165,7 +165,7 @@ class TestUtils(TestBase): start = time.time() wait_time = 0.1 wait_lock = BlockingLockFile(my_file, 0.05, wait_time) - self.failUnlessRaises(IOError, wait_lock._obtain_lock) + self.assertRaises(IOError, wait_lock._obtain_lock) elapsed = time.time() - start extra_time = 0.02 if is_win: @@ -203,9 +203,9 @@ class TestUtils(TestBase): # END for each date type # and failure - self.failUnlessRaises(ValueError, parse_date, 'invalid format') - self.failUnlessRaises(ValueError, parse_date, '123456789 -02000') - self.failUnlessRaises(ValueError, parse_date, ' 123456789 -0200') + self.assertRaises(ValueError, parse_date, 'invalid format') + self.assertRaises(ValueError, parse_date, '123456789 -02000') + self.assertRaises(ValueError, parse_date, ' 123456789 -0200') def test_actor(self): for cr in (None, self.rorepo.config_reader()): @@ -253,11 +253,11 @@ class TestUtils(TestBase): self.assertIs(ilist.two, m2) # test exceptions - self.failUnlessRaises(AttributeError, getattr, ilist, 'something') - self.failUnlessRaises(IndexError, ilist.__getitem__, 'something') + self.assertRaises(AttributeError, getattr, ilist, 'something') + self.assertRaises(IndexError, ilist.__getitem__, 'something') # delete by name and index - self.failUnlessRaises(IndexError, ilist.__delitem__, 'something') + self.assertRaises(IndexError, ilist.__delitem__, 'something') del(ilist[name2]) self.assertEqual(len(ilist), 1) self.assertNotIn(name2, ilist) @@ -266,8 +266,8 @@ class TestUtils(TestBase): self.assertNotIn(name1, ilist) self.assertEqual(len(ilist), 0) - self.failUnlessRaises(IndexError, ilist.__delitem__, 0) - self.failUnlessRaises(IndexError, ilist.__delitem__, 'something') + self.assertRaises(IndexError, ilist.__delitem__, 0) + self.assertRaises(IndexError, ilist.__delitem__, 'something') def test_from_timestamp(self): # Correct offset: UTC+2, should return datetime + tzoffset(+2) |