Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5a6464

Browse filesBrowse files
authored
Merge pull request #1668 from EliahKagan/black
Format tests with black and auto-exclude untracked paths
2 parents 1256b16 + 15c736d commit a5a6464
Copy full SHA for a5a6464

12 files changed

+82
-68
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ mypy -p git
159159
For automatic code formatting, run:
160160

161161
```bash
162-
black git
162+
black .
163163
```
164164

165165
Configuration for flake8 is in the `./.flake8` file.

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ omit = ["*/git/ext/*"]
4545
[tool.black]
4646
line-length = 120
4747
target-version = ['py37']
48-
exclude = "git/ext/gitdb"
48+
extend-exclude = "git/ext/gitdb"

‎test/performance/test_streams.py

Copy file name to clipboardExpand all lines: test/performance/test_streams.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616

1717
class TestObjDBPerformance(TestBigRepoR):
18-
1918
large_data_size_bytes = 1000 * 1000 * 10 # some MiB should do it
2019
moderate_data_size_bytes = 1000 * 1000 * 1 # just 1 MiB
2120

‎test/test_commit.py

Copy file name to clipboardExpand all lines: test/test_commit.py
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=
9393

9494
class TestCommit(TestCommitSerialization):
9595
def test_bake(self):
96-
9796
commit = self.rorepo.commit("2454ae89983a4496a445ce347d7a41c0bb0ea7ae")
9897
# commits have no dict
9998
self.assertRaises(AttributeError, setattr, commit, "someattr", 1)
@@ -170,15 +169,15 @@ def test_renames(self):
170169

171170
def check_entries(path, changes):
172171
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,
177176
},
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,
182181
},
183182
}
184183
assert path in expected

‎test/test_diff.py

Copy file name to clipboardExpand all lines: test/test_diff.py
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def test_rename_override(self, rw_dir):
419419
# create and commit file_a.txt
420420
repo = Repo.init(rw_dir)
421421
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:
423423
outfile.write("hello world\n")
424424
repo.git.add(Git.polish_url(file_a))
425425
repo.git.commit(message="Added file_a.txt")
@@ -429,21 +429,21 @@ def test_rename_override(self, rw_dir):
429429

430430
# create and commit file_b.txt with similarity index of 52
431431
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:
433433
outfile.write("hello world\nhello world")
434434
repo.git.add(Git.polish_url(file_b))
435435
repo.git.commit(message="Removed file_a.txt. Added file_b.txt")
436436

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")
439439

440440
# check default diff command with renamed files enabled
441441
diffs = commit_b.diff(commit_a)
442442
self.assertEqual(1, len(diffs))
443443
diff = diffs[0]
444444
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)
447447

448448
# check diff with rename files disabled
449449
diffs = commit_b.diff(commit_a, no_renames=True)
@@ -452,31 +452,31 @@ def test_rename_override(self, rw_dir):
452452
# check fileA.txt deleted
453453
diff = diffs[0]
454454
self.assertEqual(True, diff.deleted_file)
455-
self.assertEqual('file_a.txt', diff.a_path)
455+
self.assertEqual("file_a.txt", diff.a_path)
456456

457457
# check fileB.txt added
458458
diff = diffs[1]
459459
self.assertEqual(True, diff.new_file)
460-
self.assertEqual('file_b.txt', diff.a_path)
460+
self.assertEqual("file_b.txt", diff.a_path)
461461

462462
# 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%")
464464
self.assertEqual(2, len(diffs))
465465

466466
# check fileA.txt deleted
467467
diff = diffs[0]
468468
self.assertEqual(True, diff.deleted_file)
469-
self.assertEqual('file_a.txt', diff.a_path)
469+
self.assertEqual("file_a.txt", diff.a_path)
470470

471471
# check fileB.txt added
472472
diff = diffs[1]
473473
self.assertEqual(True, diff.new_file)
474-
self.assertEqual('file_b.txt', diff.a_path)
474+
self.assertEqual("file_b.txt", diff.a_path)
475475

476476
# 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%")
478478
self.assertEqual(1, len(diffs))
479479
diff = diffs[0]
480480
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)

‎test/test_docs.py

Copy file name to clipboardExpand all lines: test/test_docs.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def test_references_and_objects(self, rw_dir):
481481
@pytest.mark.xfail(
482482
sys.platform == "cygwin",
483483
reason="Cygwin GitPython can't find SHA for submodule",
484-
raises=ValueError
484+
raises=ValueError,
485485
)
486486
def test_submodules(self):
487487
# [1-test_submodules]

‎test/test_index.py

Copy file name to clipboardExpand all lines: test/test_index.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ def test_commit_msg_hook_fail(self, rw_repo):
946946
else:
947947
raise AssertionError("Should have caught a HookExecutionError")
948948

949-
@with_rw_repo('HEAD')
949+
@with_rw_repo("HEAD")
950950
def test_index_add_pathlike(self, rw_repo):
951951
git_dir = Path(rw_repo.git_dir)
952952

‎test/test_quick_doc.py

Copy file name to clipboardExpand all lines: test/test_quick_doc.py
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@ def tearDown(self):
1313

1414
@with_rw_directory
1515
def test_init_repo_object(self, path_to_dir):
16-
1716
# [1-test_init_repo_object]
1817
# $ git init <path/to/dir>
1918

2019
from git import Repo
2120

2221
repo = Repo.init(path_to_dir)
23-
# ![1-test_init_repo_object]
22+
# ![1-test_init_repo_object]
2423

2524
# [2-test_init_repo_object]
2625
repo = Repo(path_to_dir)
2726
# ![2-test_init_repo_object]
2827

2928
@with_rw_directory
3029
def test_cloned_repo_object(self, local_dir):
31-
3230
from git import Repo
3331
import git
32+
3433
# code to clone from url
3534
# [1-test_cloned_repo_object]
3635
# $ git clone <url> <local_dir>
@@ -44,9 +43,9 @@ def test_cloned_repo_object(self, local_dir):
4443
# [2-test_cloned_repo_object]
4544
# We must make a change to a file so that we can add the update to git
4645

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")
5049
# ![2-test_cloned_repo_object]
5150

5251
# [3-test_cloned_repo_object]
@@ -82,7 +81,7 @@ def test_cloned_repo_object(self, local_dir):
8281

8382
# Untracked files - create new file
8483
# [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
8685
f.close()
8786
# ![7-test_cloned_repo_object]
8887

@@ -95,8 +94,8 @@ def test_cloned_repo_object(self, local_dir):
9594
# [9-test_cloned_repo_object]
9695
# Let's modify one of our tracked files
9796

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
10099
# ![9-test_cloned_repo_object]
101100

102101
# [10-test_cloned_repo_object]
@@ -126,7 +125,7 @@ def test_cloned_repo_object(self, local_dir):
126125
# ![11.1-test_cloned_repo_object]
127126
# [11.2-test_cloned_repo_object]
128127
# lets add untracked.txt
129-
repo.index.add(['untracked.txt'])
128+
repo.index.add(["untracked.txt"])
130129
diffs = repo.index.diff(repo.head.commit)
131130
for d in diffs:
132131
print(d.a_path)
@@ -146,9 +145,7 @@ def test_cloned_repo_object(self, local_dir):
146145
# dir1/file2.txt
147146
# ![11.3-test_cloned_repo_object]
148147

149-
150-
151-
'''Trees and Blobs'''
148+
"""Trees and Blobs"""
152149

153150
# Latest commit tree
154151
# [12-test_cloned_repo_object]
@@ -195,7 +192,7 @@ def print_files_from_git(root, level=0):
195192

196193
# Printing text files
197194
# [17-test_cloned_repo_object]
198-
print_file = 'dir1/file2.txt'
195+
print_file = "dir1/file2.txt"
199196
tree[print_file] # the head commit tree
200197

201198
# Output <git.Blob "SHA1-HEX-HASH">
@@ -221,4 +218,4 @@ def print_files_from_git(root, level=0):
221218

222219
# Output
223220
# file 2 version 1
224-
# ![18.1-test_cloned_repo_object]
221+
# ![18.1-test_cloned_repo_object]

‎test/test_repo.py

Copy file name to clipboardExpand all lines: test/test_repo.py
+18-12Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def test_clone_from_with_path_contains_unicode(self):
251251
self.fail("Raised UnicodeEncodeError")
252252

253253
@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+
)
255257
def test_leaking_password_in_clone_logs(self, rw_dir):
256258
password = "fakepassword1234"
257259
try:
@@ -391,7 +393,9 @@ def test_clone_from_unsafe_options_allowed(self, rw_repo):
391393
for i, unsafe_option in enumerate(unsafe_options):
392394
destination = tmp_dir / str(i)
393395
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+
)
395399
assert destination.exists()
396400

397401
@with_rw_repo("HEAD")
@@ -755,8 +759,8 @@ def test_blame_complex_revision(self, git):
755759
@mock.patch.object(Git, "_call_process")
756760
def test_blame_accepts_rev_opts(self, git):
757761
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}
760764
git.assert_called_once_with(*expected_args, **boilerplate_kwargs)
761765

762766
@skipIf(
@@ -1115,7 +1119,7 @@ def test_repo_odbtype(self):
11151119
@pytest.mark.xfail(
11161120
sys.platform == "cygwin",
11171121
reason="Cygwin GitPython can't find submodule SHA",
1118-
raises=ValueError
1122+
raises=ValueError,
11191123
)
11201124
def test_submodules(self):
11211125
self.assertEqual(len(self.rorepo.submodules), 1) # non-recursive
@@ -1415,14 +1419,16 @@ def test_ignored_items_reported(self):
14151419

14161420
gi = tmp_dir / "repo" / ".gitignore"
14171421

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")
14211425

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"]
14261432

14271433
def test_ignored_raises_error_w_symlink(self):
14281434
with tempfile.TemporaryDirectory() as tdir:

‎test/test_submodule.py

Copy file name to clipboardExpand all lines: test/test_submodule.py
+24-11Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ def _patch_git_config(name, value):
3939

4040
# This is recomputed each time the context is entered, for compatibility with
4141
# 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+
)
4750

4851
with patcher:
4952
yield
@@ -469,7 +472,7 @@ def test_base_bare(self, rwrepo):
469472
@pytest.mark.xfail(
470473
sys.platform == "cygwin",
471474
reason="Cygwin GitPython can't find submodule SHA",
472-
raises=ValueError
475+
raises=ValueError,
473476
)
474477
@skipIf(
475478
HIDE_WINDOWS_KNOWN_ERRORS,
@@ -914,17 +917,17 @@ def test_ignore_non_submodule_file(self, rwdir):
914917
os.mkdir(smp)
915918

916919
with open(osp.join(smp, "a"), "w", encoding="utf-8") as f:
917-
f.write('test\n')
920+
f.write("test\n")
918921

919922
with open(osp.join(rwdir, ".gitmodules"), "w", encoding="utf-8") as f:
920-
f.write("[submodule \"a\"]\n")
923+
f.write('[submodule "a"]\n')
921924
f.write(" path = module\n")
922925
f.write(" url = https://github.com/chaconinc/DbConnector\n")
923926

924927
parent.git.add(Git.polish_url(osp.join(smp, "a")))
925928
parent.git.add(Git.polish_url(osp.join(rwdir, ".gitmodules")))
926929

927-
parent.git.commit(message='test')
930+
parent.git.commit(message="test")
928931

929932
assert len(parent.submodules) == 0
930933

@@ -1200,7 +1203,12 @@ def test_submodule_add_unsafe_options_allowed(self, rw_repo):
12001203
# The options will be allowed, but the command will fail.
12011204
with self.assertRaises(GitCommandError):
12021205
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,
12041212
)
12051213
assert not tmp_file.exists()
12061214

@@ -1211,7 +1219,12 @@ def test_submodule_add_unsafe_options_allowed(self, rw_repo):
12111219
for unsafe_option in unsafe_options:
12121220
with self.assertRaises(GitCommandError):
12131221
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,
12151228
)
12161229

12171230
@with_rw_repo("HEAD")

‎test/test_util.py

Copy file name to clipboardExpand all lines: test/test_util.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_lock_file(self):
159159
@pytest.mark.xfail(
160160
sys.platform == "cygwin",
161161
reason="Cygwin fails here for some reason, always",
162-
raises=AssertionError
162+
raises=AssertionError,
163163
)
164164
def test_blocking_lock_file(self):
165165
my_file = tempfile.mktemp()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.