@@ -84,9 +84,19 @@ def git_cherry_pick():
84
84
85
85
86
86
@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 ):
88
96
cd (tmpdir )
89
97
git_init ()
98
+ git_config ('--local' , 'user.name' , 'Monty Python' )
99
+ git_config (
'--local' ,
'user.email' ,
'[email protected] ' )
90
100
git_commit ('Initial commit' , '--allow-empty' )
91
101
yield tmpdir
92
102
@@ -258,22 +268,16 @@ def test_is_not_cpython_repo():
258
268
["3.6" ])
259
269
260
270
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 ):
264
272
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' )
269
276
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 } '
271
278
272
279
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 ):
277
281
scm_revision = get_sha1_from ('HEAD' )
278
282
assert find_config (scm_revision ) is None
279
283
@@ -283,19 +287,16 @@ def test_find_config_not_git(tmpdir, cd):
283
287
assert find_config (None ) is None
284
288
285
289
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 ):
289
291
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 ('''\
292
293
team = "python"
293
294
repo = "core-workfolow"
294
295
check_sha = "5f007046b5d4766f971272a0cc99f8461215c1ec"
295
296
default_branch = "devel"
296
297
''' )
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' )
299
300
scm_revision = get_sha1_from ('HEAD' )
300
301
cfg = load_config (None )
301
302
assert cfg == (
@@ -310,16 +311,13 @@ def test_load_full_config(tmpdir, cd):
310
311
)
311
312
312
313
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 ):
316
315
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 ('''\
319
317
repo = "core-workfolow"
320
318
''' )
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' )
323
321
scm_revision = get_sha1_from ('HEAD' )
324
322
cfg = load_config (relative_config_path )
325
323
assert cfg == (
@@ -417,7 +415,9 @@ def test_from_git_rev_read_negative(
417
415
def test_from_git_rev_read_uncommitted (tmp_git_repo_dir , git_add , git_commit ):
418
416
some_text = 'blah blah 🤖'
419
417
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' )
421
421
git_add ('.' )
422
422
with pytest .raises (ValueError ):
423
423
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):
426
426
def test_from_git_rev_read (tmp_git_repo_dir , git_add , git_commit ):
427
427
some_text = 'blah blah 🤖'
428
428
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' )
430
432
git_add ('.' )
431
433
git_commit ('Add some file' )
432
434
assert from_git_rev_read ('HEAD:' + relative_file_path ) == some_text
0 commit comments