33#
44# This module is part of GitPython and is released under
55# the BSD License: https://opensource.org/license/bsd-3-clause/
6+
67import contextlib
78from functools import wraps
89import gc
@@ -65,9 +66,10 @@ def fixture(name):
6566
6667
6768class StringProcessAdapter (object ):
69+ """Allows strings to be used as process objects returned by subprocess.Popen.
6870
69- """Allows to use strings as Process object as returned by SubProcess.Popen .
70- Its tailored to work with the test system only """
71+ This is tailored to work with the test system only .
72+ """
7173
7274 def __init__ (self , input_string ):
7375 self .stdout = io .BytesIO (input_string )
@@ -86,7 +88,7 @@ def wait(self):
8688
8789def with_rw_directory (func ):
8890 """Create a temporary directory which can be written to, remove it if the
89- test succeeds, but leave it otherwise to aid additional debugging"""
91+ test succeeds, but leave it otherwise to aid additional debugging. """
9092
9193 @wraps (func )
9294 def wrapper (self ):
@@ -106,7 +108,7 @@ def wrapper(self):
106108 raise
107109 finally :
108110 # Need to collect here to be sure all handles have been closed. It appears
109- # a windows -only issue. In fact things should be deleted, as well as
111+ # a Windows -only issue. In fact things should be deleted, as well as
110112 # memory maps closed, once objects go out of scope. For some reason
111113 # though this is not the case here unless we collect explicitly.
112114 gc .collect ()
@@ -117,8 +119,7 @@ def wrapper(self):
117119
118120
119121def with_rw_repo (working_tree_ref , bare = False ):
120- """
121- Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
122+ """Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
122123 out the working tree at the given working_tree_ref.
123124
124125 This repository type is more costly due to the working copy checkout.
@@ -199,7 +200,7 @@ def git_daemon_launched(base_path, ip, port):
199200 base_path = base_path ,
200201 as_process = True ,
201202 )
202- # yes , I know ... fortunately, this is always going to work if sleep time is just large enough
203+ # Yes , I know... fortunately, this is always going to work if sleep time is just large enough.
203204 time .sleep (0.5 * (1 + is_win ))
204205 except Exception as ex :
205206 msg = textwrap .dedent (
@@ -225,33 +226,36 @@ def git_daemon_launched(base_path, ip, port):
225226 log .debug ("Killing git-daemon..." )
226227 gd .proc .kill ()
227228 except Exception as ex :
228- ## Either it has died (and we're here), or it won't die, again here...
229+ # Either it has died (and we're here), or it won't die, again here...
229230 log .debug ("Hidden error while Killing git-daemon: %s" , ex , exc_info = 1 )
230231
231232
232233def with_rw_and_rw_remote_repo (working_tree_ref ):
233- """
234- Same as with_rw_repo, but also provides a writable remote repository from which the
235- rw_repo has been forked as well as a handle for a git-daemon that may be started to
236- run the remote_repo.
237- The remote repository was cloned as bare repository from the ro repo, whereas
238- the rw repo has a working tree and was cloned from the remote repository.
234+ """Same as with_rw_repo, but also provides a writable remote repository from which
235+ the rw_repo has been forked as well as a handle for a git-daemon that may be started
236+ to run the remote_repo.
239237
240- remote_repo has two remotes: origin and daemon_origin. One uses a local url,
241- the other uses a server url. The daemon setup must be done on system level
242- and should be an inetd service that serves tempdir.gettempdir() and all
243- directories in it.
238+ The remote repository was cloned as bare repository from the ro repo, whereas the rw
239+ repo has a working tree and was cloned from the remote repository.
240+
241+ remote_repo has two remotes: origin and daemon_origin. One uses a local url, the
242+ other uses a server url. The daemon setup must be done on system level and should be
243+ an inetd service that serves tempdir.gettempdir() and all directories in it.
244244
245245 The following sketch demonstrates this::
246- rorepo ---<bare clone>---> rw_remote_repo ---<clone>---> rw_repo
246+
247+ rorepo ---<bare clone>---> rw_remote_repo ---<clone>---> rw_repo
247248
248249 The test case needs to support the following signature::
250+
249251 def case(self, rw_repo, rw_daemon_repo)
250252
251253 This setup allows you to test push and pull scenarios and hooks nicely.
252254
253- See working dir info in with_rw_repo
254- :note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
255+ See working dir info in :func:`with_rw_repo`.
256+
257+ :note: We attempt to launch our own invocation of git-daemon, which will be shut
258+ down at the end of the test.
255259 """
256260 from git import Git , Remote # To avoid circular deps.
257261
@@ -264,16 +268,16 @@ def remote_repo_creator(self):
264268 rw_repo_dir = tempfile .mktemp (prefix = "daemon_cloned_repo-%s-" % func .__name__ )
265269
266270 rw_daemon_repo = self .rorepo .clone (rw_daemon_repo_dir , shared = True , bare = True )
267- # recursive alternates info ?
271+ # Recursive alternates info?
268272 rw_repo = rw_daemon_repo .clone (rw_repo_dir , shared = True , bare = False , n = True )
269273 try :
270274 rw_repo .head .commit = working_tree_ref
271275 rw_repo .head .reference .checkout ()
272276
273- # prepare for git-daemon
277+ # Prepare for git-daemon.
274278 rw_daemon_repo .daemon_export = True
275279
276- # this thing is just annoying !
280+ # This thing is just annoying!
277281 with rw_daemon_repo .config_writer () as crw :
278282 section = "daemon"
279283 try :
@@ -340,9 +344,7 @@ def remote_repo_creator(self):
340344
341345
342346class TestBase (TestCase ):
343-
344- """
345- Base Class providing default functionality to all tests such as:
347+ """Base class providing default functionality to all tests such as:
346348
347349 - Utility functions provided by the TestCase base of the unittest method such as::
348350 self.fail("todo")
@@ -355,20 +357,20 @@ class TestBase(TestCase):
355357
356358 The rorepo is in fact your current project's git repo. If you refer to specific
357359 shas for your objects, be sure you choose some that are part of the immutable portion
358- of the project history ( to assure tests don't fail for others ).
360+ of the project history (so that tests don't fail for others).
359361 """
360362
361363 def _small_repo_url (self ):
362- """:return" a path to a small, clonable repository"""
364+ """:return: A path to a small, clonable repository"""
363365 from git .cmd import Git
364366
365367 return Git .polish_url (osp .join (self .rorepo .working_tree_dir , "git/ext/gitdb/gitdb/ext/smmap" ))
366368
367369 @classmethod
368370 def setUpClass (cls ):
369- """
370- Dynamically add a read-only repository to our actual type. This way
371- each test type has its own repository
371+ """Dynamically add a read-only repository to our actual type.
372+
373+ This way, each test type has its own repository.
372374 """
373375 from git import Repo
374376
@@ -383,7 +385,9 @@ def tearDownClass(cls):
383385 def _make_file (self , rela_path , data , repo = None ):
384386 """
385387 Create a file at the given path relative to our repository, filled
386- with the given data. Returns absolute path to created file.
388+ with the given data.
389+
390+ :return: An absolute path to the created file.
387391 """
388392 repo = repo or self .rorepo
389393 abs_path = osp .join (repo .working_tree_dir , rela_path )
0 commit comments