4 from typing
import Optional
8 from tests
.conftest
import Dotfiles
12 "sys.platform == 'win32'",
13 reason
="The hybrid sh/Python dotbot script doesn't run on Windows platforms",
15 @pytest.mark
.parametrize("python_name", [None, "python", "python3"])
16 def test_find_python_executable(python_name
: Optional
[str], home
: str, dotfiles
: Dotfiles
) -> None:
17 """Verify that the sh/Python hybrid dotbot executable can find Python."""
19 dotfiles
.write_config([])
20 dotbot_executable
= os
.path
.join(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))), "bin", "dotbot")
22 # Create a link to sh.
23 tmp_bin
= os
.path
.join(home
, "tmp_bin")
25 sh_path
= shutil
.which("sh")
26 assert sh_path
is not None
27 os
.symlink(sh_path
, os
.path
.join(tmp_bin
, "sh"))
29 if python_name
is not None:
30 with
open(os
.path
.join(tmp_bin
, python_name
), "w") as file:
31 file.write("#!" + tmp_bin
+ "/sh\n")
32 file.write("exit 0\n")
33 os
.chmod(os
.path
.join(tmp_bin
, python_name
), 0o777)
34 env
= dict(os
.environ
)
37 if python_name
is not None:
38 subprocess
.check_call(
39 [dotbot_executable
, "-c", dotfiles
.config_filename
],
43 with pytest
.raises(subprocess
.CalledProcessError
):
44 subprocess
.check_call(
45 [dotbot_executable
, "-c", dotfiles
.config_filename
],