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

Commite148647

Browse files
committed
Add a direct test of run_commit_hook
This has three benefits:- run_commit_hook is public, being listed in git.index.fun.__all__, so it makes sense for it to have its own test.- When investigating (future, or current xfail-covered) failure of functions that use run_commit_hook, it will be useful to compare the results of other tests that already do exist to that of a direct test of run_commit_hook.- When changing which bash.exe run_commit_hook selects to use on Windows (including to ameliorate the limitation covered by the WinBashStatus.WslNoDistro xfail marks, or to attempt other possible changes suggested in#1745), or even just to investigate the possibility of doing so, it will make sense to add tests like this test but for more specific conditions or edge cases. Having this typical-case test to compare to should be helpful both for writing such tests and for efficiently verifying that the conditions they test are really the triggers for any failures.
1 parentf664a0b commite148647

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎test/test_index.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
InvalidGitRepositoryError,
3333
UnmergedEntriesError,
3434
)
35-
fromgit.index.funimporthook_path
35+
fromgit.index.funimporthook_path,run_commit_hook
3636
fromgit.index.typimportBaseIndexEntry,IndexEntry
3737
fromgit.objectsimportBlob
3838
fromtest.libimportTestBase,fixture,fixture_path,with_rw_directory,with_rw_repo
@@ -991,6 +991,24 @@ class Mocked:
991991
rel=index._to_relative_path(path)
992992
self.assertEqual(rel,os.path.relpath(path,root))
993993

994+
@pytest.mark.xfail(
995+
type(_win_bash_status)isWinBashStatus.Absent,
996+
reason="Can't run a hook on Windows without bash.exe.",
997+
rasies=HookExecutionError,
998+
)
999+
@pytest.mark.xfail(
1000+
type(_win_bash_status)isWinBashStatus.WslNoDistro,
1001+
reason="Currently uses the bash.exe of WSL, even with no WSL distro installed",
1002+
raises=HookExecutionError,
1003+
)
1004+
@with_rw_repo("HEAD",bare=True)
1005+
deftest_run_commit_hook(self,rw_repo):
1006+
index=rw_repo.index
1007+
_make_hook(index.repo.git_dir,"fake-hook","echo 'ran fake hook' >output.txt")
1008+
run_commit_hook("fake-hook",index)
1009+
output=Path(rw_repo.git_dir,"output.txt").read_text(encoding="utf-8")
1010+
self.assertEqual(output,"ran fake hook\n")
1011+
9941012
@pytest.mark.xfail(
9951013
type(_win_bash_status)isWinBashStatus.Absent,
9961014
reason="Can't run a hook on Windows without bash.exe.",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp