| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 64e7256 commit 968b883
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,10 @@ | |||
| 3 | 3 | import json | |
| 4 | 4 | from pathlib import Path | |
| 5 | 5 | ||
| 6 | - from git import _backend | ||
| 6 | + import pytest | ||
| 7 | + | ||
| 8 | + from git import Repo, _backend | ||
| 9 | + from test.lib import GIT_REPO, TestBase | ||
| 7 | 10 | ||
| 8 | 11 | ||
| 9 | 12 | def pytest_addoption(parser): | |
@@ -30,3 +33,38 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config): | |||
| 30 | 33 | with open(path, "w", encoding="utf-8") as stream: | |
| 31 | 34 | json.dump(records, stream, indent=2) | |
| 32 | 35 | stream.write("\n") | |
| 36 | + | ||
| 37 | + | ||
| 38 | + @pytest.fixture(scope="session") | ||
| 39 | + def dependency_repo_factory(tmp_path_factory): | ||
| 40 | + """Prepare each immutable historical clone source only when a test needs it.""" | ||
| 41 | + root = tmp_path_factory.mktemp("dependency-repos") | ||
| 42 | + paths = {} | ||
| 43 | + | ||
| 44 | + def get(name): | ||
| 45 | + if name not in paths: | ||
| 46 | + revision = { | ||
| 47 | + "gitdb": "2da3232f9d58e7761e384ac6d32f7b1ed77a74a2", | ||
| 48 | + "smmap": "8ce61ad5cc4016bffaf25080bc0d69b3acbe8555", | ||
| 49 | + }[name] | ||
| 50 | + path = root / name | ||
| 51 | + with Repo(GIT_REPO) as source, source.clone(path, shared=True, no_checkout=True) as repo: | ||
| 52 | + repo.create_head("master", repo.commit(revision), force=True).checkout() | ||
| 53 | + if name == "smmap": | ||
| 54 | + repo.create_tag("v0.8.1", ref="master~10", message="Test fixture tag", force=True) | ||
| 55 | + repo.git.gc() | ||
| 56 | + paths[name] = str(path) | ||
| 57 | + return paths[name] | ||
| 58 | + | ||
| 59 | + return get | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + @pytest.fixture(scope="class", autouse=True) | ||
| 63 | + def historical_dependency_sources(request): | ||
| 64 | + if request.cls is not None and issubclass(request.cls, TestBase): | ||
| 65 | + factory = request.getfixturevalue("dependency_repo_factory") | ||
| 66 | + request.cls._dependency_repo_factory = staticmethod(factory) | ||
| 67 | + yield | ||
| 68 | + del request.cls._dependency_repo_factory | ||
| 69 | + else: | ||
| 70 | + yield | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -395,13 +395,13 @@ def _small_repo_url(self): | |||
| 395 | 395 | """:return: A path to a small, clonable repository""" | |
| 396 | 396 | from git.cmd import Git | |
| 397 | 397 | ||
| 398 | - return Git.polish_url(self._dependency_repo_dirs["smmap"]) | ||
| 398 | + return Git.polish_url(self._dependency_repo_factory("smmap")) | ||
| 399 | 399 | ||
| 400 | 400 | def _gitdb_repo_url(self): | |
| 401 | 401 | """:return: A local gitdb repository reconstructed from merged history""" | |
| 402 | 402 | from git.cmd import Git | |
| 403 | 403 | ||
| 404 | - return Git.polish_url(self._dependency_repo_dirs["gitdb"]) | ||
| 404 | + return Git.polish_url(self._dependency_repo_factory("gitdb")) | ||
| 405 | 405 | ||
| 406 | 406 | @classmethod | |
| 407 | 407 | def setUpClass(cls): | |
@@ -413,26 +413,11 @@ def setUpClass(cls): | |||
| 413 | 413 | ||
| 414 | 414 | gc.collect() | |
| 415 | 415 | cls.rorepo = Repo(GIT_REPO) | |
| 416 | - cls._dependency_repo_root = tempfile.mkdtemp(prefix="gitpython-dependency-repos-") | ||
| 417 | - cls._dependency_repo_dirs = {} | ||
| 418 | - for name, rev in { | ||
| 419 | - "gitdb": "2da3232f9d58e7761e384ac6d32f7b1ed77a74a2", | ||
| 420 | - "smmap": "8ce61ad5cc4016bffaf25080bc0d69b3acbe8555", | ||
| 421 | - }.items(): | ||
| 422 | - path = osp.join(cls._dependency_repo_root, name) | ||
| 423 | - repo = cls.rorepo.clone(path, shared=True, no_checkout=True) | ||
| 424 | - repo.create_head("master", repo.commit(rev), force=True).checkout() | ||
| 425 | - if name == "smmap": | ||
| 426 | - repo.create_tag("v0.8.1", ref="master~10", message="Test fixture tag", force=True) | ||
| 427 | - repo.git.gc() | ||
| 428 | - repo.close() | ||
| 429 | - cls._dependency_repo_dirs[name] = path | ||
| 430 | 416 | ||
| 431 | 417 | @classmethod | |
| 432 | 418 | def tearDownClass(cls): | |
| 433 | 419 | cls.rorepo.git.clear_cache() | |
| 434 | 420 | cls.rorepo.git = None | |
| 435 | - rmtree(cls._dependency_repo_root) | ||
| 436 | 421 | ||
| 437 | 422 | def _make_file(self, rela_path, data, repo=None): | |
| 438 | 423 | """ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments