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

Commitc9d8845

Browse files
committed
Auto-launching git daemon to make tests more independent
Fixesgitpython-developers#217
1 parent1e1e19d commitc9d8845

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

‎git/test/lib/helper.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
importos
88
importsys
9-
fromgitimportRepo,Remote,GitCommandError
9+
fromgitimportRepo,Remote,GitCommandError,Git
1010
fromunittestimportTestCase
1111
importtempfile
1212
importshutil
@@ -149,6 +149,7 @@ def case(self, rw_repo, rw_remote_repo)
149149
This setup allows you to test push and pull scenarios and hooks nicely.
150150
151151
See working dir info in with_rw_repo
152+
:note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test.
152153
"""
153154
assertisinstance(working_tree_ref,basestring),"Decorator requires ref name for working tree checkout"
154155

@@ -186,17 +187,30 @@ def remote_repo_creator(self):
186187

187188
d_remote.config_writer.set('url',remote_repo_url)
188189

190+
temp_dir=os.path.dirname(_mktemp())
191+
# On windows, this will fail ... we deal with failures anyway and default to telling the user to do it
192+
try:
193+
gd=Git().daemon(temp_dir,as_process=True)
194+
exceptExceptionaserr:
195+
gd=None
196+
# end
197+
189198
# try to list remotes to diagnoes whether the server is up
190199
try:
191200
rw_repo.git.ls_remote(d_remote)
192201
exceptGitCommandError,e:
202+
# We assume in good faith that we didn't start the daemon - but make sure we kill it anyway
203+
# Of course we expect it to work here already, but maybe there are timing constraints
204+
# on some platforms ?
205+
ifgdisnotNone:
206+
os.kill(gd.proc.pid,15)
193207
printstr(e)
194208
ifos.name=='nt':
195209
raiseAssertionError(
196-
'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%os.path.dirname(_mktemp()))
210+
'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"'%temp_dir)
197211
else:
198212
raiseAssertionError(
199-
'Please start a git-daemon to run this test, execute: git-daemon "%s"'%os.path.dirname(_mktemp()))
213+
'Please start a git-daemon to run this test, execute: git-daemon "%s"'%temp_dir)
200214
# END make assertion
201215
# END catch ls remote error
202216

@@ -206,11 +220,16 @@ def remote_repo_creator(self):
206220
try:
207221
returnfunc(self,rw_repo,rw_remote_repo)
208222
finally:
223+
# gd.proc.kill() ... no idea why that doesn't work
224+
os.kill(gd.proc.pid,15)
225+
209226
os.chdir(prev_cwd)
210227
rw_repo.git.clear_cache()
211228
rw_remote_repo.git.clear_cache()
212229
shutil.rmtree(repo_dir,onerror=_rmtree_onerror)
213230
shutil.rmtree(remote_repo_dir,onerror=_rmtree_onerror)
231+
232+
gd.proc.wait()
214233
# END cleanup
215234
# END bare repo creator
216235
remote_repo_creator.__name__=func.__name__

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp