Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions view_commits/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"exercise_name": "view-commits",
"tags": [
"git-diff",
"git-show"
],
"requires_git": true,
"requires_github": true,
"base_files": {
"answers.txt": "answers.txt"
},
"exercise_repo": {
"repo_type": "remote",
"repo_name": "duty-roster",
"repo_title": "gm-duty-roster",
"create_fork": false,
"init": true
}
}
1 change: 1 addition & 0 deletions view_commits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See https://git-mastery.github.io/lessons/show/exercise-view-commits.html
Empty file added view_commits/__init__.py
Empty file.
1 change: 1 addition & 0 deletions view_commits/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def setup(verbose: bool = False): ...
16 changes: 16 additions & 0 deletions view_commits/res/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Q: In February, who was replaced in the Wednesday duty roster?
A:

Q: In February, who joined the Tuesday duty roster?
A:

Q: In April, what were the new names added to the duty rosters? Remove/add extra rows where appropriate.
A:
- name1
- name2

Q: In January, who were in the Tuesday duty roster? Remove/add extra rows where appropriate.
A:
- name1
- name2

Empty file added view_commits/tests/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions view_commits/tests/specs/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
182 changes: 182 additions & 0 deletions view_commits/tests/test_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
from git_autograder import GitAutograderStatus, GitAutograderTestLoader, assert_output
from git_autograder.answers.rules import (
HasExactValueRule,
HasExactListRule,
NotEmptyRule,
ContainsListRule,
)
from ..verify import QUESTION_ONE, QUESTION_TWO, QUESTION_THREE, QUESTION_FOUR, verify

REPOSITORY_NAME = "view-commits"

loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)

CORRECT_QUESTION_ONE = "Eric"
CORRECT_QUESTION_TWO = "Bruce"
CORRECT_QUESTION_THREE = """
- Beth
- Betsy
- Daisy
"""
CORRECT_QUESTION_FOUR = "- Charlie"

WRONG_QUESTION_ONE = "Ergodic"
WRONG_QUESTION_TWO = "Bru"
INCOMPLETE_QUESTION_THREE = """
- Betsy
- Daisy
"""
WRONG_QUESTION_THREE = """
- Betsy
- Bruce
- Daisy
"""
EXTRA_QUESTION_THREE = """
- Betsy
- Beth
- Eric
- Daisy
"""
WRONG_QUESTION_FOUR = "- Dave"


def test_no_answers():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: "",
QUESTION_TWO: "",
QUESTION_THREE: "",
QUESTION_FOUR: "",
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
NotEmptyRule.EMPTY.format(question=QUESTION_ONE),
NotEmptyRule.EMPTY.format(question=QUESTION_TWO),
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
NotEmptyRule.EMPTY.format(question=QUESTION_FOUR),
],
)


def test_incomplete_answer():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: "",
QUESTION_FOUR: "",
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
NotEmptyRule.EMPTY.format(question=QUESTION_THREE),
NotEmptyRule.EMPTY.format(question=QUESTION_FOUR),
],
)


def test_wrong_question_one():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: WRONG_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: CORRECT_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_ONE)],
)


def test_wrong_question_two():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: WRONG_QUESTION_TWO,
QUESTION_THREE: CORRECT_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactValueRule.NOT_EXACT.format(question=QUESTION_TWO)],
)


def test_incomplete_question_three():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: INCOMPLETE_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[HasExactListRule.INCORRECT_UNORDERED.format(question=QUESTION_THREE)],
)


def test_wrong_question_three():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: WRONG_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
HasExactListRule.INCORRECT_UNORDERED.format(question=QUESTION_THREE),
],
)


def test_wrong_question_three_extra_answer():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: EXTRA_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[ContainsListRule.INVALID_ITEM.format(question=QUESTION_THREE)],
)


def test_valid_answers():
with loader.load(
"specs/base.yml",
mock_answers={
QUESTION_ONE: CORRECT_QUESTION_ONE,
QUESTION_TWO: CORRECT_QUESTION_TWO,
QUESTION_THREE: CORRECT_QUESTION_THREE,
QUESTION_FOUR: CORRECT_QUESTION_FOUR,
},
) as output:
assert_output(output, GitAutograderStatus.SUCCESSFUL)
48 changes: 48 additions & 0 deletions view_commits/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from git_autograder import (
GitAutograderOutput,
GitAutograderExercise,
GitAutograderStatus,
)
from git_autograder.answers.rules import (
HasExactValueRule,
NotEmptyRule,
HasExactListRule,
ContainsListRule,
)

QUESTION_ONE = "In February, who was replaced in the Wednesday duty roster?"
QUESTION_TWO = "In February, who joined the Tuesday duty roster?"
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."
QUESTION_FOUR = "In January, who were in the Tuesday duty roster? Give the list of names as one line, separated by spaces."


def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
(
exercise.answers.add_validation(QUESTION_ONE, NotEmptyRule())
.add_validation(QUESTION_ONE, HasExactValueRule("Eric", is_case_sensitive=True))
.add_validation(
QUESTION_TWO,
NotEmptyRule(),
HasExactValueRule("Bruce", is_case_sensitive=True),
)
.add_validation(
QUESTION_THREE,
NotEmptyRule(),
HasExactListRule(["Betsy", "Beth", "Daisy"], is_case_sensitive=True),
ContainsListRule(
["Betsy", "Beth", "Daisy"], subset=True, is_case_sensitive=True
),
)
.add_validation(
QUESTION_FOUR,
NotEmptyRule(),
HasExactListRule(["Charlie"], is_case_sensitive=True),
ContainsListRule(["Charlie"], subset=True, is_case_sensitive=True),
)
.validate()
)

return exercise.to_output(
["Great work in viewing and understanding the diff of a specific commit!"],
GitAutograderStatus.SUCCESSFUL,
)