From 588773ffe8bb4064777b9fd6ebd9a41f56e58cc6 Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Tue, 17 Feb 2026 17:12:16 +0000 Subject: [PATCH 1/2] Fix return code in wasm tests --- test/conftest_wasm.py | 7 ++++--- test/test_add.py | 5 +---- test/test_branch.py | 5 +---- test/test_clone.py | 5 +---- test/test_config.py | 5 +---- test/test_log.py | 5 +---- test/test_rebase.py | 21 +++++---------------- test/test_reset.py | 5 +---- test/test_status.py | 5 +---- 9 files changed, 16 insertions(+), 47 deletions(-) diff --git a/test/conftest_wasm.py b/test/conftest_wasm.py index d6f2b1e..71cf70b 100644 --- a/test/conftest_wasm.py +++ b/test/conftest_wasm.py @@ -155,6 +155,7 @@ def maybe_wrap_arg(s: str | MockPath) -> str: # TypeScript object is auto converted to Python dict. # Want to return subprocess.CompletedProcess, consider namedtuple if this fails in future. + returncode = proc['returncode'] stdout = proc['stdout'] if capture_output else '' stderr = proc['stderr'] if capture_output else '' if not text: @@ -167,12 +168,12 @@ def maybe_wrap_arg(s: str | MockPath) -> str: if proc['returncode'] != 0: raise RuntimeError(f"Error setting cwd to {old_cwd}") - if check and proc['returncode'] != 0: - raise subprocess.CalledProcessError(proc['returncode'], cmd, stdout, stderr) + if check and returncode != 0: + raise subprocess.CalledProcessError(returncode, cmd, stdout, stderr) return subprocess.CompletedProcess( args=cmd, - returncode=proc['returncode'], + returncode=returncode, stdout=stdout, stderr=stderr ) diff --git a/test/test_add.py b/test/test_add.py index d324b8b..8c19f63 100644 --- a/test/test_add.py +++ b/test/test_add.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM @pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"]) @@ -40,7 +39,5 @@ def test_add_nogit(git2cpp_path, tmp_path): cmd_add = [git2cpp_path, 'add', 'mook_file.txt'] p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True, capture_output=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_add.returncode != 0 + assert p_add.returncode != 0 assert "error: could not find repository at" in p_add.stderr diff --git a/test/test_branch.py b/test/test_branch.py index 3a21136..b9dd30c 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM def test_branch_list(xtl_clone, git2cpp_path, tmp_path): @@ -38,9 +37,7 @@ def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path): def test_branch_nogit(git2cpp_path, tmp_path): cmd = [git2cpp_path, 'branch'] p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p.returncode != 0 + assert p.returncode != 0 assert "error: could not find repository at" in p.stderr diff --git a/test/test_clone.py b/test/test_clone.py index 57144b4..ff9ccec 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -1,5 +1,4 @@ import subprocess -from .conftest import GIT2CPP_TEST_WASM url = "https://github.com/xtensor-stack/xtl.git" @@ -22,9 +21,7 @@ def test_clone_is_bare(git2cpp_path, tmp_path, run_in_tmp_path): status_cmd = [git2cpp_path, "status"] p_status = subprocess.run(status_cmd, capture_output=True, cwd=tmp_path / "xtl", text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_status.returncode != 0 + assert p_status.returncode != 0 assert "This operation is not allowed against bare repositories" in p_status.stderr branch_cmd = [git2cpp_path, "branch"] diff --git a/test/test_config.py b/test/test_config.py index dcf4712..cecb720 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM def test_config_list(commit_env_config, git2cpp_path, tmp_path): @@ -53,7 +52,5 @@ def test_config_unset(git2cpp_path, tmp_path): cmd_get = [git2cpp_path, "config", "get", "core.bare"] p_get = subprocess.run(cmd_get, capture_output=True, cwd=tmp_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_get.returncode != 0 + assert p_get.returncode != 0 assert p_get.stderr == "error: config value 'core.bare' was not found\n" diff --git a/test/test_log.py b/test/test_log.py index 9d60d6f..18b91ee 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM @pytest.mark.parametrize("format_flag", ["", "--format=full", "--format=fuller"]) @@ -41,9 +40,7 @@ def test_log(xtl_clone, commit_env_config, git2cpp_path, tmp_path, format_flag): def test_log_nogit(commit_env_config, git2cpp_path, tmp_path): cmd_log = [git2cpp_path, "log"] p_log = subprocess.run(cmd_log, capture_output=True, cwd=tmp_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_log.returncode != 0 + assert p_log.returncode != 0 assert "error: could not find repository at" in p_log.stderr diff --git a/test/test_rebase.py b/test/test_rebase.py index de5efe8..b6806b9 100644 --- a/test/test_rebase.py +++ b/test/test_rebase.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM def test_rebase_basic(xtl_clone, commit_env_config, git2cpp_path, tmp_path): @@ -346,9 +345,7 @@ def test_rebase_no_upstream_error(xtl_clone, commit_env_config, git2cpp_path, tm rebase_cmd = [git2cpp_path, "rebase"] p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_rebase.returncode != 0 + assert p_rebase.returncode != 0 assert "upstream is required for rebase" in p_rebase.stderr @@ -359,9 +356,7 @@ def test_rebase_invalid_upstream_error(xtl_clone, commit_env_config, git2cpp_pat rebase_cmd = [git2cpp_path, "rebase", "nonexistent-branch"] p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_rebase.returncode != 0 + assert p_rebase.returncode != 0 assert "could not resolve upstream" in p_rebase.stderr or "could not resolve upstream" in p_rebase.stdout @@ -390,9 +385,7 @@ def test_rebase_already_in_progress_error(xtl_clone, commit_env_config, git2cpp_ # Try to start another rebase rebase_cmd = [git2cpp_path, "rebase", "master"] p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_rebase.returncode != 0 + assert p_rebase.returncode != 0 assert "rebase is already in progress" in p_rebase.stderr or "rebase is already in progress" in p_rebase.stdout @@ -403,9 +396,7 @@ def test_rebase_continue_without_rebase_error(xtl_clone, commit_env_config, git2 continue_cmd = [git2cpp_path, "rebase", "--continue"] p_continue = subprocess.run(continue_cmd, capture_output=True, cwd=xtl_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_continue.returncode != 0 + assert p_continue.returncode != 0 assert "No rebase in progress" in p_continue.stderr or "No rebase in progress" in p_continue.stdout @@ -433,7 +424,5 @@ def test_rebase_continue_with_unresolved_conflicts(xtl_clone, commit_env_config, # Try to continue without resolving continue_cmd = [git2cpp_path, "rebase", "--continue"] p_continue = subprocess.run(continue_cmd, capture_output=True, cwd=xtl_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_continue.returncode != 0 + assert p_continue.returncode != 0 assert "resolve conflicts" in p_continue.stderr or "resolve conflicts" in p_continue.stdout diff --git a/test/test_reset.py b/test/test_reset.py index dd87829..d816afb 100644 --- a/test/test_reset.py +++ b/test/test_reset.py @@ -1,7 +1,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM def test_reset(xtl_clone, commit_env_config, git2cpp_path, tmp_path): @@ -37,7 +36,5 @@ def test_reset(xtl_clone, commit_env_config, git2cpp_path, tmp_path): def test_reset_nogit(git2cpp_path, tmp_path): cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"] p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p_reset.returncode != 0 + assert p_reset.returncode != 0 assert "error: could not find repository at" in p_reset.stderr diff --git a/test/test_status.py b/test/test_status.py index 7d4bb91..55b66df 100644 --- a/test/test_status.py +++ b/test/test_status.py @@ -3,7 +3,6 @@ import subprocess import pytest -from .conftest import GIT2CPP_TEST_WASM @pytest.mark.parametrize("short_flag", ["", "-s", "--short"]) @@ -43,9 +42,7 @@ def test_status_new_file(xtl_clone, git2cpp_path, tmp_path, short_flag, long_fla def test_status_nogit(git2cpp_path, tmp_path): cmd = [git2cpp_path, "status"] p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) - if not GIT2CPP_TEST_WASM: - # TODO: fix this in wasm build - assert p.returncode != 0 + assert p.returncode != 0 assert "error: could not find repository at" in p.stderr From 3b31aaffecd2fd193c35f31e1a212524c07eaf48 Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Tue, 17 Feb 2026 17:16:52 +0000 Subject: [PATCH 2/2] Implement Path.mkdir(parents=True) in wasm tests --- test/conftest_wasm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/conftest_wasm.py b/test/conftest_wasm.py index 71cf70b..2292918 100644 --- a/test/conftest_wasm.py +++ b/test/conftest_wasm.py @@ -89,8 +89,11 @@ def iterdir(self): for f in filter(lambda f: f not in ['', '.', '..'], re.split(r"\r?\n", p.stdout)): yield MockPath(self / f) - def mkdir(self): - subprocess.run(["mkdir", str(self)], capture_output=True, text=True, check=True) + def mkdir(self, *, parents=False): + args = [str(self)] + if parents: + args.append("-p") + subprocess.run(["mkdir"] + args, capture_output=True, text=True, check=True) def read_text(self) -> str: p = subprocess.run(["cat", str(self)], capture_output=True, text=True, check=True)