Skip to content

Commit 5cf5b60

Browse files
committedFeb 29, 2024·
Revise test suite docstrings and comments
In a more limited way than in the git/ code. Docstring revisions are, in spirit, along the same lines as those in the git package, but much more conservative, because the tests' docstrings are not rendered into Sphinx documentation and there is no current plan to do so (so the tradeoffs are different, with even a tiny decrease in clarity when read in the code being a reason to avoid changes that use Sphinx roles more robustly or that would improve hypothetical rendered documentation), and because the test suite uses docstrings more sparingly and the existing docstrings were mostly already clear and easy to read. This wraps commnts to 88 columns as most comments now are in the git package, except it avoids doing so when doing so would make anything even slightly less clear, and where it would require significant further style or spacing changes for it to remain obvious (even before reading a comment) what the comment applies to, and in most portions of tutorial-generating test case code (where, although clarity would improve when reading the tests, it might sometimes decrease in the generated documentation).
1 parent 608147e commit 5cf5b60

17 files changed

+243
-186
lines changed
 

‎test/lib/helper.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,20 @@ class TestBase(TestCase):
346346
"""Base class providing default functionality to all tests such as:
347347
348348
- Utility functions provided by the TestCase base of the unittest method such as::
349+
349350
self.fail("todo")
350351
self.assertRaises(...)
351352
352353
- Class level repository which is considered read-only as it is shared among
353354
all test cases in your type.
355+
354356
Access it using::
355-
self.rorepo # 'ro' stands for read-only
357+
358+
self.rorepo # 'ro' stands for read-only
356359
357360
The rorepo is in fact your current project's git repo. If you refer to specific
358-
shas for your objects, be sure you choose some that are part of the immutable portion
359-
of the project history (so that tests don't fail for others).
361+
shas for your objects, be sure you choose some that are part of the immutable
362+
portion of the project history (so that tests don't fail for others).
360363
"""
361364

362365
def _small_repo_url(self):
@@ -383,8 +386,8 @@ def tearDownClass(cls):
383386

384387
def _make_file(self, rela_path, data, repo=None):
385388
"""
386-
Create a file at the given path relative to our repository, filled
387-
with the given data.
389+
Create a file at the given path relative to our repository, filled with the
390+
given data.
388391
389392
:return: An absolute path to the created file.
390393
"""

‎test/performance/test_streams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class TestObjDBPerformance(TestBigRepoR):
2525

2626
@with_rw_repo("HEAD", bare=True)
2727
def test_large_data_streaming(self, rwrepo):
28-
# TODO: This part overlaps with the same file in gitdb.test.performance.test_stream.
29-
# It should be shared if possible.
28+
# TODO: This part overlaps with the same file in
29+
# gitdb.test.performance.test_stream. It should be shared if possible.
3030
ldb = LooseObjectDB(osp.join(rwrepo.git_dir, "objects"))
3131

3232
for randomize in range(2):

‎test/test_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def test_add_unicode(self, rw_repo):
135135
# https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897
136136
# Therefore, it must be added using the Python implementation.
137137
rw_repo.index.add([file_path])
138-
# However, when the test winds down, rmtree fails to delete this file, which is recognized
139-
# as ??? only.
138+
# However, when the test winds down, rmtree fails to delete this file, which
139+
# is recognized as ??? only.
140140
else:
141141
# On POSIX, we can just add Unicode files without problems.
142142
rw_repo.git.add(rw_repo.working_dir)

‎test/test_clone.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def test_checkout_in_non_empty_dir(self, rw_dir):
1919
garbage_file = non_empty_dir / "not-empty"
2020
garbage_file.write_text("Garbage!")
2121

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

‎test/test_commit.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
class TestCommitSerialization(TestBase):
2929
def assert_commit_serialization(self, rwrepo, commit_id, print_performance_info=False):
30-
"""Traverse all commits in the history of commit identified by commit_id and check
31-
if the serialization works.
30+
"""Traverse all commits in the history of commit identified by commit_id and
31+
check if the serialization works.
3232
3333
:param print_performance_info: If True, we will show how fast we are.
3434
"""
@@ -317,8 +317,9 @@ def test_count(self):
317317
self.assertEqual(self.rorepo.tag("refs/tags/0.1.5").commit.count(), 143)
318318

319319
def test_list(self):
320-
# 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.
320+
# This doesn't work anymore, as we will either attempt getattr with bytes, or
321+
# compare 20 byte string with actual 20 byte bytes. This usage makes no sense
322+
# anyway.
322323
assert isinstance(
323324
Commit.list_items(self.rorepo, "0.1.5", max_count=5)["5117c9c8a4d3af19a9958677e45cda9269de1541"],
324325
Commit,
@@ -383,8 +384,8 @@ def test_serialization_unicode_support(self):
383384

384385
self.assertEqual(cmt.author.name, ncmt.author.name)
385386
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.
387+
# Actually, it can't be printed in a shell as repr wants to have ascii only it
388+
# appears.
388389
cmt.author.__repr__()
389390

390391
def test_invalid_commit(self):
@@ -498,7 +499,8 @@ def test_trailers(self):
498499
KEY_2 = "Key"
499500
VALUE_2 = "Value with inner spaces"
500501

501-
# Check that the following trailer example is extracted from multiple msg variations.
502+
# Check that the following trailer example is extracted from multiple msg
503+
# 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",

‎test/test_config.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _to_memcache(self, file_path):
4141
return sio
4242

4343
def test_read_write(self):
44-
# writer must create the exact same file as the one read before
44+
# The writer must create the exact same file as the one read before.
4545
for filename in ("git_config", "git_config_global"):
4646
file_obj = self._to_memcache(fixture_path(filename))
4747
with GitConfigParser(file_obj, read_only=False) as w_config:
@@ -56,7 +56,8 @@ def test_read_write(self):
5656
self._to_memcache(fixture_path(filename)).getvalue(),
5757
)
5858

59-
# Creating an additional config writer must fail due to exclusive access.
59+
# Creating an additional config writer must fail due to exclusive
60+
# access.
6061
with self.assertRaises(IOError):
6162
GitConfigParser(file_obj, read_only=False)
6263

@@ -91,8 +92,8 @@ def test_includes_order(self):
9192
r_config.read() # Enforce reading.
9293
# Simple inclusions, again checking them taking precedence.
9394
assert r_config.get_value("sec", "var0") == "value0_included"
94-
# This one should take the git_config_global value since included
95-
# values must be considered as soon as they get them.
95+
# This one should take the git_config_global value since included values
96+
# must be considered as soon as they get them.
9697
assert r_config.get_value("diff", "tool") == "meld"
9798
try:
9899
# FIXME: Split this assertion out somehow and mark it xfail (or fix it).
@@ -109,7 +110,8 @@ def test_lock_reentry(self, rw_dir):
109110
# Entering again locks the file again...
110111
with gcp as cw:
111112
cw.set_value("include", "some_other_value", "b")
112-
# ...so creating an additional config writer must fail due to exclusive access.
113+
# ...so creating an additional config writer must fail due to exclusive
114+
# access.
113115
with self.assertRaises(IOError):
114116
GitConfigParser(fpl, read_only=False)
115117
# but work when the lock is removed

‎test/test_diff.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,18 @@ def test_diff_unsafe_paths(self):
271271
self.assertEqual(res[10].b_rawpath, b"path/\x80-invalid-unicode-path.txt")
272272

273273
# The "Moves"
274-
# NOTE: The path prefixes a/ and b/ here are legit! We're actually
275-
# verifying that it's not "a/a/" that shows up, see the fixture data.
276-
self.assertEqual(res[11].a_path, "a/with spaces") # NOTE: path a/ here legit!
277-
self.assertEqual(res[11].b_path, "b/with some spaces") # NOTE: path b/ here legit!
274+
# NOTE: The path prefixes "a/" and "b/" here are legit! We're actually verifying
275+
# that it's not "a/a/" that shows up; see the fixture data.
276+
self.assertEqual(res[11].a_path, "a/with spaces") # NOTE: path "a/"" legit!
277+
self.assertEqual(res[11].b_path, "b/with some spaces") # NOTE: path "b/"" legit!
278278
self.assertEqual(res[12].a_path, "a/ending in a space ")
279279
self.assertEqual(res[12].b_path, "b/ending with space ")
280280
self.assertEqual(res[13].a_path, 'a/"with-quotes"')
281281
self.assertEqual(res[13].b_path, 'b/"with even more quotes"')
282282

283283
def test_diff_patch_format(self):
284-
# Test all of the 'old' format diffs for completeness - it should at least
285-
# be able to deal with it.
284+
# Test all of the 'old' format diffs for completeness - it should at least be
285+
# able to deal with it.
286286
fixtures = (
287287
"diff_2",
288288
"diff_2f",
@@ -345,8 +345,9 @@ def test_diff_submodule(self):
345345
repo.create_tag("2")
346346

347347
diff = repo.commit("1").diff(repo.commit("2"))[0]
348-
# If diff is unable to find the commit hashes (looks in wrong repo) the *_blob.size
349-
# property will be a string containing exception text, an int indicates success.
348+
# If diff is unable to find the commit hashes (looks in wrong repo) the
349+
# *_blob.size property will be a string containing exception text, an int
350+
# indicates success.
350351
self.assertIsInstance(diff.a_blob.size, int)
351352
self.assertIsInstance(diff.b_blob.size, int)
352353

@@ -392,9 +393,9 @@ def test_diff_interface(self):
392393
# END for each other side
393394
# END for each commit
394395

395-
# Assert that we could always find at least one instance of the members we
396-
# can iterate in the diff index - if not this indicates its not working correctly
397-
# or our test does not span the whole range of possibilities.
396+
# Assert that we could always find at least one instance of the members we can
397+
# iterate in the diff index - if not this indicates its not working correctly or
398+
# our test does not span the whole range of possibilities.
398399
for key, value in assertion_map.items():
399400
self.assertIsNotNone(value, "Did not find diff for %s" % key)
400401
# END for each iteration type

‎test/test_docs.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class Tutorials(TestBase):
1919
def tearDown(self):
2020
gc.collect()
2121

22-
# ACTUALLY skipped by git.util.rmtree (in local onerror function), from the last call to it via
23-
# git.objects.submodule.base.Submodule.remove (at "handle separate bare repository"), line 1062.
22+
# ACTUALLY skipped by git.util.rmtree (in local onerror function), from the last
23+
# call to it via git.objects.submodule.base.Submodule.remove
24+
# (at "handle separate bare repository"), line 1062.
2425
#
2526
# @skipIf(HIDE_WINDOWS_KNOWN_ERRORS,
2627
# "FIXME: helper.wrapper fails with: PermissionError: [WinError 5] Access is denied: "
@@ -31,8 +32,8 @@ def test_init_repo_object(self, rw_dir):
3132
from git import Repo
3233

3334
# rorepo is a Repo instance pointing to the git-python repository.
34-
# For all you know, the first argument to Repo is a path to the repository
35-
# you want to work with.
35+
# For all you know, the first argument to Repo is a path to the repository you
36+
# want to work with.
3637
repo = Repo(self.rorepo.working_tree_dir)
3738
assert not repo.bare
3839
# ![1-test_init_repo_object]
@@ -149,8 +150,8 @@ def update(self, op_code, cur_count, max_count=None, message=""):
149150
assert origin.exists()
150151
for fetch_info in origin.fetch(progress=MyProgressPrinter()):
151152
print("Updated %s to %s" % (fetch_info.ref, fetch_info.commit))
152-
# Create a local branch at the latest fetched master. We specify the name statically, but you have all
153-
# information to do it programmatically as well.
153+
# Create a local branch at the latest fetched master. We specify the name
154+
# statically, but you have all information to do it programmatically as well.
154155
bare_master = bare_repo.create_head("master", origin.refs.master)
155156
bare_repo.head.set_reference(bare_master)
156157
assert not bare_repo.delete_remote(origin).exists()
@@ -188,9 +189,9 @@ def update(self, op_code, cur_count, max_count=None, message=""):
188189
# submodules
189190

190191
# [14-test_init_repo_object]
191-
# Create a new submodule and check it out on the spot, setup to track master branch of `bare_repo`.
192-
# As our GitPython repository has submodules already that point to GitHub, make sure we don't
193-
# interact with them.
192+
# Create a new submodule and check it out on the spot, setup to track master
193+
# branch of `bare_repo`. As our GitPython repository has submodules already that
194+
# point to GitHub, make sure we don't interact with them.
194195
for sm in cloned_repo.submodules:
195196
assert not sm.remove().exists() # after removal, the sm doesn't exist anymore
196197
sm = cloned_repo.create_submodule("mysubrepo", "path/to/subrepo", url=bare_repo.git_dir, branch="master")
@@ -424,8 +425,8 @@ def test_references_and_objects(self, rw_dir):
424425
with origin.config_writer as cw:
425426
cw.set("pushurl", "other_url")
426427

427-
# Please note that in Python 2, writing origin.config_writer.set(...) is totally safe.
428-
# In py3 __del__ calls can be delayed, thus not writing changes in time.
428+
# Please note that in Python 2, writing origin.config_writer.set(...) is totally
429+
# safe. In py3 __del__ calls can be delayed, thus not writing changes in time.
429430
# ![26-test_references_and_objects]
430431

431432
# [27-test_references_and_objects]
@@ -462,7 +463,8 @@ def test_references_and_objects(self, rw_dir):
462463
# ![29-test_references_and_objects]
463464

464465
# [30-test_references_and_objects]
465-
# Check out the branch using git-checkout. It will fail as the working tree appears dirty.
466+
# Check out the branch using git-checkout.
467+
# It will fail as the working tree appears dirty.
466468
self.assertRaises(git.GitCommandError, repo.heads.master.checkout)
467469
repo.heads.past_branch.checkout()
468470
# ![30-test_references_and_objects]

‎test/test_fun.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def _assert_index_entries(self, entries, trees):
3535
# END assert entry matches fully
3636

3737
def test_aggressive_tree_merge(self):
38-
# Head tree with additions, removals and modification compared to its predecessor.
38+
# Head tree with additions, removals and modification compared to its
39+
# predecessor.
3940
odb = self.rorepo.odb
4041
HC = self.rorepo.commit("6c1faef799095f3990e9970bc2cb10aa0221cf9c")
4142
H = HC.tree

‎test/test_git.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,27 @@ def test_it_avoids_upcasing_unrelated_environment_variable_names(self):
253253
if old_name == old_name.upper():
254254
raise RuntimeError("test bug or strange locale: old_name invariant under upcasing")
255255

256-
# Step 1: Set the environment variable in this parent process. Because os.putenv is a thin
257-
# wrapper around a system API, os.environ never sees the variable in this parent
258-
# process, so the name is not upcased even on Windows.
256+
# Step 1
257+
#
258+
# Set the environment variable in this parent process. Because os.putenv is a
259+
# thin wrapper around a system API, os.environ never sees the variable in this
260+
# parent process, so the name is not upcased even on Windows.
259261
os.putenv(old_name, "1")
260262

261-
# Step 2: Create the child process that inherits the environment variable. The child uses
262-
# GitPython, and we are testing that it passes the variable with the exact original
263-
# name to its own child process (the grandchild).
263+
# Step 2
264+
#
265+
# Create the child process that inherits the environment variable. The child
266+
# uses GitPython, and we are testing that it passes the variable with the exact
267+
# original name to its own child process (the grandchild).
264268
cmdline = [
265269
sys.executable,
266270
fixture_path("env_case.py"), # Contains steps 3 and 4.
267271
self.rorepo.working_dir,
268272
old_name,
269273
]
270-
pair_text = subprocess.check_output(cmdline, shell=False, text=True) # Run steps 3 and 4.
274+
275+
# Run steps 3 and 4.
276+
pair_text = subprocess.check_output(cmdline, shell=False, text=True)
271277

272278
new_name = pair_text.split("=")[0]
273279
self.assertEqual(new_name, old_name)
@@ -668,7 +674,7 @@ def test_successful_default_refresh_invalidates_cached_version_info(self):
668674
# as unintended shell expansions can occur, and is deprecated. Instead,
669675
# use a custom command, by setting the GIT_PYTHON_GIT_EXECUTABLE
670676
# environment variable to git.cmd or by passing git.cmd's full path to
671-
# git.refresh. Or wrap the script with a .exe shim.
677+
# git.refresh. Or wrap the script with a .exe shim.)
672678
stack.enter_context(mock.patch.object(Git, "USE_SHELL", True))
673679

674680
new_git = Git()

0 commit comments

Comments
 (0)
Please sign in to comment.