diff --git a/tests/test_cli_textconv_with_git.py b/tests/test_cli_textconv_with_git.py index 5e9da4f..e67d4f5 100644 --- a/tests/test_cli_textconv_with_git.py +++ b/tests/test_cli_textconv_with_git.py @@ -82,6 +82,8 @@ def func(path_cwd): key = "diff.inv.textconv" soi_textconv_path = "sphobjinv-textconv" + + # On Windows, resolved executables paths resolved_soi_textconv_path = shutil.which(soi_textconv_path) if resolved_soi_textconv_path is None: resolved_soi_textconv_path = soi_textconv_path @@ -93,10 +95,7 @@ def func(path_cwd): logger_.info(msg_info) # On Windows, executable's path must be resolved - msg_info = ( - """.git/config diff textconv executable's path: """ - f"{resolved_soi_textconv_path}" - ) + msg_info = f""".git/config diff textconv executable's path: {val}""" logger_.info(msg_info) path_git_dir_dst = path_cwd / ".git" @@ -112,6 +111,12 @@ def func(path_cwd): reason = f"Unable to set git config setting {key} to {val}" assert is_success is True, reason + if is_win: + # .git/config after update + gc_contents = path_git_config_dst.read_text() + msg_info = f""".git/config (after update):{os.linesep}{gc_contents}""" + logger_.info(msg_info) + return func @@ -161,14 +166,15 @@ def test_textconv_git_diff( if is_win or is_linux: msg_info = f"cwd {wd.cwd!s}" logger.info(msg_info) + if is_win: + from pathlib import WindowsPath - # On Windows, unresolved executables paths - soi_textconv_path = "sphobjinv-textconv" - - # On Windows, resolved executables paths - resolved_soi_textconv_path = shutil.which(soi_textconv_path) - if resolved_soi_textconv_path is None: - resolved_soi_textconv_path = soi_textconv_path + soi_textconv_path = "sphobjinv-textconv" + str_path = shutil.which(soi_textconv_path) + if str_path is not None: + logger.info(str_path) + msg_info = str(WindowsPath(str_path)) + logger.info(msg_info) # git init wd("git init") @@ -177,6 +183,11 @@ def test_textconv_git_diff( # Into .git/config, set the textconv absolute path gitconfig(wd.cwd) + if is_win or is_linux: + key = "diff.inv.textconv" + gc_val = wd.git_config_get(key) + msg_info = f".git/config {key} --> {gc_val}" + logging.info(msg_info) # .gitattributes # Informs git: .inv are binary files uses textconv "inv" from .git/config diff --git a/tests/wd_wrapper.py b/tests/wd_wrapper.py index 8137229..d43ea65 100644 --- a/tests/wd_wrapper.py +++ b/tests/wd_wrapper.py @@ -15,7 +15,7 @@ class WorkDir import platform import shlex import subprocess as sp # noqa: S404 -from pathlib import Path +from pathlib import Path, WindowsPath from typing import Dict, List @@ -257,8 +257,12 @@ def git_config_list(self) -> Dict[str, str]: str_blob = cp_out.stdout key_val_pairs = str_blob.split(os.linesep) for key_val_pair in key_val_pairs: - key, val = key_val_pair.split("=") - d_ret[key] = val + if len(key_val_pair) != 0: + pair = key_val_pair.split("=") + if len(pair) == 2: + key = pair[0] + val = pair[1] + d_ret[key] = val else: # no git config settings? Hmmm ... pass @@ -331,16 +335,23 @@ def git_config_set( """ is_win = platform.system().lower() == "windows" + cmd = [ + "git", + "config", + dotted_key, + ] if is_path and is_win: # In Bash, single quotes protect (Windows path) backslashes # Does not deal with escaping spaces - val = f"'{val}'" - + # `Path is Windows safe `_ + escaped_val = "'" + str(WindowsPath(val)) + "'" + cmd.append(escaped_val) + else: + cmd.append(val) # Sphinx hates \$ # It's non-obvious if the above solution is viable. # git config diff.inv.textconv "sh -c 'sphobjinv co plain \"\$0\" -'" # git config diff.inv.textconv "sh -c 'sphobjinv-textconv \"\$0\"'" - cmd = f"git config {dotted_key} '{val}'" cp_out = run(cmd, cwd=self.cwd) if cp_out is None or cp_out.returncode != 0: ret = False