Skip to content

Commit 22f7a81

Browse files
committed
[mix-messy-graph] Add tests
1 parent 6a88d56 commit 22f7a81

File tree

8 files changed

+315
-6
lines changed

8 files changed

+315
-6
lines changed

mix_messy_graph/tests/specs/base.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,39 @@ initialization:
22
steps:
33
- type: commit
44
empty: true
5-
message: Empty commit
5+
message: Add features.md
66
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: commit
17+
empty: true
18+
message: Add the search feature
19+
20+
- type: commit
21+
empty: true
22+
message: Add the delete feature
23+
24+
- type: new-file
25+
filename: features.md
26+
contents: |
27+
# Features
28+
29+
## Create Book
30+
31+
Allows creating one book at a time.
32+
33+
## Searching for Books
34+
35+
Allows searching for books by keywords.
36+
Works only for book titles.
37+
38+
## Deleting Books
39+
40+
Allows deleting books.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Add features.md
6+
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: commit
17+
empty: true
18+
message: Add the search feature
19+
20+
- type: commit
21+
empty: true
22+
message: Add the delete feature
23+
24+
- type: branch
25+
branch-name: feature-search
26+
- type: checkout
27+
branch-name: main
28+
- type: branch
29+
branch-name: feature-delete
30+
- type: checkout
31+
branch-name: main
32+
- type: branch
33+
branch-name: list
34+
35+
- type: new-file
36+
filename: features.md
37+
contents: |
38+
# Features
39+
40+
## Create Book
41+
42+
Allows creating one book at a time.
43+
44+
## Searching for Books
45+
46+
Allows searching for books by keywords.
47+
Works only for book titles.
48+
49+
## Deleting Books
50+
51+
Allows deleting books.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Add features.md
6+
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: commit
17+
empty: true
18+
message: Add the search feature
19+
20+
- type: commit
21+
empty: true
22+
message: Add the delete feature
23+
24+
- type: new-file
25+
filename: features.md
26+
contents: |
27+
# Features
28+
29+
## Searching for Books
30+
31+
Allows searching for books by keywords.
32+
Works only for book titles.
33+
34+
## Create Book
35+
36+
Allows creating one book at a time.
37+
38+
## Deleting Books
39+
40+
Allows deleting books.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Add features.md
6+
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: commit
17+
empty: true
18+
message: Add the search feature
19+
20+
- type: new-file
21+
filename: features.md
22+
contents: |
23+
# Features
24+
25+
## Create Book
26+
27+
Allows creating one book at a time.
28+
29+
## Searching for Books
30+
31+
Allows searching for books by keywords.
32+
Works only for book titles.
33+
34+
## Deleting Books
35+
36+
Allows deleting books.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Add features.md
6+
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: branch
17+
branch-name: feature-search
18+
- type: commit
19+
empty: true
20+
message: Feature search
21+
- type: checkout
22+
branch-name: main
23+
- type: merge
24+
branch-name: feature-search
25+
26+
- type: commit
27+
empty: true
28+
message: Add the delete feature
29+
30+
- type: new-file
31+
filename: features.md
32+
contents: |
33+
# Features
34+
35+
## Create Book
36+
37+
Allows creating one book at a time.
38+
39+
## Searching for Books
40+
41+
Allows searching for books by keywords.
42+
Works only for book titles.
43+
44+
## Deleting Books
45+
46+
Allows deleting books.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Add features.md
6+
id: start
7+
- type: commit
8+
empty: true
9+
message: Mention feature for creating books
10+
- type: tag
11+
tag-name: v1.0
12+
- type: commit
13+
empty: true
14+
message: Fix phrasing of heading
15+
16+
- type: commit
17+
empty: true
18+
message: Add the search feature!
19+
20+
- type: commit
21+
empty: true
22+
message: Add the delete feature
23+
24+
- type: new-file
25+
filename: features.md
26+
contents: |
27+
# Features
28+
29+
## Create Book
30+
31+
Allows creating one book at a time.
32+
33+
## Searching for Books
34+
35+
Allows searching for books by keywords.
36+
Works only for book titles.
37+
38+
## Deleting Books
39+
40+
Allows deleting books.
Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,73 @@
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_SEARCH_BRANCH_STILL_EXISTS,
5+
FEATURE_DELETE_BRANCH_STILL_EXISTS,
6+
FEATURES_FILE_CONTENT_INVALID,
7+
LIST_BRANCH_STILL_EXISTS,
8+
MISMATCH_COMMIT_MESSAGE,
9+
SQUASH_NOT_USED,
10+
verify,
11+
)
412

513
REPOSITORY_NAME = "mix-messy-graph"
614

715
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
816

917

1018
def test_base():
11-
with loader.load("specs/base.yml", "start"):
12-
pass
19+
with loader.load("specs/base.yml") as output:
20+
assert_output(output, GitAutograderStatus.SUCCESSFUL)
21+
22+
23+
def test_non_squash_merge_used():
24+
with loader.load("specs/non_squash_merge_used.yml") as output:
25+
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [SQUASH_NOT_USED])
26+
27+
28+
def test_wrong_commit_message():
29+
with loader.load("specs/wrong_commit_message.yml") as output:
30+
assert_output(
31+
output,
32+
GitAutograderStatus.UNSUCCESSFUL,
33+
[
34+
MISMATCH_COMMIT_MESSAGE.format(
35+
expected="Add the search feature", given="Add the search feature!"
36+
)
37+
],
38+
)
39+
40+
41+
def test_missing_commit():
42+
with loader.load("specs/missing_commit.yml") as output:
43+
assert_output(
44+
output,
45+
GitAutograderStatus.UNSUCCESSFUL,
46+
[
47+
MISMATCH_COMMIT_MESSAGE.format(
48+
expected="Add the delete feature", given="<Missing commit>"
49+
)
50+
],
51+
)
52+
53+
54+
def test_branches_not_deleted():
55+
with loader.load("specs/branches_not_deleted.yml") as output:
56+
assert_output(
57+
output,
58+
GitAutograderStatus.UNSUCCESSFUL,
59+
[
60+
FEATURE_SEARCH_BRANCH_STILL_EXISTS,
61+
FEATURE_DELETE_BRANCH_STILL_EXISTS,
62+
LIST_BRANCH_STILL_EXISTS,
63+
],
64+
)
65+
66+
67+
def test_features_content_invalid():
68+
with loader.load("specs/features_content_invalid.yml") as output:
69+
assert_output(
70+
output,
71+
GitAutograderStatus.UNSUCCESSFUL,
72+
[FEATURES_FILE_CONTENT_INVALID],
73+
)

mix_messy_graph/verify.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def ensure_str(val) -> str:
5555
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
5656
main_branch = exercise.repo.branches.branch("main")
5757
merge_commits = [c for c in main_branch.commits if len(c.parents) > 1]
58-
if len(merge_commits) > 0:
58+
merge_reflogs = [e for e in main_branch.reflog if "merge" in e.action]
59+
if merge_commits or merge_reflogs:
5960
raise exercise.wrong_answer([SQUASH_NOT_USED])
6061

6162
commit_messages = [ensure_str(c.commit.message) for c in main_branch.commits][::-1]

0 commit comments

Comments
 (0)