| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e40fc2c commit 1de2fdc
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | import shutil | |
| 15 | 15 | import subprocess | |
| 16 | 16 | import sys | |
| 17 | - from tempfile import TemporaryFile | ||
| 17 | + import tempfile | ||
| 18 | 18 | from unittest import skipUnless | |
| 19 | 19 | ||
| 20 | 20 | if sys.version_info >= (3, 8): | |
@@ -67,6 +67,24 @@ def _rollback_refresh(): | |||
| 67 | 67 | refresh() | |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | + @contextlib.contextmanager | ||
| 71 | + def _fake_git(): | ||
| 72 | + fake_output = "git version 123.456.789 (fake)" | ||
| 73 | + | ||
| 74 | + with tempfile.TemporaryDirectory() as tdir: | ||
| 75 | + if os.name == "nt": | ||
| 76 | + fake_git = Path(tdir, "fake-git.cmd") | ||
| 77 | + script = f"@echo {fake_output}\n" | ||
| 78 | + fake_git.write_text(script, encoding="utf-8") | ||
| 79 | + else: | ||
| 80 | + fake_git = Path(tdir, "fake-git") | ||
| 81 | + script = f"#!/bin/sh\necho '{fake_output}'\n" | ||
| 82 | + fake_git.write_text(script, encoding="utf-8") | ||
| 83 | + fake_git.chmod(0o755) | ||
| 84 | + | ||
| 85 | + yield str(fake_git.absolute()) | ||
| 86 | + | ||
| 87 | + | ||
| 70 | 88 | @ddt.ddt | |
| 71 | 89 | class TestGit(TestBase): | |
| 72 | 90 | @classmethod | |
@@ -260,7 +278,7 @@ def test_it_ignores_false_kwargs(self, git): | |||
| 260 | 278 | self.assertTrue("pass_this_kwarg" not in git.call_args[1]) | |
| 261 | 279 | ||
| 262 | 280 | def test_it_raises_proper_exception_with_output_stream(self): | |
| 263 | - with TemporaryFile() as tmp_file: | ||
| 281 | + with tempfile.TemporaryFile() as tmp_file: | ||
| 264 | 282 | with self.assertRaises(GitCommandError): | |
| 265 | 283 | self.git.checkout("non-existent-branch", output_stream=tmp_file) | |
| 266 | 284 | ||
@@ -483,6 +501,16 @@ def test_refresh_with_good_relative_git_path_arg(self): | |||
| 483 | 501 | refresh(basename) | |
| 484 | 502 | self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE, absolute_path) | |
| 485 | 503 | ||
| 504 | + def test_version_info_is_cached(self): | ||
| 505 | + with _rollback_refresh(): | ||
| 506 | + with _fake_git() as path: | ||
| 507 | + new_git = Git() # Not cached yet. | ||
| 508 | + refresh(path) | ||
| 509 | + version_info = new_git.version_info # Caches the value. | ||
| 510 | + self.assertEqual(version_info, (123, 456, 789)) | ||
| 511 | + os.remove(path) # Arrange that reading a second time would fail. | ||
| 512 | + self.assertEqual(new_git.version_info, version_info) # Cached value. | ||
| 513 | + | ||
| 486 | 514 | def test_options_are_passed_to_git(self): | |
| 487 | 515 | # This works because any command after git --version is ignored. | |
| 488 | 516 | git_version = self.git(version=True).NoOp() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments