Skip to content

Commit bce1a22

Browse files
committed
Extract _make_executable for TestSpawn.
1 parent d8ccaf1 commit bce1a22

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

distutils/tests/test_spawn.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ def test_spawn(self):
4545
spawn([exe]) # should work without any error
4646

4747
def test_find_executable(self, tmp_path):
48-
program_noeext = 'program'
49-
# Give the temporary program an ".exe" suffix for all.
50-
# It's needed on Windows and not harmful on other platforms.
51-
program = program_noeext + ".exe"
52-
53-
program_path = tmp_path / program
54-
program_path.write_text("", encoding='utf-8')
55-
program_path.chmod(stat.S_IXUSR)
48+
program_path = self._make_executable(tmp_path, '.exe')
49+
program = program_path.name
50+
program_noeext = program_path.with_suffix('').name
5651
filename = str(program_path)
5752
tmp_dir = path.Path(tmp_path)
5853

@@ -121,6 +116,15 @@ def test_find_executable(self, tmp_path):
121116
rv = find_executable(program)
122117
assert rv == filename
123118

119+
@staticmethod
120+
def _make_executable(tmp_path, ext):
121+
# Give the temporary program a suffix regardless of platform.
122+
# It's needed on Windows and not harmful on others.
123+
program = tmp_path.joinpath('program').with_suffix(ext)
124+
program.write_text("", encoding='utf-8')
125+
program.chmod(stat.S_IXUSR)
126+
return program
127+
124128
def test_spawn_missing_exe(self):
125129
with pytest.raises(DistutilsExecError) as ctx:
126130
spawn(['does-not-exist'])

0 commit comments

Comments
 (0)