Skip to content

Commit b59236e

Browse files
committed
Overhaul verification logic to use commit messages
1 parent da82ec8 commit b59236e

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

sensors_revert/tests/specs/incorrect_readings.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ initialization:
55
empty: true
66
message: Empty commit
77
id: start
8+
- type: revert
9+
revision: dbac57019977296abff9e4f687f587c4a2d24f02
10+
- type: revert
11+
revision: 59505167b47f35c12d21bc61d731226b394a5341
812
- type: edit-file
913
filename: east.csv
1014
contents: 4821\n9304\n1578\n6042\n7189\n2463\n8931\n5710\n

sensors_revert/tests/test_verify.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
COMMITS_UNREVERTED,
66
COMMITS_REVERTED_WRONG_ORDER,
77
INCORRECT_READINGS,
8-
NO_REVERT_COMMIT,
98
verify,
109
)
1110

@@ -63,7 +62,7 @@ def test_no_revert_commit():
6362
assert_output(
6463
output,
6564
GitAutograderStatus.UNSUCCESSFUL,
66-
[NO_REVERT_COMMIT],
65+
[COMMITS_UNREVERTED],
6766
)
6867

6968

@@ -72,7 +71,7 @@ def test_only_jan_14_reverted():
7271
assert_output(
7372
output,
7473
GitAutograderStatus.UNSUCCESSFUL,
75-
[NO_REVERT_COMMIT],
74+
[COMMITS_UNREVERTED],
7675
)
7776

7877

@@ -81,5 +80,5 @@ def test_only_jan_13_reverted():
8180
assert_output(
8281
output,
8382
GitAutograderStatus.UNSUCCESSFUL,
84-
[NO_REVERT_COMMIT],
83+
[COMMITS_REVERTED_WRONG_ORDER],
8584
)

sensors_revert/verify.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
)
66

77
MISSING_FILE = "You are missing the {filename} file."
8-
COMMITS_UNREVERTED = "You have not reverted the commits yet!"
8+
COMMITS_UNREVERTED = "You have not reverted all the commits yet!"
99
COMMITS_REVERTED_WRONG_ORDER = "You have reverted the commits in the wrong order!"
1010
INCORRECT_READINGS = "The files contain the wrong readings!"
11-
NO_REVERT_COMMIT = "You have not performed the changes through revert commits!"
1211

1312
EXPECTED_EAST = (
1413
"4821\n9304\n1578\n6042\n7189\n2463\n8931\n5710\n4428\n3097\n8652\n1904\n7485\n6379\n5140\n9836\n2057\n4719\n3568\n8243\n"
@@ -23,14 +22,6 @@
2322
"5193\n8042\n6721\n4389\n2075\n9510\n3648\n7281\n5904\n1837\n4416\n9032\n7765\n6208\n3589\n8471\n2940\n1683\n7352\n5129\n"
2423
)
2524

26-
UNREVERTED_EAST = EXPECTED_EAST.replace("7485", "7285")
27-
UNREVERTED_NORTH = EXPECTED_NORTH.replace("8501", "8301")
28-
# Unreverted South and West are equivalent to expected South and West
29-
30-
# Reverting East and North in the wrong order leads to the same result
31-
WRONG_ORDER_REVERT_SOUTH = EXPECTED_SOUTH.replace("4530", "4330")
32-
WRONG_ORDER_REVERT_WEST = EXPECTED_WEST.replace("3648", "3638")
33-
3425

3526
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
3627
comments = []
@@ -62,24 +53,28 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
6253
if comments:
6354
raise exercise.wrong_answer(comments)
6455

65-
if (east_contents == UNREVERTED_EAST
66-
and north_contents == UNREVERTED_NORTH):
56+
branch = exercise.repo.branches.branch("main")
57+
commit_messages = [str(c.commit.message.strip()) for c in branch.commits]
58+
commit_messages.reverse()
59+
60+
reverted_14th = False
61+
reverted_13th = False
62+
for m in commit_messages[-4:]:
63+
if not reverted_14th and 'Revert "Record data for Jan 14"' in m:
64+
reverted_14th = True
65+
if not reverted_13th and 'Revert "Record data for Jan 13"' in m:
66+
if not reverted_14th:
67+
raise exercise.wrong_answer([COMMITS_REVERTED_WRONG_ORDER])
68+
reverted_13th = True
69+
break
70+
71+
if not (reverted_14th and reverted_13th):
6772
raise exercise.wrong_answer([COMMITS_UNREVERTED])
6873

69-
if (south_contents == WRONG_ORDER_REVERT_SOUTH
70-
and west_contents == WRONG_ORDER_REVERT_WEST):
71-
raise exercise.wrong_answer([COMMITS_REVERTED_WRONG_ORDER])
72-
7374
if not (east_contents == EXPECTED_EAST
7475
and north_contents == EXPECTED_NORTH
7576
and south_contents == EXPECTED_SOUTH
7677
and west_contents == EXPECTED_WEST):
7778
raise exercise.wrong_answer([INCORRECT_READINGS])
7879

79-
commits = exercise.repo.branches.branch("main").commits
80-
81-
if ("Revert" not in commits[0].commit.message
82-
or "Revert" not in commits[1].commit.message):
83-
raise exercise.wrong_answer([NO_REVERT_COMMIT])
84-
8580
return exercise.to_output(["Good work reverting commits!"], GitAutograderStatus.SUCCESSFUL)

0 commit comments

Comments
 (0)