11from __future__ import annotations
22
3+ import contextlib
34import subprocess
45import sys
56from unittest import mock
1516from testing .fixtures import git_dir
1617from testing .fixtures import sample_local_config
1718from testing .fixtures import write_config
18- from testing .util import cwd
1919from testing .util import git_commit
2020
2121
@@ -269,7 +269,7 @@ def push_example(tempdir_factory):
269269def test_run_ns_pre_push_updating_branch (push_example ):
270270 src , src_head , clone , clone_head = push_example
271271
272- with cwd (clone ):
272+ with contextlib . chdir (clone ):
273273 args = ('origin' , src )
274274 stdin = f'HEAD { clone_head } refs/heads/b { src_head } \n ' .encode ()
275275 ns = hook_impl ._run_ns ('pre-push' , False , args , stdin )
@@ -287,7 +287,7 @@ def test_run_ns_pre_push_updating_branch(push_example):
287287def test_run_ns_pre_push_new_branch (push_example ):
288288 src , src_head , clone , clone_head = push_example
289289
290- with cwd (clone ):
290+ with contextlib . chdir (clone ):
291291 args = ('origin' , src )
292292 stdin = f'HEAD { clone_head } refs/heads/b { hook_impl .Z40 } \n ' .encode ()
293293 ns = hook_impl ._run_ns ('pre-push' , False , args , stdin )
@@ -300,7 +300,7 @@ def test_run_ns_pre_push_new_branch(push_example):
300300def test_run_ns_pre_push_new_branch_existing_rev (push_example ):
301301 src , src_head , clone , _ = push_example
302302
303- with cwd (clone ):
303+ with contextlib . chdir (clone ):
304304 args = ('origin' , src )
305305 stdin = f'HEAD { src_head } refs/heads/b2 { hook_impl .Z40 } \n ' .encode ()
306306 ns = hook_impl ._run_ns ('pre-push' , False , args , stdin )
@@ -311,7 +311,7 @@ def test_run_ns_pre_push_new_branch_existing_rev(push_example):
311311def test_run_ns_pre_push_ref_with_whitespace (push_example ):
312312 src , src_head , clone , _ = push_example
313313
314- with cwd (clone ):
314+ with contextlib . chdir (clone ):
315315 args = ('origin' , src )
316316 line = f'HEAD^{{/ }} { src_head } refs/heads/b2 { hook_impl .Z40 } \n '
317317 stdin = line .encode ()
@@ -327,7 +327,7 @@ def test_pushing_orphan_branch(push_example):
327327 git_commit (cwd = clone , msg = 'something else to get unique hash' )
328328 clone_rev = git .head_rev (clone )
329329
330- with cwd (clone ):
330+ with contextlib . chdir (clone ):
331331 args = ('origin' , src )
332332 stdin = f'HEAD { clone_rev } refs/heads/b2 { hook_impl .Z40 } \n ' .encode ()
333333 ns = hook_impl ._run_ns ('pre-push' , False , args , stdin )
@@ -339,7 +339,7 @@ def test_pushing_orphan_branch(push_example):
339339def test_run_ns_pre_push_deleting_branch (push_example ):
340340 src , src_head , clone , _ = push_example
341341
342- with cwd (clone ):
342+ with contextlib . chdir (clone ):
343343 args = ('origin' , src )
344344 stdin = f'(delete) { hook_impl .Z40 } refs/heads/b { src_head } ' .encode ()
345345 ns = hook_impl ._run_ns ('pre-push' , False , args , stdin )
@@ -352,7 +352,7 @@ def test_hook_impl_main_noop_pre_push(cap_out, store, push_example):
352352
353353 stdin = f'(delete) { hook_impl .Z40 } refs/heads/b { src_head } ' .encode ()
354354 with mock .patch .object (sys .stdin .buffer , 'read' , return_value = stdin ):
355- with cwd (clone ):
355+ with contextlib . chdir (clone ):
356356 write_config ('.' , sample_local_config ())
357357 ret = hook_impl .hook_impl (
358358 store ,
@@ -368,7 +368,7 @@ def test_hook_impl_main_noop_pre_push(cap_out, store, push_example):
368368
369369
370370def test_hook_impl_main_runs_hooks (cap_out , tempdir_factory , store ):
371- with cwd (git_dir (tempdir_factory )):
371+ with contextlib . chdir (git_dir (tempdir_factory )):
372372 write_config ('.' , sample_local_config ())
373373 ret = hook_impl .hook_impl (
374374 store ,
0 commit comments