Skip to content

Commit d7c13cb

Browse files
committed
Revise docstrings/comments in most other test modules
Besides test modules where there were no such changes to be made, this also does not touch test_util.py, becuase although it has a few comments that might be improved, it may make more sense to do that together with some further refactoring changes.
1 parent d4a87c1 commit d7c13cb

17 files changed

+719
-712
lines changed

Diff for: test/test_actor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_from_string_should_separate_name_and_email(self):
1414
self.assertEqual("Michael Trier", a.name)
1515
self.assertEqual("[email protected]", a.email)
1616

17-
# base type capabilities
17+
# Base type capabilities
1818
assert a == a
1919
assert not (a != a)
2020
m = set()

Diff for: test/test_base.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: https://opensource.org/license/bsd-3-clause/
7+
78
import os
89
import sys
910
import tempfile
@@ -34,7 +35,7 @@ def tearDown(self):
3435
)
3536

3637
def test_base_object(self):
37-
# test interface of base object classes
38+
# Test interface of base object classes.
3839
types = (Blob, Tree, Commit, TagObject)
3940
self.assertEqual(len(types), len(self.type_tuples))
4041

@@ -61,12 +62,12 @@ def test_base_object(self):
6162

6263
if isinstance(item, base.IndexObject):
6364
num_index_objs += 1
64-
if hasattr(item, "path"): # never runs here
65-
assert not item.path.startswith("/") # must be relative
65+
if hasattr(item, "path"): # Never runs here.
66+
assert not item.path.startswith("/") # Must be relative.
6667
assert isinstance(item.mode, int)
6768
# END index object check
6869

69-
# read from stream
70+
# Read from stream.
7071
data_stream = item.data_stream
7172
data = data_stream.read()
7273
assert data
@@ -79,7 +80,7 @@ def test_base_object(self):
7980
os.remove(tmpfilename)
8081
# END for each object type to create
8182

82-
# each has a unique sha
83+
# Each has a unique sha.
8384
self.assertEqual(len(s), num_objs)
8485
self.assertEqual(len(s | s), num_objs)
8586
self.assertEqual(num_index_objs, 2)
@@ -92,7 +93,7 @@ def test_get_object_type_by_name(self):
9293
self.assertRaises(ValueError, get_object_type_by_name, b"doesntexist")
9394

9495
def test_object_resolution(self):
95-
# objects must be resolved to shas so they compare equal
96+
# Objects must be resolved to shas so they compare equal.
9697
self.assertEqual(self.rorepo.head.reference.object, self.rorepo.active_branch.object)
9798

9899
@with_rw_repo("HEAD", bare=True)
@@ -122,7 +123,7 @@ def test_add_unicode(self, rw_repo):
122123

123124
file_path = osp.join(rw_repo.working_dir, filename)
124125

125-
# verify first that we could encode file name in this environment
126+
# Verify first that we could encode file name in this environment.
126127
try:
127128
file_path.encode(sys.getfilesystemencoding())
128129
except UnicodeEncodeError as e:
@@ -132,14 +133,14 @@ def test_add_unicode(self, rw_repo):
132133
fp.write(b"something")
133134

134135
if is_win:
135-
# on windows, there is no way this works, see images on
136+
# On Windows, there is no way this works, see images on:
136137
# https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897
137-
# Therefore, it must be added using the python implementation
138+
# Therefore, it must be added using the Python implementation.
138139
rw_repo.index.add([file_path])
139140
# However, when the test winds down, rmtree fails to delete this file, which is recognized
140141
# as ??? only.
141142
else:
142-
# on posix, we can just add unicode files without problems
143+
# On POSIX, we can just add Unicode files without problems.
143144
rw_repo.git.add(rw_repo.working_dir)
144145
# end
145146
rw_repo.index.commit("message")

Diff for: test/test_blob_filter.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test the blob filter."""
2+
23
from pathlib import Path
34
from typing import Sequence, Tuple
45
from unittest.mock import MagicMock

Diff for: test/test_clone.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_checkout_in_non_empty_dir(self, rw_dir):
2121
garbage_file.write_text("Garbage!")
2222

2323
# Verify that cloning into the non-empty dir fails while complaining about
24-
# the target directory not being empty/non-existent
24+
# the target directory not being empty/non-existent.
2525
try:
2626
self.rorepo.clone(non_empty_dir)
2727
except git.GitCommandError as exc:

Diff for: test/test_commit.py

+44-42
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: https://opensource.org/license/bsd-3-clause/
7+
78
import copy
89
from datetime import datetime
910
from io import BytesIO
@@ -28,18 +29,20 @@
2829

2930
class TestCommitSerialization(TestBase):
3031
def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=False):
31-
"""traverse all commits in the history of commit identified by commit_id and check
32+
"""Traverse all commits in the history of commit identified by commit_id and check
3233
if the serialization works.
33-
:param print_performance_info: if True, we will show how fast we are"""
34-
ns = 0 # num serializations
35-
nds = 0 # num deserializations
34+
35+
:param print_performance_info: If True, we will show how fast we are.
36+
"""
37+
ns = 0 # Number of serializations.
38+
nds = 0 # Number of deserializations.
3639

3740
st = time.time()
3841
for cm in rwrepo.commit(commit_id).traverse():
3942
nds += 1
4043

41-
# assert that we deserialize commits correctly, hence we get the same
42-
# sha on serialization
44+
# Assert that we deserialize commits correctly, hence we get the same
45+
# sha on serialization.
4346
stream = BytesIO()
4447
cm._serialize(stream)
4548
ns += 1
@@ -71,13 +74,13 @@ def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=
7174
streamlen = stream.tell()
7275
stream.seek(0)
7376

74-
# reuse istream
77+
# Reuse istream.
7578
istream.size = streamlen
7679
istream.stream = stream
7780
istream.binsha = None
7881
nc.binsha = rwrepo.odb.store(istream).binsha
7982

80-
# if it worked, we have exactly the same contents !
83+
# If it worked, we have exactly the same contents!
8184
self.assertEqual(nc.hexsha, cm.hexsha)
8285
# END check commits
8386
elapsed = time.time() - st
@@ -94,7 +97,7 @@ def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=
9497
class TestCommit(TestCommitSerialization):
9598
def test_bake(self):
9699
commit = self.rorepo.commit("2454ae89983a4496a445ce347d7a41c0bb0ea7ae")
97-
# commits have no dict
100+
# Commits have no dict.
98101
self.assertRaises(AttributeError, setattr, commit, "someattr", 1)
99102
commit.author # bake
100103

@@ -148,7 +151,7 @@ def check_entries(d):
148151
check_entries(d)
149152
# END for each stated file
150153

151-
# assure data is parsed properly
154+
# Check that data is parsed properly.
152155
michael = Actor._from_string("Michael Trier <[email protected]>")
153156
self.assertEqual(commit.author, michael)
154157
self.assertEqual(commit.committer, michael)
@@ -162,9 +165,9 @@ def test_renames(self):
162165
commit = self.rorepo.commit("185d847ec7647fd2642a82d9205fb3d07ea71715")
163166
files = commit.stats.files
164167

165-
# when a file is renamed, the output of git diff is like "dir/{old => new}"
166-
# unless we disable rename with --no-renames, which produces two lines
167-
# one with the old path deletes and another with the new added
168+
# When a file is renamed, the output of git diff is like "dir/{old => new}"
169+
# unless we disable rename with --no-renames, which produces two lines,
170+
# one with the old path deletes and another with the new added.
168171
self.assertEqual(len(files), 2)
169172

170173
def check_entries(path, changes):
@@ -190,7 +193,7 @@ def check_entries(path, changes):
190193
# END for each stated file
191194

192195
def test_unicode_actor(self):
193-
# assure we can parse unicode actors correctly
196+
# Check that we can parse Unicode actors correctly.
194197
name = "Üäöß ÄußÉ"
195198
self.assertEqual(len(name), 9)
196199
special = Actor._from_string("%s <[email protected]>" % name)
@@ -205,7 +208,7 @@ def test_traversal(self):
205208
p00 = p0.parents[0]
206209
p10 = p1.parents[0]
207210

208-
# basic branch first, depth first
211+
# Basic branch first, depth first.
209212
dfirst = start.traverse(branch_first=False)
210213
bfirst = start.traverse(branch_first=True)
211214
self.assertEqual(next(dfirst), p0)
@@ -216,7 +219,7 @@ def test_traversal(self):
216219
self.assertEqual(next(bfirst), p00)
217220
self.assertEqual(next(bfirst), p10)
218221

219-
# at some point, both iterations should stop
222+
# At some point, both iterations should stop.
220223
self.assertEqual(list(bfirst)[-1], first)
221224

222225
stoptraverse = self.rorepo.commit("254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d").traverse(
@@ -235,40 +238,39 @@ def test_traversal(self):
235238
stoptraverse = self.rorepo.commit("254d04aa3180eb8b8daf7b7ff25f010cd69b4e7d").traverse(as_edge=True)
236239
self.assertEqual(len(next(stoptraverse)), 2)
237240

238-
# ignore self
241+
# Ignore self
239242
self.assertEqual(next(start.traverse(ignore_self=False)), start)
240243

241-
# depth
244+
# Depth
242245
self.assertEqual(len(list(start.traverse(ignore_self=False, depth=0))), 1)
243246

244-
# prune
247+
# Prune
245248
self.assertEqual(next(start.traverse(branch_first=1, prune=lambda i, d: i == p0)), p1)
246249

247-
# predicate
250+
# Predicate
248251
self.assertEqual(next(start.traverse(branch_first=1, predicate=lambda i, d: i == p1)), p1)
249252

250-
# traversal should stop when the beginning is reached
253+
# Traversal should stop when the beginning is reached.
251254
self.assertRaises(StopIteration, next, first.traverse())
252255

253-
# parents of the first commit should be empty ( as the only parent has a null
254-
# sha )
256+
# Parents of the first commit should be empty (as the only parent has a null sha)
255257
self.assertEqual(len(first.parents), 0)
256258

257259
def test_iteration(self):
258-
# we can iterate commits
260+
# We can iterate commits.
259261
all_commits = Commit.list_items(self.rorepo, self.rorepo.head)
260262
assert all_commits
261263
self.assertEqual(all_commits, list(self.rorepo.iter_commits()))
262264

263-
# this includes merge commits
265+
# This includes merge commits.
264266
mcomit = self.rorepo.commit("d884adc80c80300b4cc05321494713904ef1df2d")
265267
assert mcomit in all_commits
266268

267-
# we can limit the result to paths
269+
# We can limit the result to paths.
268270
ltd_commits = list(self.rorepo.iter_commits(paths="CHANGES"))
269271
assert ltd_commits and len(ltd_commits) < len(all_commits)
270272

271-
# show commits of multiple paths, resulting in a union of commits
273+
# Show commits of multiple paths, resulting in a union of commits.
272274
less_ltd_commits = list(Commit.iter_items(self.rorepo, "master", paths=("CHANGES", "AUTHORS")))
273275
assert len(ltd_commits) < len(less_ltd_commits)
274276

@@ -280,7 +282,7 @@ def __init__(self, *args, **kwargs):
280282
assert type(child_commits[0]) is Child
281283

282284
def test_iter_items(self):
283-
# pretty not allowed
285+
# pretty not allowed.
284286
self.assertRaises(ValueError, Commit.iter_items, self.rorepo, "master", pretty="raw")
285287

286288
def test_rev_list_bisect_all(self):
@@ -311,14 +313,14 @@ def test_ambiguous_arg_iteration(self, rw_dir):
311313
touch(path)
312314
rw_repo.index.add([path])
313315
rw_repo.index.commit("initial commit")
314-
list(rw_repo.iter_commits(rw_repo.head.ref)) # should fail unless bug is fixed
316+
list(rw_repo.iter_commits(rw_repo.head.ref)) # Should fail unless bug is fixed.
315317

316318
def test_count(self):
317319
self.assertEqual(self.rorepo.tag("refs/tags/0.1.5").commit.count(), 143)
318320

319321
def test_list(self):
320322
# This doesn't work anymore, as we will either attempt getattr with bytes, or compare 20 byte string
321-
# with actual 20 byte bytes. This usage makes no sense anyway
323+
# with actual 20 byte bytes. This usage makes no sense anyway.
322324
assert isinstance(
323325
Commit.list_items(self.rorepo, "0.1.5", max_count=5)["5117c9c8a4d3af19a9958677e45cda9269de1541"],
324326
Commit,
@@ -340,7 +342,7 @@ def test_equality(self):
340342
self.assertNotEqual(commit2, commit3)
341343

342344
def test_iter_parents(self):
343-
# should return all but ourselves, even if skip is defined
345+
# Should return all but ourselves, even if skip is defined.
344346
c = self.rorepo.commit("0.1.5")
345347
for skip in (0, 1):
346348
piter = c.iter_parents(skip=skip)
@@ -355,17 +357,17 @@ def test_name_rev(self):
355357

356358
@with_rw_repo("HEAD", bare=True)
357359
def test_serialization(self, rwrepo):
358-
# create all commits of our repo
360+
# Create all commits of our repo.
359361
self.assert_commit_serialization(rwrepo, "0.1.6")
360362

361363
def test_serialization_unicode_support(self):
362364
self.assertEqual(Commit.default_encoding.lower(), "utf-8")
363365

364-
# create a commit with unicode in the message, and the author's name
365-
# Verify its serialization and deserialization
366+
# Create a commit with Unicode in the message, and the author's name.
367+
# Verify its serialization and deserialization.
366368
cmt = self.rorepo.commit("0.1.6")
367-
assert isinstance(cmt.message, str) # it automatically decodes it as such
368-
assert isinstance(cmt.author.name, str) # same here
369+
assert isinstance(cmt.message, str) # It automatically decodes it as such.
370+
assert isinstance(cmt.author.name, str) # Same here.
369371

370372
cmt.message = "üäêèß"
371373
self.assertEqual(len(cmt.message), 5)
@@ -383,8 +385,8 @@ def test_serialization_unicode_support(self):
383385

384386
self.assertEqual(cmt.author.name, ncmt.author.name)
385387
self.assertEqual(cmt.message, ncmt.message)
386-
# actually, it can't be printed in a shell as repr wants to have ascii only
387-
# it appears
388+
# Actually, it can't be printed in a shell as repr wants to have ascii only
389+
# it appears.
388390
cmt.author.__repr__()
389391

390392
def test_invalid_commit(self):
@@ -498,14 +500,14 @@ def test_trailers(self):
498500
KEY_2 = "Key"
499501
VALUE_2 = "Value with inner spaces"
500502

501-
# Check the following trailer example is extracted from multiple msg variations
503+
# Check that the following trailer example is extracted from multiple msg variations.
502504
TRAILER = f"{KEY_1}: {VALUE_1_1}\n{KEY_2}: {VALUE_2}\n{KEY_1}: {VALUE_1_2}"
503505
msgs = [
504506
f"Subject\n\n{TRAILER}\n",
505507
f"Subject\n \nSome body of a function\n \n{TRAILER}\n",
506508
f"Subject\n \nSome body of a function\n\nnon-key: non-value\n\n{TRAILER}\n",
507509
(
508-
# check when trailer has inconsistent whitespace
510+
# Check when trailer has inconsistent whitespace.
509511
f"Subject\n \nSome multiline\n body of a function\n\nnon-key: non-value\n\n"
510512
f"{KEY_1}:{VALUE_1_1}\n{KEY_2} : {VALUE_2}\n{KEY_1}: {VALUE_1_2}\n"
511513
),
@@ -523,7 +525,7 @@ def test_trailers(self):
523525
KEY_2: [VALUE_2],
524526
}
525527

526-
# check that trailer stays empty for multiple msg combinations
528+
# Check that the trailer stays empty for multiple msg combinations.
527529
msgs = [
528530
"Subject\n",
529531
"Subject\n\nBody with some\nText\n",
@@ -539,7 +541,7 @@ def test_trailers(self):
539541
assert commit.trailers_list == []
540542
assert commit.trailers_dict == {}
541543

542-
# check that only the last key value paragraph is evaluated
544+
# Check that only the last key value paragraph is evaluated.
543545
commit = copy.copy(self.rorepo.commit("master"))
544546
commit.message = f"Subject\n\nMultiline\nBody\n\n{KEY_1}: {VALUE_1_1}\n\n{KEY_2}: {VALUE_2}\n"
545547
assert commit.trailers_list == [(KEY_2, VALUE_2)]

0 commit comments

Comments
 (0)