Skip to content

Commit 266f4cf

Browse files
authored
Fix wasm test returncode (#100)
* Fix return code in wasm tests * Implement Path.mkdir(parents=True) in wasm tests
1 parent 289f069 commit 266f4cf

File tree

9 files changed

+21
-49
lines changed

9 files changed

+21
-49
lines changed

test/conftest_wasm.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ def iterdir(self):
8989
for f in filter(lambda f: f not in ['', '.', '..'], re.split(r"\r?\n", p.stdout)):
9090
yield MockPath(self / f)
9191

92-
def mkdir(self):
93-
subprocess.run(["mkdir", str(self)], capture_output=True, text=True, check=True)
92+
def mkdir(self, *, parents=False):
93+
args = [str(self)]
94+
if parents:
95+
args.append("-p")
96+
subprocess.run(["mkdir"] + args, capture_output=True, text=True, check=True)
9497

9598
def read_text(self) -> str:
9699
p = subprocess.run(["cat", str(self)], capture_output=True, text=True, check=True)
@@ -155,6 +158,7 @@ def maybe_wrap_arg(s: str | MockPath) -> str:
155158

156159
# TypeScript object is auto converted to Python dict.
157160
# Want to return subprocess.CompletedProcess, consider namedtuple if this fails in future.
161+
returncode = proc['returncode']
158162
stdout = proc['stdout'] if capture_output else ''
159163
stderr = proc['stderr'] if capture_output else ''
160164
if not text:
@@ -167,12 +171,12 @@ def maybe_wrap_arg(s: str | MockPath) -> str:
167171
if proc['returncode'] != 0:
168172
raise RuntimeError(f"Error setting cwd to {old_cwd}")
169173

170-
if check and proc['returncode'] != 0:
171-
raise subprocess.CalledProcessError(proc['returncode'], cmd, stdout, stderr)
174+
if check and returncode != 0:
175+
raise subprocess.CalledProcessError(returncode, cmd, stdout, stderr)
172176

173177
return subprocess.CompletedProcess(
174178
args=cmd,
175-
returncode=proc['returncode'],
179+
returncode=returncode,
176180
stdout=stdout,
177181
stderr=stderr
178182
)

test/test_add.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
@@ -40,7 +39,5 @@ def test_add_nogit(git2cpp_path, tmp_path):
4039

4140
cmd_add = [git2cpp_path, 'add', 'mook_file.txt']
4241
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True, capture_output=True)
43-
if not GIT2CPP_TEST_WASM:
44-
# TODO: fix this in wasm build
45-
assert p_add.returncode != 0
42+
assert p_add.returncode != 0
4643
assert "error: could not find repository at" in p_add.stderr

test/test_branch.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
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):
3837
def test_branch_nogit(git2cpp_path, tmp_path):
3938
cmd = [git2cpp_path, 'branch']
4039
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
41-
if not GIT2CPP_TEST_WASM:
42-
# TODO: fix this in wasm build
43-
assert p.returncode != 0
40+
assert p.returncode != 0
4441
assert "error: could not find repository at" in p.stderr
4542

4643

test/test_clone.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import subprocess
2-
from .conftest import GIT2CPP_TEST_WASM
32

43
url = "https://github.com/xtensor-stack/xtl.git"
54

@@ -22,9 +21,7 @@ def test_clone_is_bare(git2cpp_path, tmp_path, run_in_tmp_path):
2221

2322
status_cmd = [git2cpp_path, "status"]
2423
p_status = subprocess.run(status_cmd, capture_output=True, cwd=tmp_path / "xtl", text=True)
25-
if not GIT2CPP_TEST_WASM:
26-
# TODO: fix this in wasm build
27-
assert p_status.returncode != 0
24+
assert p_status.returncode != 0
2825
assert "This operation is not allowed against bare repositories" in p_status.stderr
2926

3027
branch_cmd = [git2cpp_path, "branch"]

test/test_config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
def test_config_list(commit_env_config, git2cpp_path, tmp_path):
@@ -53,7 +52,5 @@ def test_config_unset(git2cpp_path, tmp_path):
5352

5453
cmd_get = [git2cpp_path, "config", "get", "core.bare"]
5554
p_get = subprocess.run(cmd_get, capture_output=True, cwd=tmp_path, text=True)
56-
if not GIT2CPP_TEST_WASM:
57-
# TODO: fix this in wasm build
58-
assert p_get.returncode != 0
55+
assert p_get.returncode != 0
5956
assert p_get.stderr == "error: config value 'core.bare' was not found\n"

test/test_log.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
@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):
4140
def test_log_nogit(commit_env_config, git2cpp_path, tmp_path):
4241
cmd_log = [git2cpp_path, "log"]
4342
p_log = subprocess.run(cmd_log, capture_output=True, cwd=tmp_path, text=True)
44-
if not GIT2CPP_TEST_WASM:
45-
# TODO: fix this in wasm build
46-
assert p_log.returncode != 0
43+
assert p_log.returncode != 0
4744
assert "error: could not find repository at" in p_log.stderr
4845

4946

test/test_rebase.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
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
346345

347346
rebase_cmd = [git2cpp_path, "rebase"]
348347
p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True)
349-
if not GIT2CPP_TEST_WASM:
350-
# TODO: fix this in wasm build
351-
assert p_rebase.returncode != 0
348+
assert p_rebase.returncode != 0
352349
assert "upstream is required for rebase" in p_rebase.stderr
353350

354351

@@ -359,9 +356,7 @@ def test_rebase_invalid_upstream_error(xtl_clone, commit_env_config, git2cpp_pat
359356

360357
rebase_cmd = [git2cpp_path, "rebase", "nonexistent-branch"]
361358
p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True)
362-
if not GIT2CPP_TEST_WASM:
363-
# TODO: fix this in wasm build
364-
assert p_rebase.returncode != 0
359+
assert p_rebase.returncode != 0
365360
assert "could not resolve upstream" in p_rebase.stderr or "could not resolve upstream" in p_rebase.stdout
366361

367362

@@ -390,9 +385,7 @@ def test_rebase_already_in_progress_error(xtl_clone, commit_env_config, git2cpp_
390385
# Try to start another rebase
391386
rebase_cmd = [git2cpp_path, "rebase", "master"]
392387
p_rebase = subprocess.run(rebase_cmd, capture_output=True, cwd=xtl_path, text=True)
393-
if not GIT2CPP_TEST_WASM:
394-
# TODO: fix this in wasm build
395-
assert p_rebase.returncode != 0
388+
assert p_rebase.returncode != 0
396389
assert "rebase is already in progress" in p_rebase.stderr or "rebase is already in progress" in p_rebase.stdout
397390

398391

@@ -403,9 +396,7 @@ def test_rebase_continue_without_rebase_error(xtl_clone, commit_env_config, git2
403396

404397
continue_cmd = [git2cpp_path, "rebase", "--continue"]
405398
p_continue = subprocess.run(continue_cmd, capture_output=True, cwd=xtl_path, text=True)
406-
if not GIT2CPP_TEST_WASM:
407-
# TODO: fix this in wasm build
408-
assert p_continue.returncode != 0
399+
assert p_continue.returncode != 0
409400
assert "No rebase in progress" in p_continue.stderr or "No rebase in progress" in p_continue.stdout
410401

411402

@@ -433,7 +424,5 @@ def test_rebase_continue_with_unresolved_conflicts(xtl_clone, commit_env_config,
433424
# Try to continue without resolving
434425
continue_cmd = [git2cpp_path, "rebase", "--continue"]
435426
p_continue = subprocess.run(continue_cmd, capture_output=True, cwd=xtl_path, text=True)
436-
if not GIT2CPP_TEST_WASM:
437-
# TODO: fix this in wasm build
438-
assert p_continue.returncode != 0
427+
assert p_continue.returncode != 0
439428
assert "resolve conflicts" in p_continue.stderr or "resolve conflicts" in p_continue.stdout

test/test_reset.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import subprocess
22

33
import pytest
4-
from .conftest import GIT2CPP_TEST_WASM
54

65

76
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):
3736
def test_reset_nogit(git2cpp_path, tmp_path):
3837
cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"]
3938
p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True)
40-
if not GIT2CPP_TEST_WASM:
41-
# TODO: fix this in wasm build
42-
assert p_reset.returncode != 0
39+
assert p_reset.returncode != 0
4340
assert "error: could not find repository at" in p_reset.stderr

test/test_status.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44

55
import pytest
6-
from .conftest import GIT2CPP_TEST_WASM
76

87

98
@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
4342
def test_status_nogit(git2cpp_path, tmp_path):
4443
cmd = [git2cpp_path, "status"]
4544
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
46-
if not GIT2CPP_TEST_WASM:
47-
# TODO: fix this in wasm build
48-
assert p.returncode != 0
45+
assert p.returncode != 0
4946
assert "error: could not find repository at" in p.stderr
5047

5148

0 commit comments

Comments
 (0)