-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_log.py
More file actions
63 lines (49 loc) · 2 KB
/
test_log.py
File metadata and controls
63 lines (49 loc) · 2 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
import subprocess
import pytest
@pytest.mark.parametrize("format_flag", ["", "--format=full", "--format=fuller"])
def test_log(xtl_clone, commit_env_config, git2cpp_path, tmp_path, format_flag):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
p = xtl_path / "mook_file.txt"
p.write_text("")
cmd_add = [git2cpp_path, "add", "mook_file.txt"]
p_add = subprocess.run(cmd_add, cwd=xtl_path, text=True)
assert p_add.returncode == 0
cmd_commit = [git2cpp_path, "commit", "-m", "test commit"]
p_commit = subprocess.run(cmd_commit, cwd=xtl_path, text=True)
assert p_commit.returncode == 0
cmd_log = [git2cpp_path, "log"]
if format_flag != "":
cmd_log.append(format_flag)
p_log = subprocess.run(cmd_log, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
assert "Jane Doe" in p_log.stdout
assert "test commit" in p_log.stdout
if format_flag == "":
assert "Commit" not in p_log.stdout
else:
assert "Commit" in p_log.stdout
if format_flag == "--format=full":
assert "Date" not in p_log.stdout
else:
assert "CommitDate" in p_log.stdout
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)
assert p_log.returncode != 0
@pytest.mark.parametrize("max_count_flag", ["", "-n", "--max-count"])
def test_max_count(
xtl_clone, commit_env_config, git2cpp_path, tmp_path, max_count_flag
):
assert (tmp_path / "xtl").exists()
xtl_path = tmp_path / "xtl"
cmd_log = [git2cpp_path, "log"]
if max_count_flag != "":
cmd_log.append(max_count_flag)
cmd_log.append("2")
p_log = subprocess.run(cmd_log, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
if max_count_flag == "":
assert p_log.stdout.count("Author") > 2
else:
assert p_log.stdout.count("Author") == 2