@@ -84,9 +84,19 @@ def git_cherry_pick():
8484
8585
8686@pytest .fixture
87- def tmp_git_repo_dir (tmpdir , cd , git_init , git_commit ):
87+ def git_config ():
88+ git_config_cmd = 'git' , 'config'
89+ return lambda * extra_args : (
90+ subprocess .run (git_config_cmd + extra_args , check = True )
91+ )
92+
93+
94+ @pytest .fixture
95+ def tmp_git_repo_dir (tmpdir , cd , git_init , git_commit , git_config ):
8896 cd (tmpdir )
8997 git_init ()
98+ git_config ('--local' , 'user.name' , 'Monty Python' )
99+ git_config ('--local' , 'user.email' , 'bot@python.org' )
90100 git_commit ('Initial commit' , '--allow-empty' )
91101 yield tmpdir
92102
@@ -258,22 +268,16 @@ def test_is_not_cpython_repo():
258268 ["3.6" ])
259269
260270
261- def test_find_config (tmpdir , cd ):
262- cd (tmpdir )
263- subprocess .run ('git init .' .split (), check = True )
271+ def test_find_config (tmp_git_repo_dir , git_add , git_commit ):
264272 relative_config_path = '.cherry_picker.toml'
265- cfg = tmpdir .join (relative_config_path )
266- cfg .write ('param = 1' )
267- subprocess .run ('git add .' .split (), check = True )
268- subprocess .run (('git' , 'commit' , '-m' , 'Initial commit' ), check = True )
273+ tmp_git_repo_dir .join (relative_config_path ).write ('param = 1' )
274+ git_add (relative_config_path )
275+ git_commit ('Add config' )
269276 scm_revision = get_sha1_from ('HEAD' )
270- assert find_config (scm_revision ) == scm_revision + ':' + relative_config_path
277+ assert find_config (scm_revision ) == f' { scm_revision } : { relative_config_path } '
271278
272279
273- def test_find_config_not_found (tmpdir , cd ):
274- cd (tmpdir )
275- subprocess .run ('git init .' .split (), check = True )
276- subprocess .run (('git' , 'commit' , '-m' , 'Initial commit' , '--allow-empty' ), check = True )
280+ def test_find_config_not_found (tmp_git_repo_dir ):
277281 scm_revision = get_sha1_from ('HEAD' )
278282 assert find_config (scm_revision ) is None
279283
@@ -283,19 +287,16 @@ def test_find_config_not_git(tmpdir, cd):
283287 assert find_config (None ) is None
284288
285289
286- def test_load_full_config (tmpdir , cd ):
287- cd (tmpdir )
288- subprocess .run ('git init .' .split (), check = True )
290+ def test_load_full_config (tmp_git_repo_dir , git_add , git_commit ):
289291 relative_config_path = '.cherry_picker.toml'
290- cfg = tmpdir .join (relative_config_path )
291- cfg .write ('''\
292+ tmp_git_repo_dir .join (relative_config_path ).write ('''\
292293 team = "python"
293294 repo = "core-workfolow"
294295 check_sha = "5f007046b5d4766f971272a0cc99f8461215c1ec"
295296 default_branch = "devel"
296297 ''' )
297- subprocess . run ( 'git add .' . split (), check = True )
298- subprocess . run (( 'git' , 'commit' , '-m' , 'Initial commit' ), check = True )
298+ git_add ( relative_config_path )
299+ git_commit ( 'Add config' )
299300 scm_revision = get_sha1_from ('HEAD' )
300301 cfg = load_config (None )
301302 assert cfg == (
@@ -310,16 +311,13 @@ def test_load_full_config(tmpdir, cd):
310311 )
311312
312313
313- def test_load_partial_config (tmpdir , cd ):
314- cd (tmpdir )
315- subprocess .run ('git init .' .split (), check = True )
314+ def test_load_partial_config (tmp_git_repo_dir , git_add , git_commit ):
316315 relative_config_path = '.cherry_picker.toml'
317- cfg = tmpdir .join (relative_config_path )
318- cfg .write ('''\
316+ tmp_git_repo_dir .join (relative_config_path ).write ('''\
319317 repo = "core-workfolow"
320318 ''' )
321- subprocess . run ( 'git add .' . split (), check = True )
322- subprocess . run (( 'git' , 'commit' , '-m' , 'Initial commit' ), check = True )
319+ git_add ( relative_config_path )
320+ git_commit ( 'Add config' )
323321 scm_revision = get_sha1_from ('HEAD' )
324322 cfg = load_config (relative_config_path )
325323 assert cfg == (
@@ -417,7 +415,9 @@ def test_from_git_rev_read_negative(
417415def test_from_git_rev_read_uncommitted (tmp_git_repo_dir , git_add , git_commit ):
418416 some_text = 'blah blah 🤖'
419417 relative_file_path = '.some.file'
420- tmp_git_repo_dir .join (relative_file_path ).write (some_text )
418+ (
419+ pathlib .Path (tmp_git_repo_dir ) / relative_file_path
420+ ).write_text (some_text , encoding = 'utf-8' )
421421 git_add ('.' )
422422 with pytest .raises (ValueError ):
423423 from_git_rev_read ('HEAD:' + relative_file_path ) == some_text
@@ -426,7 +426,9 @@ def test_from_git_rev_read_uncommitted(tmp_git_repo_dir, git_add, git_commit):
426426def test_from_git_rev_read (tmp_git_repo_dir , git_add , git_commit ):
427427 some_text = 'blah blah 🤖'
428428 relative_file_path = '.some.file'
429- tmp_git_repo_dir .join (relative_file_path ).write (some_text )
429+ (
430+ pathlib .Path (tmp_git_repo_dir ) / relative_file_path
431+ ).write_text (some_text , encoding = 'utf-8' )
430432 git_add ('.' )
431433 git_commit ('Add some file' )
432434 assert from_git_rev_read ('HEAD:' + relative_file_path ) == some_text
0 commit comments