7 files changed
@@ -15,7 +15,6 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | class TestObjDBPerformance(TestBigRepoR): | |
| 18 | - | ||
| 19 | 18 | large_data_size_bytes = 1000 * 1000 * 10 # some MiB should do it | |
| 20 | 19 | moderate_data_size_bytes = 1000 * 1000 * 1 # just 1 MiB | |
| 21 | 20 | ||
@@ -93,7 +93,6 @@ def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info= | |||
| 93 | 93 | ||
| 94 | 94 | class TestCommit(TestCommitSerialization): | |
| 95 | 95 | def test_bake(self): | |
| 96 | - | ||
| 97 | 96 | commit = self.rorepo.commit("2454ae89983a4496a445ce347d7a41c0bb0ea7ae") | |
| 98 | 97 | # commits have no dict | |
| 99 | 98 | self.assertRaises(AttributeError, setattr, commit, "someattr", 1) | |
@@ -170,15 +169,15 @@ def test_renames(self): | |||
| 170 | 169 | ||
| 171 | 170 | def check_entries(path, changes): | |
| 172 | 171 | expected = { | |
| 173 | - ".github/workflows/Future.yml" : { | ||
| 174 | - 'insertions': 57, | ||
| 175 | - 'deletions': 0, | ||
| 176 | - 'lines': 57, | ||
| 172 | + ".github/workflows/Future.yml": { | ||
| 173 | + "insertions": 57, | ||
| 174 | + "deletions": 0, | ||
| 175 | + "lines": 57, | ||
| 177 | 176 | }, | |
| 178 | - ".github/workflows/test_pytest.yml" : { | ||
| 179 | - 'insertions': 0, | ||
| 180 | - 'deletions': 55, | ||
| 181 | - 'lines': 55, | ||
| 177 | + ".github/workflows/test_pytest.yml": { | ||
| 178 | + "insertions": 0, | ||
| 179 | + "deletions": 55, | ||
| 180 | + "lines": 55, | ||
| 182 | 181 | }, | |
| 183 | 182 | } | |
| 184 | 183 | assert path in expected | |
@@ -419,7 +419,7 @@ def test_rename_override(self, rw_dir): | |||
| 419 | 419 | # create and commit file_a.txt | |
| 420 | 420 | repo = Repo.init(rw_dir) | |
| 421 | 421 | file_a = osp.join(rw_dir, "file_a.txt") | |
| 422 | - with open(file_a, "w", encoding='utf-8') as outfile: | ||
| 422 | + with open(file_a, "w", encoding="utf-8") as outfile: | ||
| 423 | 423 | outfile.write("hello world\n") | |
| 424 | 424 | repo.git.add(Git.polish_url(file_a)) | |
| 425 | 425 | repo.git.commit(message="Added file_a.txt") | |
@@ -429,21 +429,21 @@ def test_rename_override(self, rw_dir): | |||
| 429 | 429 | ||
| 430 | 430 | # create and commit file_b.txt with similarity index of 52 | |
| 431 | 431 | file_b = osp.join(rw_dir, "file_b.txt") | |
| 432 | - with open(file_b, "w", encoding='utf-8') as outfile: | ||
| 432 | + with open(file_b, "w", encoding="utf-8") as outfile: | ||
| 433 | 433 | outfile.write("hello world\nhello world") | |
| 434 | 434 | repo.git.add(Git.polish_url(file_b)) | |
| 435 | 435 | repo.git.commit(message="Removed file_a.txt. Added file_b.txt") | |
| 436 | 436 | ||
| 437 | - commit_a = repo.commit('HEAD') | ||
| 438 | - commit_b = repo.commit('HEAD~1') | ||
| 437 | + commit_a = repo.commit("HEAD") | ||
| 438 | + commit_b = repo.commit("HEAD~1") | ||
| 439 | 439 | ||
| 440 | 440 | # check default diff command with renamed files enabled | |
| 441 | 441 | diffs = commit_b.diff(commit_a) | |
| 442 | 442 | self.assertEqual(1, len(diffs)) | |
| 443 | 443 | diff = diffs[0] | |
| 444 | 444 | self.assertEqual(True, diff.renamed_file) | |
| 445 | - self.assertEqual('file_a.txt', diff.rename_from) | ||
| 446 | - self.assertEqual('file_b.txt', diff.rename_to) | ||
| 445 | + self.assertEqual("file_a.txt", diff.rename_from) | ||
| 446 | + self.assertEqual("file_b.txt", diff.rename_to) | ||
| 447 | 447 | ||
| 448 | 448 | # check diff with rename files disabled | |
| 449 | 449 | diffs = commit_b.diff(commit_a, no_renames=True) | |
@@ -452,31 +452,31 @@ def test_rename_override(self, rw_dir): | |||
| 452 | 452 | # check fileA.txt deleted | |
| 453 | 453 | diff = diffs[0] | |
| 454 | 454 | self.assertEqual(True, diff.deleted_file) | |
| 455 | - self.assertEqual('file_a.txt', diff.a_path) | ||
| 455 | + self.assertEqual("file_a.txt", diff.a_path) | ||
| 456 | 456 | ||
| 457 | 457 | # check fileB.txt added | |
| 458 | 458 | diff = diffs[1] | |
| 459 | 459 | self.assertEqual(True, diff.new_file) | |
| 460 | - self.assertEqual('file_b.txt', diff.a_path) | ||
| 460 | + self.assertEqual("file_b.txt", diff.a_path) | ||
| 461 | 461 | ||
| 462 | 462 | # check diff with high similarity index | |
| 463 | - diffs = commit_b.diff(commit_a, split_single_char_options=False, M='75%') | ||
| 463 | + diffs = commit_b.diff(commit_a, split_single_char_options=False, M="75%") | ||
| 464 | 464 | self.assertEqual(2, len(diffs)) | |
| 465 | 465 | ||
| 466 | 466 | # check fileA.txt deleted | |
| 467 | 467 | diff = diffs[0] | |
| 468 | 468 | self.assertEqual(True, diff.deleted_file) | |
| 469 | - self.assertEqual('file_a.txt', diff.a_path) | ||
| 469 | + self.assertEqual("file_a.txt", diff.a_path) | ||
| 470 | 470 | ||
| 471 | 471 | # check fileB.txt added | |
| 472 | 472 | diff = diffs[1] | |
| 473 | 473 | self.assertEqual(True, diff.new_file) | |
| 474 | - self.assertEqual('file_b.txt', diff.a_path) | ||
| 474 | + self.assertEqual("file_b.txt", diff.a_path) | ||
| 475 | 475 | ||
| 476 | 476 | # check diff with low similarity index | |
| 477 | - diffs = commit_b.diff(commit_a, split_single_char_options=False, M='40%') | ||
| 477 | + diffs = commit_b.diff(commit_a, split_single_char_options=False, M="40%") | ||
| 478 | 478 | self.assertEqual(1, len(diffs)) | |
| 479 | 479 | diff = diffs[0] | |
| 480 | 480 | self.assertEqual(True, diff.renamed_file) | |
| 481 | - self.assertEqual('file_a.txt', diff.rename_from) | ||
| 482 | - self.assertEqual('file_b.txt', diff.rename_to) | ||
| 481 | + self.assertEqual("file_a.txt", diff.rename_from) | ||
| 482 | + self.assertEqual("file_b.txt", diff.rename_to) | ||
@@ -946,7 +946,7 @@ def test_commit_msg_hook_fail(self, rw_repo): | |||
| 946 | 946 | else: | |
| 947 | 947 | raise AssertionError("Should have caught a HookExecutionError") | |
| 948 | 948 | ||
| 949 | - @with_rw_repo('HEAD') | ||
| 949 | + @with_rw_repo("HEAD") | ||
| 950 | 950 | def test_index_add_pathlike(self, rw_repo): | |
| 951 | 951 | git_dir = Path(rw_repo.git_dir) | |
| 952 | 952 | ||
@@ -13,24 +13,23 @@ def tearDown(self): | |||
| 13 | 13 | ||
| 14 | 14 | @with_rw_directory | |
| 15 | 15 | def test_init_repo_object(self, path_to_dir): | |
| 16 | - | ||
| 17 | 16 | # [1-test_init_repo_object] | |
| 18 | 17 | # $ git init <path/to/dir> | |
| 19 | 18 | ||
| 20 | 19 | from git import Repo | |
| 21 | 20 | ||
| 22 | 21 | repo = Repo.init(path_to_dir) | |
| 23 | - # ![1-test_init_repo_object] | ||
| 22 | + # ![1-test_init_repo_object] | ||
| 24 | 23 | ||
| 25 | 24 | # [2-test_init_repo_object] | |
| 26 | 25 | repo = Repo(path_to_dir) | |
| 27 | 26 | # ![2-test_init_repo_object] | |
| 28 | 27 | ||
| 29 | 28 | @with_rw_directory | |
| 30 | 29 | def test_cloned_repo_object(self, local_dir): | |
| 31 | - | ||
| 32 | 30 | from git import Repo | |
| 33 | 31 | import git | |
| 32 | + | ||
| 34 | 33 | # code to clone from url | |
| 35 | 34 | # [1-test_cloned_repo_object] | |
| 36 | 35 | # $ git clone <url> <local_dir> | |
@@ -44,9 +43,9 @@ def test_cloned_repo_object(self, local_dir): | |||
| 44 | 43 | # [2-test_cloned_repo_object] | |
| 45 | 44 | # We must make a change to a file so that we can add the update to git | |
| 46 | 45 | ||
| 47 | - update_file = 'dir1/file2.txt' # we'll use local_dir/dir1/file2.txt | ||
| 48 | - with open(f"{local_dir}/{update_file}", 'a') as f: | ||
| 49 | - f.write('\nUpdate version 2') | ||
| 46 | + update_file = "dir1/file2.txt" # we'll use local_dir/dir1/file2.txt | ||
| 47 | + with open(f"{local_dir}/{update_file}", "a") as f: | ||
| 48 | + f.write("\nUpdate version 2") | ||
| 50 | 49 | # ![2-test_cloned_repo_object] | |
| 51 | 50 | ||
| 52 | 51 | # [3-test_cloned_repo_object] | |
@@ -82,7 +81,7 @@ def test_cloned_repo_object(self, local_dir): | |||
| 82 | 81 | ||
| 83 | 82 | # Untracked files - create new file | |
| 84 | 83 | # [7-test_cloned_repo_object] | |
| 85 | - f = open(f'{local_dir}/untracked.txt', 'w') # creates an empty file | ||
| 84 | + f = open(f"{local_dir}/untracked.txt", "w") # creates an empty file | ||
| 86 | 85 | f.close() | |
| 87 | 86 | # ![7-test_cloned_repo_object] | |
| 88 | 87 | ||
@@ -95,8 +94,8 @@ def test_cloned_repo_object(self, local_dir): | |||
| 95 | 94 | # [9-test_cloned_repo_object] | |
| 96 | 95 | # Let's modify one of our tracked files | |
| 97 | 96 | ||
| 98 | - with open(f'{local_dir}/Downloads/file3.txt', 'w') as f: | ||
| 99 | - f.write('file3 version 2') # overwrite file 3 | ||
| 97 | + with open(f"{local_dir}/Downloads/file3.txt", "w") as f: | ||
| 98 | + f.write("file3 version 2") # overwrite file 3 | ||
| 100 | 99 | # ![9-test_cloned_repo_object] | |
| 101 | 100 | ||
| 102 | 101 | # [10-test_cloned_repo_object] | |
@@ -126,7 +125,7 @@ def test_cloned_repo_object(self, local_dir): | |||
| 126 | 125 | # ![11.1-test_cloned_repo_object] | |
| 127 | 126 | # [11.2-test_cloned_repo_object] | |
| 128 | 127 | # lets add untracked.txt | |
| 129 | - repo.index.add(['untracked.txt']) | ||
| 128 | + repo.index.add(["untracked.txt"]) | ||
| 130 | 129 | diffs = repo.index.diff(repo.head.commit) | |
| 131 | 130 | for d in diffs: | |
| 132 | 131 | print(d.a_path) | |
@@ -146,9 +145,7 @@ def test_cloned_repo_object(self, local_dir): | |||
| 146 | 145 | # dir1/file2.txt | |
| 147 | 146 | # ![11.3-test_cloned_repo_object] | |
| 148 | 147 | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - '''Trees and Blobs''' | ||
| 148 | + """Trees and Blobs""" | ||
| 152 | 149 | ||
| 153 | 150 | # Latest commit tree | |
| 154 | 151 | # [12-test_cloned_repo_object] | |
@@ -195,7 +192,7 @@ def print_files_from_git(root, level=0): | |||
| 195 | 192 | ||
| 196 | 193 | # Printing text files | |
| 197 | 194 | # [17-test_cloned_repo_object] | |
| 198 | - print_file = 'dir1/file2.txt' | ||
| 195 | + print_file = "dir1/file2.txt" | ||
| 199 | 196 | tree[print_file] # the head commit tree | |
| 200 | 197 | ||
| 201 | 198 | # Output <git.Blob "SHA1-HEX-HASH"> | |
@@ -221,4 +218,4 @@ def print_files_from_git(root, level=0): | |||
| 221 | 218 | ||
| 222 | 219 | # Output | |
| 223 | 220 | # file 2 version 1 | |
| 224 | - # ![18.1-test_cloned_repo_object] | ||
| 221 | + # ![18.1-test_cloned_repo_object] | ||
@@ -251,7 +251,9 @@ def test_clone_from_with_path_contains_unicode(self): | |||
| 251 | 251 | self.fail("Raised UnicodeEncodeError") | |
| 252 | 252 | ||
| 253 | 253 | @with_rw_directory | |
| 254 | - @skip("the referenced repository was removed, and one needs to setup a new password controlled repo under the orgs control") | ||
| 254 | + @skip( | ||
| 255 | + "the referenced repository was removed, and one needs to setup a new password controlled repo under the orgs control" | ||
| 256 | + ) | ||
| 255 | 257 | def test_leaking_password_in_clone_logs(self, rw_dir): | |
| 256 | 258 | password = "fakepassword1234" | |
| 257 | 259 | try: | |
@@ -391,7 +393,9 @@ def test_clone_from_unsafe_options_allowed(self, rw_repo): | |||
| 391 | 393 | for i, unsafe_option in enumerate(unsafe_options): | |
| 392 | 394 | destination = tmp_dir / str(i) | |
| 393 | 395 | assert not destination.exists() | |
| 394 | - Repo.clone_from(rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True) | ||
| 396 | + Repo.clone_from( | ||
| 397 | + rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True | ||
| 398 | + ) | ||
| 395 | 399 | assert destination.exists() | |
| 396 | 400 | ||
| 397 | 401 | @with_rw_repo("HEAD") | |
@@ -755,8 +759,8 @@ def test_blame_complex_revision(self, git): | |||
| 755 | 759 | @mock.patch.object(Git, "_call_process") | |
| 756 | 760 | def test_blame_accepts_rev_opts(self, git): | |
| 757 | 761 | res = self.rorepo.blame("HEAD", "README.md", rev_opts=["-M", "-C", "-C"]) | |
| 758 | - expected_args = ['blame', 'HEAD', '-M', '-C', '-C', '--', 'README.md'] | ||
| 759 | - boilerplate_kwargs = {"p" : True, "stdout_as_string": False} | ||
| 762 | + expected_args = ["blame", "HEAD", "-M", "-C", "-C", "--", "README.md"] | ||
| 763 | + boilerplate_kwargs = {"p": True, "stdout_as_string": False} | ||
| 760 | 764 | git.assert_called_once_with(*expected_args, **boilerplate_kwargs) | |
| 761 | 765 | ||
| 762 | 766 | @skipIf( | |
@@ -1415,14 +1419,16 @@ def test_ignored_items_reported(self): | |||
| 1415 | 1419 | ||
| 1416 | 1420 | gi = tmp_dir / "repo" / ".gitignore" | |
| 1417 | 1421 | ||
| 1418 | - with open(gi, 'w') as file: | ||
| 1419 | - file.write('ignored_file.txt\n') | ||
| 1420 | - file.write('ignored_dir/\n') | ||
| 1422 | + with open(gi, "w") as file: | ||
| 1423 | + file.write("ignored_file.txt\n") | ||
| 1424 | + file.write("ignored_dir/\n") | ||
| 1421 | 1425 | ||
| 1422 | - assert temp_repo.ignored(['included_file.txt', 'included_dir/file.txt']) == [] | ||
| 1423 | - assert temp_repo.ignored(['ignored_file.txt']) == ['ignored_file.txt'] | ||
| 1424 | - assert temp_repo.ignored(['included_file.txt', 'ignored_file.txt']) == ['ignored_file.txt'] | ||
| 1425 | - assert temp_repo.ignored(['included_file.txt', 'ignored_file.txt', 'included_dir/file.txt', 'ignored_dir/file.txt']) == ['ignored_file.txt', 'ignored_dir/file.txt'] | ||
| 1426 | + assert temp_repo.ignored(["included_file.txt", "included_dir/file.txt"]) == [] | ||
| 1427 | + assert temp_repo.ignored(["ignored_file.txt"]) == ["ignored_file.txt"] | ||
| 1428 | + assert temp_repo.ignored(["included_file.txt", "ignored_file.txt"]) == ["ignored_file.txt"] | ||
| 1429 | + assert temp_repo.ignored( | ||
| 1430 | + ["included_file.txt", "ignored_file.txt", "included_dir/file.txt", "ignored_dir/file.txt"] | ||
| 1431 | + ) == ["ignored_file.txt", "ignored_dir/file.txt"] | ||
| 1426 | 1432 | ||
| 1427 | 1433 | def test_ignored_raises_error_w_symlink(self): | |
| 1428 | 1434 | with tempfile.TemporaryDirectory() as tdir: | |
@@ -39,11 +39,14 @@ def _patch_git_config(name, value): | |||
| 39 | 39 | ||
| 40 | 40 | # This is recomputed each time the context is entered, for compatibility with | |
| 41 | 41 | # existing GIT_CONFIG_* environment variables, even if changed in this process. | |
| 42 | - patcher = mock.patch.dict(os.environ, { | ||
| 43 | - "GIT_CONFIG_COUNT": str(pair_index + 1), | ||
| 44 | - f"GIT_CONFIG_KEY_{pair_index}": name, | ||
| 45 | - f"GIT_CONFIG_VALUE_{pair_index}": value, | ||
| 46 | - }) | ||
| 42 | + patcher = mock.patch.dict( | ||
| 43 | + os.environ, | ||
| 44 | + { | ||
| 45 | + "GIT_CONFIG_COUNT": str(pair_index + 1), | ||
| 46 | + f"GIT_CONFIG_KEY_{pair_index}": name, | ||
| 47 | + f"GIT_CONFIG_VALUE_{pair_index}": value, | ||
| 48 | + }, | ||
| 49 | + ) | ||
| 47 | 50 | ||
| 48 | 51 | with patcher: | |
| 49 | 52 | yield | |
@@ -914,17 +917,17 @@ def test_ignore_non_submodule_file(self, rwdir): | |||
| 914 | 917 | os.mkdir(smp) | |
| 915 | 918 | ||
| 916 | 919 | with open(osp.join(smp, "a"), "w", encoding="utf-8") as f: | |
| 917 | - f.write('test\n') | ||
| 920 | + f.write("test\n") | ||
| 918 | 921 | ||
| 919 | 922 | with open(osp.join(rwdir, ".gitmodules"), "w", encoding="utf-8") as f: | |
| 920 | - f.write("[submodule \"a\"]\n") | ||
| 923 | + f.write('[submodule "a"]\n') | ||
| 921 | 924 | f.write(" path = module\n") | |
| 922 | 925 | f.write(" url = https://github.com/chaconinc/DbConnector\n") | |
| 923 | 926 | ||
| 924 | 927 | parent.git.add(Git.polish_url(osp.join(smp, "a"))) | |
| 925 | 928 | parent.git.add(Git.polish_url(osp.join(rwdir, ".gitmodules"))) | |
| 926 | 929 | ||
| 927 | - parent.git.commit(message='test') | ||
| 930 | + parent.git.commit(message="test") | ||
| 928 | 931 | ||
| 929 | 932 | assert len(parent.submodules) == 0 | |
| 930 | 933 | ||
@@ -1200,7 +1203,12 @@ def test_submodule_add_unsafe_options_allowed(self, rw_repo): | |||
| 1200 | 1203 | # The options will be allowed, but the command will fail. | |
| 1201 | 1204 | with self.assertRaises(GitCommandError): | |
| 1202 | 1205 | Submodule.add( | |
| 1203 | - rw_repo, "new", "new", str(tmp_dir), clone_multi_options=[unsafe_option], allow_unsafe_options=True | ||
| 1206 | + rw_repo, | ||
| 1207 | + "new", | ||
| 1208 | + "new", | ||
| 1209 | + str(tmp_dir), | ||
| 1210 | + clone_multi_options=[unsafe_option], | ||
| 1211 | + allow_unsafe_options=True, | ||
| 1204 | 1212 | ) | |
| 1205 | 1213 | assert not tmp_file.exists() | |
| 1206 | 1214 | ||
@@ -1211,7 +1219,12 @@ def test_submodule_add_unsafe_options_allowed(self, rw_repo): | |||
| 1211 | 1219 | for unsafe_option in unsafe_options: | |
| 1212 | 1220 | with self.assertRaises(GitCommandError): | |
| 1213 | 1221 | Submodule.add( | |
| 1214 | - rw_repo, "new", "new", str(tmp_dir), clone_multi_options=[unsafe_option], allow_unsafe_options=True | ||
| 1222 | + rw_repo, | ||
| 1223 | + "new", | ||
| 1224 | + "new", | ||
| 1225 | + str(tmp_dir), | ||
| 1226 | + clone_multi_options=[unsafe_option], | ||
| 1227 | + allow_unsafe_options=True, | ||
| 1215 | 1228 | ) | |
| 1216 | 1229 | ||
| 1217 | 1230 | @with_rw_repo("HEAD") | |
0 commit comments