-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_fixtures.py
More file actions
75 lines (59 loc) · 2.53 KB
/
test_fixtures.py
File metadata and controls
75 lines (59 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Test fixtures to confirm that wasm monkeypatching works correctly.
import re
import subprocess
from .conftest import GIT2CPP_TEST_WASM
def test_run_in_tmp_path(tmp_path, run_in_tmp_path):
p = subprocess.run(["pwd"], capture_output=True, text=True, check=True)
assert p.stdout.strip() == str(tmp_path)
def test_tmp_path(tmp_path):
p = subprocess.run(["pwd"], capture_output=True, text=True, check=True, cwd=str(tmp_path))
assert p.stdout.strip() == str(tmp_path)
assert tmp_path.exists()
assert tmp_path.is_dir()
assert not tmp_path.is_file()
assert sorted(tmp_path.iterdir()) == []
subprocess.run(["mkdir", f"{tmp_path}/def"], capture_output=True, text=True, check=True)
assert sorted(tmp_path.iterdir()) == [tmp_path / "def"]
subprocess.run(["mkdir", f"{tmp_path}/abc"], capture_output=True, text=True, check=True)
assert sorted(tmp_path.iterdir()) == [tmp_path / "abc", tmp_path / "def"]
p = subprocess.run(["pwd"], capture_output=True, text=True, check=True, cwd=tmp_path.parent)
assert p.stdout.strip() == str(tmp_path.parent)
assert tmp_path in list(tmp_path.parent.iterdir())
def test_env_vars():
# By default there should be not GIT_* env vars set.
p = subprocess.run(["env"], capture_output=True, text=True, check=True)
git_lines = sorted(filter(lambda f: f.startswith("GIT_"), re.split(r"\r?\n", p.stdout)))
if GIT2CPP_TEST_WASM:
assert git_lines == ["GIT_CORS_PROXY=http://localhost:8881/"]
else:
assert git_lines == []
def test_repo_init_with_commit(repo_init_with_commit, git2cpp_path, tmp_path):
assert (tmp_path / "initial.txt").exists()
assert (tmp_path / "initial.txt").is_file()
assert (tmp_path / "initial.txt").read_text() == "initial"
git_dir = tmp_path / ".git"
assert git_dir.exists()
assert git_dir.is_dir()
assert sorted(tmp_path.iterdir()) == [
git_dir,
tmp_path / "initial.txt",
]
assert sorted(git_dir.iterdir()) == [
git_dir / "HEAD",
git_dir / "config",
git_dir / "description",
git_dir / "hooks",
git_dir / "index",
git_dir / "info",
git_dir / "logs",
git_dir / "objects",
git_dir / "refs",
]
cmd = [git2cpp_path, "log"]
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode == 0
lines = p.stdout.splitlines()
assert "commit" in lines[0]
assert lines[1].startswith("Author:")
assert lines[2].startswith("Date:")
assert "Initial commit" in lines[4]