Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions test/conftest_wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -155,6 +158,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:
Expand All @@ -167,12 +171,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
)
Expand Down
5 changes: 1 addition & 4 deletions test/test_add.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess

import pytest
from .conftest import GIT2CPP_TEST_WASM


@pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"])
Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions test/test_branch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess

import pytest
from .conftest import GIT2CPP_TEST_WASM


def test_branch_list(xtl_clone, git2cpp_path, tmp_path):
Expand Down Expand Up @@ -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


Expand Down
5 changes: 1 addition & 4 deletions test/test_clone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import subprocess
from .conftest import GIT2CPP_TEST_WASM

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

Expand All @@ -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"]
Expand Down
5 changes: 1 addition & 4 deletions test/test_config.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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"
5 changes: 1 addition & 4 deletions test/test_log.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess

import pytest
from .conftest import GIT2CPP_TEST_WASM


@pytest.mark.parametrize("format_flag", ["", "--format=full", "--format=fuller"])
Expand Down Expand Up @@ -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


Expand Down
21 changes: 5 additions & 16 deletions test/test_rebase.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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


Expand All @@ -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


Expand Down Expand Up @@ -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


Expand All @@ -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


Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions test/test_reset.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions test/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import subprocess

import pytest
from .conftest import GIT2CPP_TEST_WASM


@pytest.mark.parametrize("short_flag", ["", "-s", "--short"])
Expand Down Expand Up @@ -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


Expand Down