Skip to content

Commit 89292a1

Browse files
committed
[branch-bender] Add unit testing
1 parent 0843a50 commit 89292a1

File tree

10 files changed

+305
-7
lines changed

10 files changed

+305
-7
lines changed

branch_bender/tests/specs/base.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,34 @@ initialization:
44
empty: true
55
message: Empty commit
66
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: merge
33+
branch-name: feature/login
34+
- type: merge
35+
branch-name: feature/dashboard
36+
- type: merge
37+
branch-name: feature/payments
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: merge
33+
branch-name: feature/login
34+
- type: merge
35+
branch-name: feature/dashboard
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: merge
33+
branch-name: feature/login
34+
- type: merge
35+
branch-name: feature/payments
36+
- type: merge
37+
branch-name: feature/dashboard
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: merge
33+
branch-name: feature/dashboard
34+
- type: merge
35+
branch-name: feature/login
36+
- type: merge
37+
branch-name: feature/payments
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty
6+
id: start
7+
- type: branch
8+
branch-name: bug-fix
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
8+
- type: branch
9+
branch-name: feature/login
10+
- type: commit
11+
empty: true
12+
message: Empty commit on feature/login
13+
- type: checkout
14+
branch-name: main
15+
16+
- type: branch
17+
branch-name: feature/dashboard
18+
- type: commit
19+
empty: true
20+
message: Empty commit on feature/dashboard
21+
- type: checkout
22+
branch-name: main
23+
24+
- type: branch
25+
branch-name: feature/payments
26+
- type: commit
27+
empty: true
28+
message: Empty commit on feature/payments
29+
- type: checkout
30+
branch-name: main
31+
32+
- type: branch
33+
branch-name: other
34+
- type: commit
35+
empty: true
36+
message: Empty commit on other
37+
- type: checkout
38+
branch-name: main
39+
40+
- type: merge
41+
branch-name: feature/login
42+
- type: merge
43+
branch-name: feature/dashboard
44+
- type: merge
45+
branch-name: other
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
initialization:
2+
steps:
3+
- type: new-file
4+
filename: test.txt
5+
contents: |
6+
hi
7+
- type: add
8+
files:
9+
- test.txt
10+
- type: commit
11+
message: Start
12+
id: start
13+
- type: edit-file
14+
filename: test.txt
15+
contents: |
16+
changed

branch_bender/tests/test_verify.py

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,69 @@
1-
from git_autograder import GitAutograderTestLoader
1+
from git_autograder import GitAutograderStatus, GitAutograderTestLoader, assert_output
22

3-
from ..verify import verify
3+
from ..verify import (
4+
FEATURE_DASHBOARD_MERGE_MISSING,
5+
FEATURE_LOGIN_MERGE_MISSING,
6+
FEATURE_PAYMENTS_MERGE_MISSING,
7+
MISSING_MERGES,
8+
NO_MERGES,
9+
NOT_ON_MAIN,
10+
RESET_MESSAGE,
11+
UNCOMMITTED_CHANGES,
12+
verify,
13+
)
414

515
REPOSITORY_NAME = "branch-bender"
616

717
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
818

919

10-
def test():
11-
with loader.load("specs/base.yml", "start"):
12-
pass
20+
def test_base():
21+
with loader.load("specs/base.yml", "start") as output:
22+
assert_output(output, GitAutograderStatus.SUCCESSFUL)
23+
24+
25+
def test_no_merges():
26+
with loader.load("specs/no_merges.yml", "start") as output:
27+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [NO_MERGES])
28+
29+
30+
def test_missing_merges():
31+
with loader.load("specs/missing_merges.yml", "start") as output:
32+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [MISSING_MERGES])
33+
34+
35+
def test_uncommitted():
36+
with loader.load("specs/uncommitted.yml") as output:
37+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [UNCOMMITTED_CHANGES])
38+
39+
40+
def test_not_main():
41+
with loader.load("specs/not_main.yml") as output:
42+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [NOT_ON_MAIN])
43+
44+
45+
def test_not_login_first():
46+
with loader.load("specs/not_login_first.yml", "start") as output:
47+
assert_output(
48+
output,
49+
GitAutograderStatus.UNSUCCESSFUL,
50+
[FEATURE_LOGIN_MERGE_MISSING, RESET_MESSAGE],
51+
)
52+
53+
54+
def test_not_dashboard_second():
55+
with loader.load("specs/not_dashboard_second.yml", "start") as output:
56+
assert_output(
57+
output,
58+
GitAutograderStatus.UNSUCCESSFUL,
59+
[FEATURE_DASHBOARD_MERGE_MISSING, RESET_MESSAGE],
60+
)
61+
62+
63+
def test_not_payments_last():
64+
with loader.load("specs/not_payments_last.yml", "start") as output:
65+
assert_output(
66+
output,
67+
GitAutograderStatus.UNSUCCESSFUL,
68+
[FEATURE_PAYMENTS_MERGE_MISSING, RESET_MESSAGE],
69+
)

branch_bender/verify.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from git_autograder import (
22
GitAutograderExercise,
3-
GitAutograderInvalidStateException,
43
GitAutograderOutput,
54
GitAutograderStatus,
6-
GitAutograderWrongAnswerException,
75
)
86

97
UNCOMMITTED_CHANGES = "You still have uncommitted changes. Commit them first on the appropriate branch first!"
@@ -34,9 +32,13 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
3432
main_reflog = main_branch.reflog
3533
merge_logs = [entry for entry in main_reflog if entry.action.startswith("merge")]
3634
merge_order = [entry.action[len("merge ") :] for entry in merge_logs][::-1]
35+
3736
if len(merge_order) == 0:
3837
raise exercise.wrong_answer([NO_MERGES])
3938

39+
if len(merge_order) < 3:
40+
raise exercise.wrong_answer([MISSING_MERGES])
41+
4042
if merge_order[0] != "feature/login":
4143
raise exercise.wrong_answer([FEATURE_LOGIN_MERGE_MISSING, RESET_MESSAGE])
4244

0 commit comments

Comments
 (0)