Skip to content

Commit 998c55b

Browse files
SAN-MUYUNjovnc
andauthored
[view-commits] Implement exercise T4L1/view-commits (#102)
# Exercise Review ## Exercise Discussion #60 ## Checklist - [ ] If you require a new remote repository on the `Git-Mastery` organization, have you [created a request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.md) for it? - [x] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme? - [x] Have you tested the download script using `test-download.sh`? - [x] Have you verified that this exercise does not already exist or is not currently in review? - [ ] Did you introduce a new grading mechanism that should belong to [`git-autograder`](https://github.com/git-mastery/git-autograder)? - [ ] Did you introduce a new dependency that should belong to [`app`](https://github.com/git-mastery/app)? --------- Co-authored-by: jovnc <[email protected]>
1 parent c8c8696 commit 998c55b

File tree

9 files changed

+273
-0
lines changed

9 files changed

+273
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"exercise_name": "view-commits",
3+
"tags": [
4+
"git-diff",
5+
"git-show"
6+
],
7+
"requires_git": true,
8+
"requires_github": true,
9+
"base_files": {
10+
"answers.txt": "answers.txt"
11+
},
12+
"exercise_repo": {
13+
"repo_type": "remote",
14+
"repo_name": "duty-roster",
15+
"repo_title": "gm-duty-roster",
16+
"create_fork": false,
17+
"init": true
18+
}
19+
}

view_commits/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://git-mastery.github.io/lessons/show/exercise-view-commits.html

view_commits/__init__.py

Whitespace-only changes.

view_commits/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def setup(verbose: bool = False): ...

view_commits/res/answers.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Q: In February, who was replaced in the Wednesday duty roster?
2+
A:
3+
4+
Q: In February, who joined the Tuesday duty roster?
5+
A:
6+
7+
Q: In April, what were the new names added to the duty rosters? Remove/add extra rows where appropriate.
8+
A:
9+
- name1
10+
- name2
11+
12+
Q: In January, who were in the Tuesday duty roster? Remove/add extra rows where appropriate.
13+
A:
14+
- name1
15+
- name2
16+

view_commits/tests/__init__.py

Whitespace-only changes.

view_commits/tests/specs/base.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start

view_commits/tests/test_verify.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
from git_autograder import GitAutograderStatus, GitAutograderTestLoader, assert_output
2+
from git_autograder.answers.rules import (
3+
HasExactValueRule,
4+
HasExactListRule,
5+
NotEmptyRule,
6+
ContainsListRule,
7+
)
8+
from ..verify import QUESTION_ONE, QUESTION_TWO, QUESTION_THREE, QUESTION_FOUR, verify
9+
10+
REPOSITORY_NAME = "view-commits"
11+
12+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
13+
14+
CORRECT_QUESTION_ONE = "Eric"
15+
CORRECT_QUESTION_TWO = "Bruce"
16+
CORRECT_QUESTION_THREE = """
17+
- Beth
18+
- Betsy
19+
- Daisy
20+
"""
21+
CORRECT_QUESTION_FOUR = "- Charlie"
22+
23+
WRONG_QUESTION_ONE = "Ergodic"
24+
WRONG_QUESTION_TWO = "Bru"
25+
INCOMPLETE_QUESTION_THREE = """
26+
- Betsy
27+
- Daisy
28+
"""
29+
WRONG_QUESTION_THREE = """
30+
- Betsy
31+
- Bruce
32+
- Daisy
33+
"""
34+
EXTRA_QUESTION_THREE = """
35+
- Betsy
36+
- Beth
37+
- Eric
38+
- Daisy
39+
"""
40+
WRONG_QUESTION_FOUR = "- Dave"
41+
42+
43+
def test_no_answers():
44+
with loader.load(
45+
"specs/base.yml",
46+
mock_answers={
47+
QUESTION_ONE: "",
48+
QUESTION_TWO: "",
49+
QUESTION_THREE: "",
50+
QUESTION_FOUR: "",
51+
},
52+
) as output:
53+
assert_output(
54+
output,
55+
GitAutograderStatus.UNSUCCESSFUL,
56+
[
57+
NotEmptyRule.EMPTY.format(question=QUESTION_ONE),
58+
NotEmptyRule.EMPTY.format(question=QUESTION_TWO),
59+
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
60+
NotEmptyRule.EMPTY.format(question=QUESTION_FOUR),
61+
],
62+
)
63+
64+
65+
def test_incomplete_answer():
66+
with loader.load(
67+
"specs/base.yml",
68+
mock_answers={
69+
QUESTION_ONE: CORRECT_QUESTION_ONE,
70+
QUESTION_TWO: CORRECT_QUESTION_TWO,
71+
QUESTION_THREE: "",
72+
QUESTION_FOUR: "",
73+
},
74+
) as output:
75+
assert_output(
76+
output,
77+
GitAutograderStatus.UNSUCCESSFUL,
78+
[
79+
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
80+
NotEmptyRule.EMPTY.format(question=QUESTION_FOUR),
81+
],
82+
)
83+
84+
85+
def test_wrong_question_one():
86+
with loader.load(
87+
"specs/base.yml",
88+
mock_answers={
89+
QUESTION_ONE: WRONG_QUESTION_ONE,
90+
QUESTION_TWO: CORRECT_QUESTION_TWO,
91+
QUESTION_THREE: CORRECT_QUESTION_THREE,
92+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
93+
},
94+
) as output:
95+
assert_output(
96+
output,
97+
GitAutograderStatus.UNSUCCESSFUL,
98+
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_ONE)],
99+
)
100+
101+
102+
def test_wrong_question_two():
103+
with loader.load(
104+
"specs/base.yml",
105+
mock_answers={
106+
QUESTION_ONE: CORRECT_QUESTION_ONE,
107+
QUESTION_TWO: WRONG_QUESTION_TWO,
108+
QUESTION_THREE: CORRECT_QUESTION_THREE,
109+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
110+
},
111+
) as output:
112+
assert_output(
113+
output,
114+
GitAutograderStatus.UNSUCCESSFUL,
115+
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_TWO)],
116+
)
117+
118+
119+
def test_incomplete_question_three():
120+
with loader.load(
121+
"specs/base.yml",
122+
mock_answers={
123+
QUESTION_ONE: CORRECT_QUESTION_ONE,
124+
QUESTION_TWO: CORRECT_QUESTION_TWO,
125+
QUESTION_THREE: INCOMPLETE_QUESTION_THREE,
126+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
127+
},
128+
) as output:
129+
assert_output(
130+
output,
131+
GitAutograderStatus.UNSUCCESSFUL,
132+
[HasExactListRule.INCORRECT_UNORDERED.format(question=QUESTION_THREE)],
133+
)
134+
135+
136+
def test_wrong_question_three():
137+
with loader.load(
138+
"specs/base.yml",
139+
mock_answers={
140+
QUESTION_ONE: CORRECT_QUESTION_ONE,
141+
QUESTION_TWO: CORRECT_QUESTION_TWO,
142+
QUESTION_THREE: WRONG_QUESTION_THREE,
143+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
144+
},
145+
) as output:
146+
assert_output(
147+
output,
148+
GitAutograderStatus.UNSUCCESSFUL,
149+
[
150+
HasExactListRule.INCORRECT_UNORDERED.format(question=QUESTION_THREE),
151+
],
152+
)
153+
154+
155+
def test_wrong_question_three_extra_answer():
156+
with loader.load(
157+
"specs/base.yml",
158+
mock_answers={
159+
QUESTION_ONE: CORRECT_QUESTION_ONE,
160+
QUESTION_TWO: CORRECT_QUESTION_TWO,
161+
QUESTION_THREE: EXTRA_QUESTION_THREE,
162+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
163+
},
164+
) as output:
165+
assert_output(
166+
output,
167+
GitAutograderStatus.UNSUCCESSFUL,
168+
[ContainsListRule.INVALID_ITEM.format(question=QUESTION_THREE)],
169+
)
170+
171+
172+
def test_valid_answers():
173+
with loader.load(
174+
"specs/base.yml",
175+
mock_answers={
176+
QUESTION_ONE: CORRECT_QUESTION_ONE,
177+
QUESTION_TWO: CORRECT_QUESTION_TWO,
178+
QUESTION_THREE: CORRECT_QUESTION_THREE,
179+
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
180+
},
181+
) as output:
182+
assert_output(output, GitAutograderStatus.SUCCESSFUL)

view_commits/verify.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from git_autograder import (
2+
GitAutograderOutput,
3+
GitAutograderExercise,
4+
GitAutograderStatus,
5+
)
6+
from git_autograder.answers.rules import (
7+
HasExactValueRule,
8+
NotEmptyRule,
9+
HasExactListRule,
10+
ContainsListRule,
11+
)
12+
13+
QUESTION_ONE = "In February, who was replaced in the Wednesday duty roster?"
14+
QUESTION_TWO = "In February, who joined the Tuesday duty roster?"
15+
QUESTION_THREE = "In April, what were the new names added to the duty rosters? Give the list of names as one line, separated by spaces."
16+
QUESTION_FOUR = "In January, who were in the Tuesday duty roster? Give the list of names as one line, separated by spaces."
17+
18+
19+
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
20+
(
21+
exercise.answers.add_validation(QUESTION_ONE, NotEmptyRule())
22+
.add_validation(QUESTION_ONE, HasExactValueRule("Eric", is_case_sensitive=True))
23+
.add_validation(
24+
QUESTION_TWO,
25+
NotEmptyRule(),
26+
HasExactValueRule("Bruce", is_case_sensitive=True),
27+
)
28+
.add_validation(
29+
QUESTION_THREE,
30+
NotEmptyRule(),
31+
HasExactListRule(["Betsy", "Beth", "Daisy"], is_case_sensitive=True),
32+
ContainsListRule(
33+
["Betsy", "Beth", "Daisy"], subset=True, is_case_sensitive=True
34+
),
35+
)
36+
.add_validation(
37+
QUESTION_FOUR,
38+
NotEmptyRule(),
39+
HasExactListRule(["Charlie"], is_case_sensitive=True),
40+
ContainsListRule(["Charlie"], subset=True, is_case_sensitive=True),
41+
)
42+
.validate()
43+
)
44+
45+
return exercise.to_output(
46+
["Great work in viewing and understanding the diff of a specific commit!"],
47+
GitAutograderStatus.SUCCESSFUL,
48+
)

0 commit comments

Comments
 (0)