Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1de2fdc

Browse files
committed
Test that version_info caches
This begins to test the established version_info caching behavior.
1 parente40fc2c commit1de2fdc

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

‎test/test_git.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
importshutil
1515
importsubprocess
1616
importsys
17-
fromtempfileimportTemporaryFile
17+
importtempfile
1818
fromunittestimportskipUnless
1919

2020
ifsys.version_info>= (3,8):
@@ -67,6 +67,24 @@ def _rollback_refresh():
6767
refresh()
6868

6969

70+
@contextlib.contextmanager
71+
def_fake_git():
72+
fake_output="git version 123.456.789 (fake)"
73+
74+
withtempfile.TemporaryDirectory()astdir:
75+
ifos.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+
yieldstr(fake_git.absolute())
86+
87+
7088
@ddt.ddt
7189
classTestGit(TestBase):
7290
@classmethod
@@ -260,7 +278,7 @@ def test_it_ignores_false_kwargs(self, git):
260278
self.assertTrue("pass_this_kwarg"notingit.call_args[1])
261279

262280
deftest_it_raises_proper_exception_with_output_stream(self):
263-
withTemporaryFile()astmp_file:
281+
withtempfile.TemporaryFile()astmp_file:
264282
withself.assertRaises(GitCommandError):
265283
self.git.checkout("non-existent-branch",output_stream=tmp_file)
266284

@@ -483,6 +501,16 @@ def test_refresh_with_good_relative_git_path_arg(self):
483501
refresh(basename)
484502
self.assertEqual(self.git.GIT_PYTHON_GIT_EXECUTABLE,absolute_path)
485503

504+
deftest_version_info_is_cached(self):
505+
with_rollback_refresh():
506+
with_fake_git()aspath:
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+
486514
deftest_options_are_passed_to_git(self):
487515
# This works because any command after git --version is ignored.
488516
git_version=self.git(version=True).NoOp()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp