| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent faa19ac commit bffc537
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - # Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names. | ||
| 1 | + """Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names.""" | ||
| 2 | 2 | ||
| 3 | 3 | import subprocess | |
| 4 | 4 | import sys | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | # | |
| 4 | 4 | # This module is part of GitPython and is released under | |
| 5 | 5 | # the BSD License: https://opensource.org/license/bsd-3-clause/ | |
| 6 | + | ||
| 6 | 7 | import contextlib | |
| 7 | 8 | from functools import wraps | |
| 8 | 9 | import gc | |
@@ -65,9 +66,10 @@ def fixture(name): | |||
| 65 | 66 | ||
| 66 | 67 | ||
| 67 | 68 | class StringProcessAdapter(object): | |
| 69 | + """Allows strings to be used as process objects returned by subprocess.Popen. | ||
| 68 | 70 | ||
| 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 | + """ | ||
| 71 | 73 | ||
| 72 | 74 | def __init__(self, input_string): | |
| 73 | 75 | self.stdout = io.BytesIO(input_string) | |
@@ -86,7 +88,7 @@ def wait(self): | |||
| 86 | 88 | ||
| 87 | 89 | def with_rw_directory(func): | |
| 88 | 90 | """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.""" | ||
| 90 | 92 | ||
| 91 | 93 | @wraps(func) | |
| 92 | 94 | def wrapper(self): | |
@@ -106,7 +108,7 @@ def wrapper(self): | |||
| 106 | 108 | raise | |
| 107 | 109 | finally: | |
| 108 | 110 | # 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 | ||
| 110 | 112 | # memory maps closed, once objects go out of scope. For some reason | |
| 111 | 113 | # though this is not the case here unless we collect explicitly. | |
| 112 | 114 | gc.collect() | |
@@ -117,8 +119,7 @@ def wrapper(self): | |||
| 117 | 119 | ||
| 118 | 120 | ||
| 119 | 121 | def 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 | ||
| 122 | 123 | out the working tree at the given working_tree_ref. | |
| 123 | 124 | ||
| 124 | 125 | This repository type is more costly due to the working copy checkout. | |
@@ -199,7 +200,7 @@ def git_daemon_launched(base_path, ip, port): | |||
| 199 | 200 | base_path=base_path, | |
| 200 | 201 | as_process=True, | |
| 201 | 202 | ) | |
| 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. | ||
| 203 | 204 | time.sleep(0.5 * (1 + is_win)) | |
| 204 | 205 | except Exception as ex: | |
| 205 | 206 | msg = textwrap.dedent( | |
@@ -225,33 +226,36 @@ def git_daemon_launched(base_path, ip, port): | |||
| 225 | 226 | log.debug("Killing git-daemon...") | |
| 226 | 227 | gd.proc.kill() | |
| 227 | 228 | 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... | ||
| 229 | 230 | log.debug("Hidden error while Killing git-daemon: %s", ex, exc_info=1) | |
| 230 | 231 | ||
| 231 | 232 | ||
| 232 | 233 | def 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. | ||
| 239 | 237 | ||
| 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. | ||
| 244 | 244 | ||
| 245 | 245 | 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 | ||
| 247 | 248 | ||
| 248 | 249 | The test case needs to support the following signature:: | |
| 250 | + | ||
| 249 | 251 | def case(self, rw_repo, rw_daemon_repo) | |
| 250 | 252 | ||
| 251 | 253 | This setup allows you to test push and pull scenarios and hooks nicely. | |
| 252 | 254 | ||
| 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. | ||
| 255 | 259 | """ | |
| 256 | 260 | from git import Git, Remote # To avoid circular deps. | |
| 257 | 261 | ||
@@ -264,16 +268,16 @@ def remote_repo_creator(self): | |||
| 264 | 268 | rw_repo_dir = tempfile.mktemp(prefix="daemon_cloned_repo-%s-" % func.__name__) | |
| 265 | 269 | ||
| 266 | 270 | rw_daemon_repo = self.rorepo.clone(rw_daemon_repo_dir, shared=True, bare=True) | |
| 267 | - # recursive alternates info ? | ||
| 271 | + # Recursive alternates info? | ||
| 268 | 272 | rw_repo = rw_daemon_repo.clone(rw_repo_dir, shared=True, bare=False, n=True) | |
| 269 | 273 | try: | |
| 270 | 274 | rw_repo.head.commit = working_tree_ref | |
| 271 | 275 | rw_repo.head.reference.checkout() | |
| 272 | 276 | ||
| 273 | - # prepare for git-daemon | ||
| 277 | + # Prepare for git-daemon. | ||
| 274 | 278 | rw_daemon_repo.daemon_export = True | |
| 275 | 279 | ||
| 276 | - # this thing is just annoying ! | ||
| 280 | + # This thing is just annoying! | ||
| 277 | 281 | with rw_daemon_repo.config_writer() as crw: | |
| 278 | 282 | section = "daemon" | |
| 279 | 283 | try: | |
@@ -340,9 +344,7 @@ def remote_repo_creator(self): | |||
| 340 | 344 | ||
| 341 | 345 | ||
| 342 | 346 | class 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: | ||
| 346 | 348 | ||
| 347 | 349 | - Utility functions provided by the TestCase base of the unittest method such as:: | |
| 348 | 350 | self.fail("todo") | |
@@ -355,20 +357,20 @@ class TestBase(TestCase): | |||
| 355 | 357 | ||
| 356 | 358 | The rorepo is in fact your current project's git repo. If you refer to specific | |
| 357 | 359 | 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). | ||
| 359 | 361 | """ | |
| 360 | 362 | ||
| 361 | 363 | def _small_repo_url(self): | |
| 362 | - """:return" a path to a small, clonable repository""" | ||
| 364 | + """:return: A path to a small, clonable repository""" | ||
| 363 | 365 | from git.cmd import Git | |
| 364 | 366 | ||
| 365 | 367 | return Git.polish_url(osp.join(self.rorepo.working_tree_dir, "git/ext/gitdb/gitdb/ext/smmap")) | |
| 366 | 368 | ||
| 367 | 369 | @classmethod | |
| 368 | 370 | 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. | ||
| 372 | 374 | """ | |
| 373 | 375 | from git import Repo | |
| 374 | 376 | ||
@@ -383,7 +385,9 @@ def tearDownClass(cls): | |||
| 383 | 385 | def _make_file(self, rela_path, data, repo=None): | |
| 384 | 386 | """ | |
| 385 | 387 | 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. | ||
| 387 | 391 | """ | |
| 388 | 392 | repo = repo or self.rorepo | |
| 389 | 393 | abs_path = osp.join(repo.working_tree_dir, rela_path) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | - """Contains library functions""" | ||
| 1 | + """Support library for tests.""" | ||
| 2 | + | ||
| 2 | 3 | import logging | |
| 3 | 4 | import os | |
| 4 | 5 | import tempfile | |
@@ -20,22 +21,16 @@ | |||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | 23 | class TestBigRepoR(TestBase): | |
| 23 | - | ||
| 24 | 24 | """TestCase providing access to readonly 'big' repositories using the following | |
| 25 | 25 | member variables: | |
| 26 | 26 | ||
| 27 | - * gitrorepo | ||
| 28 | - | ||
| 29 | - * Read-Only git repository - actually the repo of git itself | ||
| 30 | - | ||
| 31 | - * puregitrorepo | ||
| 27 | + * gitrorepo: | ||
| 28 | + Read-Only git repository - actually (by default) the repo of GitPython itself. | ||
| 32 | 29 | ||
| 33 | - * As gitrepo, but uses pure python implementation | ||
| 30 | + * puregitrorepo: | ||
| 31 | + Like gitrorepo, but uses a pure Python implementation for its object database. | ||
| 34 | 32 | """ | |
| 35 | 33 | ||
| 36 | - # { Invariants | ||
| 37 | - # } END invariants | ||
| 38 | - | ||
| 39 | 34 | def setUp(self): | |
| 40 | 35 | try: | |
| 41 | 36 | super(TestBigRepoR, self).setUp() | |
@@ -62,10 +57,10 @@ def tearDown(self): | |||
| 62 | 57 | ||
| 63 | 58 | ||
| 64 | 59 | class TestBigRepoRW(TestBigRepoR): | |
| 60 | + """Like :class:`TestBigRepoR`, but provides a big repository that we can write to. | ||
| 65 | 61 | ||
| 66 | - """As above, but provides a big repository that we can write to. | ||
| 67 | - | ||
| 68 | - Provides ``self.gitrwrepo`` and ``self.puregitrwrepo``""" | ||
| 62 | + Provides ``self.gitrwrepo`` and ``self.puregitrwrepo``. | ||
| 63 | + """ | ||
| 69 | 64 | ||
| 70 | 65 | def setUp(self): | |
| 71 | 66 | self.gitrwrepo = None | |
| Back | FazBrowse Home | New Git URL |
0 commit comments