| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1ed7644 commit bbf967b
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import os | |
| 2 | + import re | ||
| 2 | 3 | import subprocess | |
| 3 | 4 | from pathlib import Path | |
| 4 | 5 | ||
@@ -73,6 +74,10 @@ def private_test_repo(): | |||
| 73 | 74 | # Fixture containing everything needed to access private github repo. | |
| 74 | 75 | # GIT2CPP_TEST_PRIVATE_TOKEN is the fine-grained Personal Access Token for private test repo. | |
| 75 | 76 | # If this is not available as an environment variable, tests that use this fixture are skipped. | |
| 77 | + | ||
| 78 | + if GIT2CPP_TEST_WASM: | ||
| 79 | + pytest.skip("Use of credentials in wasm not yet implemented") | ||
| 80 | + | ||
| 76 | 81 | token = os.getenv("GIT2CPP_TEST_PRIVATE_TOKEN") | |
| 77 | 82 | if token is None or len(token) == 0: | |
| 78 | 83 | pytest.skip("No token for private test repo GIT2CPP_TEST_PRIVATE_TOKEN") | |
@@ -84,3 +89,11 @@ def private_test_repo(): | |||
| 84 | 89 | "https_url": f"https://github.com/{org_name}/{repo_name}", | |
| 85 | 90 | "token": token, | |
| 86 | 91 | } | |
| 92 | + | ||
| 93 | + | ||
| 94 | + # Functions not fixtures below here. | ||
| 95 | + | ||
| 96 | + | ||
| 97 | + def strip_ansi_colours(text): | ||
| 98 | + # Strip ansi colour code sequences from a string. | ||
| 99 | + return re.sub(r"\x1b\[[^m]*m", "", text) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,12 +19,15 @@ def pytest_ignore_collect(collection_path: pathlib.Path) -> bool: | |||
| 19 | 19 | "test_clone.py", | |
| 20 | 20 | "test_commit.py", | |
| 21 | 21 | "test_config.py", | |
| 22 | + "test_diff.py", | ||
| 23 | + "test_fetch.py", | ||
| 22 | 24 | "test_fixtures.py", | |
| 23 | 25 | "test_git.py", | |
| 24 | 26 | "test_init.py", | |
| 25 | 27 | "test_log.py", | |
| 26 | 28 | "test_merge.py", | |
| 27 | 29 | "test_mv.py", | |
| 30 | + "test_push.py", | ||
| 28 | 31 | "test_rebase.py", | |
| 29 | 32 | "test_remote.py", | |
| 30 | 33 | "test_reset.py", | |
@@ -33,6 +36,7 @@ def pytest_ignore_collect(collection_path: pathlib.Path) -> bool: | |||
| 33 | 36 | "test_rm.py", | |
| 34 | 37 | "test_stash.py", | |
| 35 | 38 | "test_status.py", | |
| 39 | + "test_tag.py", | ||
| 36 | 40 | ] | |
| 37 | 41 | ||
| 38 | 42 | ||
@@ -54,18 +58,6 @@ def load_page(page: Page): | |||
| 54 | 58 | page.locator("#loaded").wait_for() | |
| 55 | 59 | ||
| 56 | 60 | ||
| 57 | - def os_chdir(dir: str): | ||
| 58 | - subprocess.run(["cd", str(dir)], capture_output=True, check=True, text=True) | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - def os_getcwd(): | ||
| 62 | - return subprocess.run(["pwd"], capture_output=True, check=True, text=True).stdout.strip() | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - def os_remove(file: str): | ||
| 66 | - return subprocess.run(["rm", str(file)], capture_output=True, check=True, text=True) | ||
| 67 | - | ||
| 68 | - | ||
| 69 | 61 | class MockPath(pathlib.Path): | |
| 70 | 62 | def __init__(self, path: str = ""): | |
| 71 | 63 | super().__init__(path) | |
@@ -95,26 +87,62 @@ def mkdir(self, *, parents=False): | |||
| 95 | 87 | args.append("-p") | |
| 96 | 88 | subprocess.run(["mkdir"] + args, capture_output=True, text=True, check=True) | |
| 97 | 89 | ||
| 90 | + def read_bytes(self) -> bytes: | ||
| 91 | + raise RuntimeError("Not implemented") | ||
| 92 | + | ||
| 98 | 93 | def read_text(self) -> str: | |
| 99 | 94 | p = subprocess.run(["cat", str(self)], capture_output=True, text=True, check=True) | |
| 100 | 95 | text = p.stdout | |
| 101 | 96 | if text.endswith("\n"): | |
| 102 | 97 | text = text[:-1] | |
| 103 | 98 | return text | |
| 104 | 99 | ||
| 100 | + def write_bytes(self, data: bytes): | ||
| 101 | + # Convert binary data to a string where each element is backslash-escaped so that we can | ||
| 102 | + # write to file in cockle using `echo -e <backslash-escaped data>`. | ||
| 103 | + encoded_string = "".join(map(lambda d: f"\\x{d:02x}", data)) | ||
| 104 | + cmd = ["echo", "-e", encoded_string, ">", str(self)] | ||
| 105 | + subprocess.run(cmd, capture_output=True, text=True, check=True) | ||
| 106 | + return len(data) | ||
| 107 | + | ||
| 105 | 108 | def write_text(self, data: str): | |
| 106 | 109 | # Note that in general it is not valid to direct output of a subprocess.run call to a file, | |
| 107 | 110 | # but we get away with it here as the command arguments are passed straight through to | |
| 108 | 111 | # cockle without being checked. | |
| 109 | - p = subprocess.run(["echo", data, ">", str(self)], capture_output=True, text=True) | ||
| 110 | - assert p.returncode == 0 | ||
| 112 | + if data.endswith("\n"): | ||
| 113 | + data = data[:-1] | ||
| 114 | + cmd = ["echo", data, ">", str(self)] | ||
| 115 | + subprocess.run(cmd, capture_output=True, text=True, check=True) | ||
| 116 | + return len(data) | ||
| 111 | 117 | ||
| 112 | 118 | def __truediv__(self, other): | |
| 113 | 119 | if isinstance(other, str): | |
| 114 | 120 | return MockPath(f"{self}/{other}") | |
| 115 | 121 | raise RuntimeError("MockPath.__truediv__ only supports strings") | |
| 116 | 122 | ||
| 117 | 123 | ||
| 124 | + def os_chdir(dir: str): | ||
| 125 | + subprocess.run(["cd", str(dir)], capture_output=True, check=True, text=True) | ||
| 126 | + | ||
| 127 | + | ||
| 128 | + def os_getcwd(): | ||
| 129 | + return subprocess.run(["pwd"], capture_output=True, check=True, text=True).stdout.strip() | ||
| 130 | + | ||
| 131 | + | ||
| 132 | + def os_remove(file: str): | ||
| 133 | + return subprocess.run(["rm", str(file)], capture_output=True, check=True, text=True) | ||
| 134 | + | ||
| 135 | + | ||
| 136 | + def os_rename(src: str | MockPath, dst: str | MockPath): | ||
| 137 | + return subprocess.run(["mv", str(src), str(dst)], capture_output=True, check=True, text=True) | ||
| 138 | + | ||
| 139 | + | ||
| 140 | + def os_symlink(src: str | MockPath, dst: str | MockPath): | ||
| 141 | + return subprocess.run( | ||
| 142 | + ["ln", "-s", str(src), str(dst)], capture_output=True, check=True, text=True | ||
| 143 | + ) | ||
| 144 | + | ||
| 145 | + | ||
| 118 | 146 | def subprocess_run( | |
| 119 | 147 | page: Page, | |
| 120 | 148 | cmd: list[str], | |
@@ -192,3 +220,5 @@ def mock_subprocess_run(page: Page, monkeypatch): | |||
| 192 | 220 | monkeypatch.setattr(os, "chdir", os_chdir) | |
| 193 | 221 | monkeypatch.setattr(os, "getcwd", os_getcwd) | |
| 194 | 222 | monkeypatch.setattr(os, "remove", os_remove) | |
| 223 | + monkeypatch.setattr(os, "rename", os_rename) | ||
| 224 | + monkeypatch.setattr(os, "symlink", os_symlink) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import pytest | |
| 4 | 4 | ||
| 5 | + from .conftest import strip_ansi_colours | ||
| 6 | + | ||
| 5 | 7 | ||
| 6 | 8 | def test_checkout(repo_init_with_commit, git2cpp_path, tmp_path): | |
| 7 | 9 | assert (tmp_path / "initial.txt").exists() | |
@@ -103,6 +105,7 @@ def test_checkout_with_unstaged_changes(repo_init_with_commit, git2cpp_path, tmp | |||
| 103 | 105 | ||
| 104 | 106 | # Should succeed and show status | |
| 105 | 107 | assert p_checkout.returncode == 0 | |
| 108 | + p_checkout.stdout = strip_ansi_colours(p_checkout.stdout) | ||
| 106 | 109 | assert " M initial.txt" in p_checkout.stdout | |
| 107 | 110 | assert "Switched to branch 'newbranch'" in p_checkout.stdout | |
| 108 | 111 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | 4 | import pytest | |
| 5 | 5 | ||
| 6 | + from .conftest import strip_ansi_colours | ||
| 7 | + | ||
| 6 | 8 | ||
| 7 | 9 | def test_diff_nogit(git2cpp_path, tmp_path): | |
| 8 | 10 | cmd = [git2cpp_path, "diff"] | |
@@ -84,6 +86,8 @@ def test_diff_stat(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 84 | 86 | cmd = [git2cpp_path, "diff", "--stat"] | |
| 85 | 87 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 86 | 88 | assert p.returncode == 0 | |
| 89 | + | ||
| 90 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 87 | 91 | assert "initial.txt" in p.stdout | |
| 88 | 92 | assert "1 file changed, 1 insertion(+)" in p.stdout | |
| 89 | 93 | assert "Modified content" not in p.stdout | |
@@ -132,6 +136,7 @@ def test_diff_summary(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 132 | 136 | cmd = [git2cpp_path, "diff", "--cached", "--summary"] | |
| 133 | 137 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 134 | 138 | assert p.returncode == 0 | |
| 139 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 135 | 140 | assert "newfile.txt" in p.stdout | |
| 136 | 141 | assert "+" not in p.stdout | |
| 137 | 142 | ||
@@ -146,6 +151,7 @@ def test_diff_name_only(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 146 | 151 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 147 | 152 | ||
| 148 | 153 | assert p.returncode == 0 | |
| 154 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 149 | 155 | assert p.stdout == "initial.txt\n" | |
| 150 | 156 | assert "+" not in p.stdout | |
| 151 | 157 | ||
@@ -159,6 +165,7 @@ def test_diff_name_status(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 159 | 165 | cmd = [git2cpp_path, "diff", "--name-status"] | |
| 160 | 166 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 161 | 167 | assert p.returncode == 0 | |
| 168 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 162 | 169 | assert p.stdout == "M\tinitial.txt\n" | |
| 163 | 170 | ||
| 164 | 171 | ||
@@ -172,6 +179,7 @@ def test_diff_raw(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 172 | 179 | cmd = [git2cpp_path, "diff", "--raw"] | |
| 173 | 180 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 174 | 181 | assert p.returncode == 0 | |
| 182 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 175 | 183 | assert "M\tinitial.txt" in p.stdout | |
| 176 | 184 | assert bool(re.search(":[0-9]*", p.stdout)) | |
| 177 | 185 | ||
@@ -635,7 +643,6 @@ def test_diff_find_copies_harder( | |||
| 635 | 643 | [git2cpp_path, "commit", "-m", "add original file"], | |
| 636 | 644 | cwd=tmp_path, | |
| 637 | 645 | check=True, | |
| 638 | - env=commit_env_config, | ||
| 639 | 646 | ) | |
| 640 | 647 | ||
| 641 | 648 | # Create identical copy | |
@@ -669,7 +676,6 @@ def test_diff_find_copies_with_threshold( | |||
| 669 | 676 | [git2cpp_path, "commit", "-m", "add original file"], | |
| 670 | 677 | cwd=tmp_path, | |
| 671 | 678 | check=True, | |
| 672 | - env=commit_env_config, | ||
| 673 | 679 | ) | |
| 674 | 680 | ||
| 675 | 681 | # Create a partial copy (60% similar) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | 4 | import pytest | |
| 5 | 5 | ||
| 6 | + from .conftest import strip_ansi_colours | ||
| 7 | + | ||
| 6 | 8 | ||
| 7 | 9 | @pytest.mark.parametrize("format_flag", ["", "--format=full", "--format=fuller"]) | |
| 8 | 10 | def test_log(commit_env_config, git2cpp_path, tmp_path, format_flag): | |
@@ -101,7 +103,7 @@ def test_log_with_head_reference(repo_init_with_commit, commit_env_config, git2c | |||
| 101 | 103 | assert p_log.returncode == 0 | |
| 102 | 104 | ||
| 103 | 105 | # Check that HEAD reference is shown | |
| 104 | - assert "HEAD ->" in p_log.stdout | ||
| 106 | + assert "HEAD ->" in strip_ansi_colours(p_log.stdout) | ||
| 105 | 107 | assert "master" in p_log.stdout or "main" in p_log.stdout | |
| 106 | 108 | ||
| 107 | 109 | ||
@@ -253,7 +255,7 @@ def test_log_commit_without_references(commit_env_config, git2cpp_path, tmp_path | |||
| 253 | 255 | assert p_log.returncode == 0 | |
| 254 | 256 | ||
| 255 | 257 | # First commit line should have references | |
| 256 | - lines = p_log.stdout.split("\n") | ||
| 258 | + lines = strip_ansi_colours(p_log.stdout).split("\n") | ||
| 257 | 259 | first_commit_line = [line for line in lines if line.startswith("commit")][0] | |
| 258 | 260 | assert "(" in first_commit_line # Has references | |
| 259 | 261 | ||
@@ -286,7 +288,7 @@ def test_log_abbrev_commit_flags( | |||
| 286 | 288 | p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True) | |
| 287 | 289 | assert p.returncode == 0 | |
| 288 | 290 | ||
| 289 | - m = re.search(r"^commit\s+([0-9a-fA-F]+)", p.stdout, flags=re.MULTILINE) | ||
| 291 | + m = re.search(r"^commit\s+([0-9a-fA-F]+)", strip_ansi_colours(p.stdout), flags=re.MULTILINE) | ||
| 290 | 292 | if abbrev_commit_flag in ["", "--no-abbrev-commit"]: | |
| 291 | 293 | assert len(m.group(1)) == 40 | |
| 292 | 294 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | import pytest | |
| 6 | 6 | ||
| 7 | + from .conftest import strip_ansi_colours | ||
| 8 | + | ||
| 7 | 9 | ||
| 8 | 10 | @pytest.mark.parametrize("short_flag", ["", "-s", "--short"]) | |
| 9 | 11 | @pytest.mark.parametrize("long_flag", ["", "--long"]) | |
@@ -185,6 +187,8 @@ def test_status_mixed_changes(repo_init_with_commit, git2cpp_path, tmp_path, sho | |||
| 185 | 187 | p = subprocess.run(cmd_status, capture_output=True, cwd=tmp_path, text=True) | |
| 186 | 188 | ||
| 187 | 189 | assert p.returncode == 0 | |
| 190 | + | ||
| 191 | + p.stdout = strip_ansi_colours(p.stdout) | ||
| 188 | 192 | if short_flag == "-s": | |
| 189 | 193 | assert "A staged.txt" in p.stdout | |
| 190 | 194 | assert "D to_delete.txt" in p.stdout | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import pytest | |
| 4 | 4 | ||
| 5 | + from .conftest import GIT2CPP_TEST_WASM | ||
| 6 | + | ||
| 5 | 7 | ||
| 6 | 8 | def test_tag_list_empty(repo_init_with_commit, git2cpp_path, tmp_path): | |
| 7 | 9 | """Test listing tags when there are no tags.""" | |
@@ -235,6 +237,9 @@ def test_tag_annotated_no_message(repo_init_with_commit, commit_env_config, git2 | |||
| 235 | 237 | commit_cmd = [git2cpp_path, "commit", "-m", "my specific commit message"] | |
| 236 | 238 | subprocess.run(commit_cmd, cwd=tmp_path, check=True) | |
| 237 | 239 | ||
| 240 | + if GIT2CPP_TEST_WASM: | ||
| 241 | + pytest.skip("Not possible to pass empty argument to wasm") | ||
| 242 | + | ||
| 238 | 243 | # Create tag with empty message (should create lightweight tag) | |
| 239 | 244 | create_cmd = [git2cpp_path, "tag", "-m", "", "v1.0.0"] | |
| 240 | 245 | subprocess.run(create_cmd, capture_output=True, cwd=tmp_path, check=True) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments