-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commit_step.py
42 lines (33 loc) · 1.47 KB
/
test_commit_step.py
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
from git import Repo
import pytest
from src.repo_smith.initialize_repo import initialize_repo
def test_commit_step_missing_message():
with pytest.raises(Exception):
initialize_repo("tests/specs/commit_step/commit_step_missing_message.yml")
def test_commit_step():
def pre_hook(r: Repo) -> None:
with pytest.raises(Exception):
# Ensure there is 0 commits
# Must cast to list since the Iterator alone will not raise an error
list(r.iter_commits("main"))
repo_initializer = initialize_repo("tests/specs/commit_step/commit.yml")
repo_initializer.add_pre_hook("commit", pre_hook)
with repo_initializer.initialize() as r:
commits = list(r.iter_commits("main"))
assert len(commits) == 1
commit = commits[0]
assert len(commit.stats.files) == 1
assert "file.txt" in commit.stats.files
def test_commit_step_empty_commit():
def pre_hook(r: Repo) -> None:
with pytest.raises(Exception):
# Ensure there is 0 commits
# Must cast to list since the Iterator alone will not raise an error
list(r.iter_commits("main"))
repo_initializer = initialize_repo("tests/specs/commit_step/commit_empty.yml")
repo_initializer.add_pre_hook("commit", pre_hook)
with repo_initializer.initialize() as r:
commits = list(r.iter_commits("main"))
assert len(commits) == 1
commit = commits[0]
assert len(commit.stats.files) == 0