Skip to content

Revise comments, docstrings, some messages, and a bit of code #1725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7dd2095
Fix docstrings that intend '\' literally
EliahKagan Oct 10, 2023
ffcbf07
Put all regex patterns in r-strings
EliahKagan Oct 10, 2023
2c94b6a
Remove r prefix from strings that need not be raw
EliahKagan Oct 10, 2023
35fd65b
Fix _index_from_*_format docstrings (proc reading)
EliahKagan Oct 15, 2023
5af7446
Fix case in IndexObject.abspath exception message
EliahKagan Oct 16, 2023
692e59e
Remove Commit._deserialize doc for param_from_rev_list
EliahKagan Oct 16, 2023
ab46192
Add missing space in Submodule.update debug message
EliahKagan Oct 17, 2023
1114828
Remove obsolete comment in Submodule.module
EliahKagan Oct 18, 2023
f95d4fd
Clarify "master repository" in RootModule docs
EliahKagan Oct 18, 2023
9fea488
Change spelling from "commit'ish" to "commit-ish"
EliahKagan Oct 18, 2023
4536b63
Update git-source citation in Reference.set_object
EliahKagan Oct 18, 2023
59d208c
Fix message in SymbolicReference.from_path
EliahKagan Oct 18, 2023
add46d9
Use "is" to compare __class__
EliahKagan Oct 18, 2023
cd16a35
Revise docstrings and comments for clarity and formatting
EliahKagan Oct 18, 2023
e8343e2
Firm up comment about is_win in util.is_cygwin_git
EliahKagan Oct 18, 2023
f78587f
Remove explicit inheritance from object
EliahKagan Oct 18, 2023
0327f8f
Make all one-element __slots__ be tuples
EliahKagan Oct 18, 2023
d4a87c1
Revise comments in tests used to generate tutorials
EliahKagan Oct 22, 2023
11fce8a
Revise docstrings/comments in most other test modules
EliahKagan Oct 20, 2023
cf9243a
Add a module docstring to tstrunner.py
EliahKagan Oct 23, 2023
b5c3ca4
Slightly improve readability of installation-test strings
EliahKagan Oct 23, 2023
f444470
More wording improvements (in git module)
EliahKagan Oct 23, 2023
db317f1
Change :returns: to :return:
EliahKagan Oct 23, 2023
720e4bb
Fix TestBigRepoR.setUp info message
EliahKagan Oct 23, 2023
faa19ac
Remove outdated git_daemon_launched Windows info
EliahKagan Oct 24, 2023
bffc537
Revise docstrings/comments in test helpers
EliahKagan Oct 24, 2023
30f49d9
Revise docstrings/comments in performance tests
EliahKagan Oct 24, 2023
8d3efc5
Remove explicit inheritance from object in test suite
EliahKagan Oct 24, 2023
a5fc1d8
Improve consistency of "END" comments
EliahKagan Oct 24, 2023
c2eb6b5
Add missing comment revisions in git/objects/submodule/base.py
EliahKagan Oct 24, 2023
ddb4417
Improve consistency of "END" comments in test suite
EliahKagan Oct 24, 2023
1d3f275
Avoid making "END" notation more verbose
EliahKagan Oct 30, 2023
81dad7e
Add missing comment revisions in git/index/base.py
EliahKagan Oct 30, 2023
a040edb
Shorten some docstring references with tilde notation
EliahKagan Oct 30, 2023
af1b5d4
Fix commented *.py names at the top of modules
EliahKagan Oct 30, 2023
b970d42
Remove encoding declarations
EliahKagan Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revise docstrings/comments in test helpers
  • Loading branch information
EliahKagan committed Oct 24, 2023
commit bffc537d17a47c354d5fd36338ff7318a08995c2
2 changes: 1 addition & 1 deletion test/fixtures/env_case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names.
"""Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names."""

import subprocess
import sys
Expand Down
70 changes: 37 additions & 33 deletions test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# This module is part of GitPython and is released under
# the BSD License: https://opensource.org/license/bsd-3-clause/

import contextlib
from functools import wraps
import gc
Expand Down Expand Up @@ -65,9 +66,10 @@ def fixture(name):


class StringProcessAdapter(object):
"""Allows strings to be used as process objects returned by subprocess.Popen.

"""Allows to use strings as Process object as returned by SubProcess.Popen.
Its tailored to work with the test system only"""
This is tailored to work with the test system only.
"""

def __init__(self, input_string):
self.stdout = io.BytesIO(input_string)
Expand All @@ -86,7 +88,7 @@ def wait(self):

def with_rw_directory(func):
"""Create a temporary directory which can be written to, remove it if the
test succeeds, but leave it otherwise to aid additional debugging"""
test succeeds, but leave it otherwise to aid additional debugging."""

@wraps(func)
def wrapper(self):
Expand All @@ -106,7 +108,7 @@ def wrapper(self):
raise
finally:
# Need to collect here to be sure all handles have been closed. It appears
# a windows-only issue. In fact things should be deleted, as well as
# a Windows-only issue. In fact things should be deleted, as well as
# memory maps closed, once objects go out of scope. For some reason
# though this is not the case here unless we collect explicitly.
gc.collect()
Expand All @@ -117,8 +119,7 @@ def wrapper(self):


def with_rw_repo(working_tree_ref, bare=False):
"""
Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
"""Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
out the working tree at the given working_tree_ref.

This repository type is more costly due to the working copy checkout.
Expand Down Expand Up @@ -199,7 +200,7 @@ def git_daemon_launched(base_path, ip, port):
base_path=base_path,
as_process=True,
)
# yes, I know ... fortunately, this is always going to work if sleep time is just large enough
# Yes, I know... fortunately, this is always going to work if sleep time is just large enough.
time.sleep(0.5 * (1 + is_win))
except Exception as ex:
msg = textwrap.dedent(
Expand All @@ -225,33 +226,36 @@ def git_daemon_launched(base_path, ip, port):
log.debug("Killing git-daemon...")
gd.proc.kill()
except Exception as ex:
## Either it has died (and we're here), or it won't die, again here...
# Either it has died (and we're here), or it won't die, again here...
log.debug("Hidden error while Killing git-daemon: %s", ex, exc_info=1)


def with_rw_and_rw_remote_repo(working_tree_ref):
"""
Same as with_rw_repo, but also provides a writable remote repository from which the
rw_repo has been forked as well as a handle for a git-daemon that may be started to
run the remote_repo.
The remote repository was cloned as bare repository from the ro repo, whereas
the rw repo has a working tree and was cloned from the remote repository.
"""Same as with_rw_repo, but also provides a writable remote repository from which
the rw_repo has been forked as well as a handle for a git-daemon that may be started
to run the remote_repo.

remote_repo has two remotes: origin and daemon_origin. One uses a local url,
the other uses a server url. The daemon setup must be done on system level
and should be an inetd service that serves tempdir.gettempdir() and all
directories in it.
The remote repository was cloned as bare repository from the ro repo, whereas the rw
repo has a working tree and was cloned from the remote repository.

remote_repo has two remotes: origin and daemon_origin. One uses a local url, the
other uses a server url. The daemon setup must be done on system level and should be
an inetd service that serves tempdir.gettempdir() and all directories in it.

The following sketch demonstrates this::
rorepo ---<bare clone>---> rw_remote_repo ---<clone>---> rw_repo

rorepo ---<bare clone>---> rw_remote_repo ---<clone>---> rw_repo

The test case needs to support the following signature::

def case(self, rw_repo, rw_daemon_repo)

This setup allows you to test push and pull scenarios and hooks nicely.

See working dir info in with_rw_repo
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
See working dir info in :func:`with_rw_repo`.

:note: We attempt to launch our own invocation of git-daemon, which will be shut
down at the end of the test.
"""
from git import Git, Remote # To avoid circular deps.

Expand All @@ -264,16 +268,16 @@ def remote_repo_creator(self):
rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" % func.__name__)

rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir, shared=True, bare=True)
# recursive alternates info ?
# Recursive alternates info?
rw_repo = rw_daemon_repo.clone(rw_repo_dir, shared=True, bare=False, n=True)
try:
rw_repo.head.commit = working_tree_ref
rw_repo.head.reference.checkout()

# prepare for git-daemon
# Prepare for git-daemon.
rw_daemon_repo.daemon_export = True

# this thing is just annoying !
# This thing is just annoying!
with rw_daemon_repo.config_writer() as crw:
section = "daemon"
try:
Expand Down Expand Up @@ -340,9 +344,7 @@ def remote_repo_creator(self):


class TestBase(TestCase):

"""
Base Class providing default functionality to all tests such as:
"""Base class providing default functionality to all tests such as:

- Utility functions provided by the TestCase base of the unittest method such as::
self.fail("todo")
Expand All @@ -355,20 +357,20 @@ class TestBase(TestCase):

The rorepo is in fact your current project's git repo. If you refer to specific
shas for your objects, be sure you choose some that are part of the immutable portion
of the project history ( to assure tests don't fail for others ).
of the project history (so that tests don't fail for others).
"""

def _small_repo_url(self):
""":return" a path to a small, clonable repository"""
""":return: A path to a small, clonable repository"""
from git.cmd import Git

return Git.polish_url(osp.join(self.rorepo.working_tree_dir, "git/ext/gitdb/gitdb/ext/smmap"))

@classmethod
def setUpClass(cls):
"""
Dynamically add a read-only repository to our actual type. This way
each test type has its own repository
"""Dynamically add a read-only repository to our actual type.

This way, each test type has its own repository.
"""
from git import Repo

Expand All @@ -383,7 +385,9 @@ def tearDownClass(cls):
def _make_file(self, rela_path, data, repo=None):
"""
Create a file at the given path relative to our repository, filled
with the given data. Returns absolute path to created file.
with the given data.

:return: An absolute path to the created file.
"""
repo = repo or self.rorepo
abs_path = osp.join(repo.working_tree_dir, rela_path)
Expand Down
23 changes: 9 additions & 14 deletions test/performance/lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains library functions"""
"""Support library for tests."""

import logging
import os
import tempfile
Expand All @@ -20,22 +21,16 @@


class TestBigRepoR(TestBase):

"""TestCase providing access to readonly 'big' repositories using the following
member variables:

* gitrorepo

* Read-Only git repository - actually the repo of git itself

* puregitrorepo
* gitrorepo:
Read-Only git repository - actually (by default) the repo of GitPython itself.

* As gitrepo, but uses pure python implementation
* puregitrorepo:
Like gitrorepo, but uses a pure Python implementation for its object database.
"""

# { Invariants
# } END invariants

def setUp(self):
try:
super(TestBigRepoR, self).setUp()
Expand All @@ -62,10 +57,10 @@ def tearDown(self):


class TestBigRepoRW(TestBigRepoR):
"""Like :class:`TestBigRepoR`, but provides a big repository that we can write to.

"""As above, but provides a big repository that we can write to.

Provides ``self.gitrwrepo`` and ``self.puregitrwrepo``"""
Provides ``self.gitrwrepo`` and ``self.puregitrwrepo``.
"""

def setUp(self):
self.gitrwrepo = None
Expand Down