def _parse_cmd(cmd: str, *paths: str) -> typing.Tuple[pathlib.Path, typing.List[str]]: try: exe_name, args = cmd.split(' ', maxsplit=1) except ValueError: # cmd has no argument exe_name, args = cmd, '' exe_path: typing.Optional[pathlib.Path] = find_executable(exe_name, *paths) if not exe_path: raise ExecutableNotFoundError(exe_name) args_list = shlex.split(args) return exe_path, args_list
def test_direct_find(): exe = Path('test.exe') exe.touch() assert exe.absolute() == _find_exe.find_executable('test')
def test_paths(): assert _find_exe.find_executable('python') assert _find_exe.find_executable('python', '.') _find_exe._KNOWN_EXECUTABLES = {} assert _find_exe.find_executable('python', '.') is None
def test_context(): assert _find_exe.find_executable('__sure__not__') is None _find_exe._KNOWN_EXECUTABLES['__sure__not__.exe'] = 'ok' assert _find_exe.find_executable('__sure__not__') == 'ok'
def test_find_executable(): python = _find_exe.find_executable('python') assert _find_exe.find_executable('python.exe') == python assert _find_exe.find_executable('python', f'{sys.prefix}/Scripts') == python assert _find_exe.find_executable('__sure__not__') is None