Skip to content

Commit 17e8e36

Browse files
committed
[branch-previous] Migrate tests
1 parent 69afb99 commit 17e8e36

11 files changed

+276
-495
lines changed

branch_previous/test_verify.py

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
from exercise_utils.test import GitAutograderTestLoader, assert_output
2+
from git_autograder.status import GitAutograderStatus
3+
4+
from .verify import (
5+
MISSING_BRANCH,
6+
MISSING_COMMIT,
7+
WRONG_CONTENT,
8+
WRONG_START,
9+
verify,
10+
)
11+
12+
REPOSITORY_NAME = "branch-previous"
13+
14+
loader = GitAutograderTestLoader(REPOSITORY_NAME, verify)
15+
16+
17+
def test_base():
18+
with loader.start() as (test, rs):
19+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
20+
rs.git.add(all=True)
21+
rs.git.commit(message="Describe night")
22+
23+
rs.files.append("story.txt", "I was alone in my room.")
24+
rs.git.add(all=True)
25+
rs.git.commit(message="Describe location")
26+
27+
rs.files.append("story.txt", "I heard a strange noise.")
28+
rs.git.add(all=True)
29+
rs.git.commit(message="Mention noise")
30+
31+
rs.git.checkout("visitor-line", start_point="HEAD~1", branch=True)
32+
33+
rs.files.append("story.txt", "I heard someone knocking at the door.")
34+
rs.git.add(all=True)
35+
rs.git.commit(message="Mention knocking")
36+
37+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
38+
39+
rs.files.append("story.txt", "I fell asleep on the couch.")
40+
rs.git.add(all=True)
41+
rs.git.commit(message="Mention sleeping")
42+
43+
output = test.run()
44+
assert_output(output, GitAutograderStatus.SUCCESSFUL)
45+
46+
47+
def test_visitor_missing_branch():
48+
with loader.start() as (test, rs):
49+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
50+
rs.git.add(all=True)
51+
rs.git.commit(message="Describe night")
52+
53+
rs.files.append("story.txt", "I was alone in my room.")
54+
rs.git.add(all=True)
55+
rs.git.commit(message="Describe location")
56+
57+
rs.files.append("story.txt", "I heard a strange noise.")
58+
rs.git.add(all=True)
59+
rs.git.commit(message="Mention noise")
60+
61+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
62+
63+
rs.files.append("story.txt", "I fell asleep on the couch.")
64+
rs.git.add(all=True)
65+
rs.git.commit(message="Mention sleeping")
66+
67+
output = test.run()
68+
assert_output(
69+
output,
70+
GitAutograderStatus.UNSUCCESSFUL,
71+
[MISSING_BRANCH.format(branch_name="visitor-line")],
72+
)
73+
74+
75+
def test_sleep_missing_branch():
76+
with loader.start() as (test, rs):
77+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
78+
rs.git.add(all=True)
79+
rs.git.commit(message="Describe night")
80+
81+
rs.files.append("story.txt", "I was alone in my room.")
82+
rs.git.add(all=True)
83+
rs.git.commit(message="Describe location")
84+
85+
rs.files.append("story.txt", "I heard a strange noise.")
86+
rs.git.add(all=True)
87+
rs.git.commit(message="Mention noise")
88+
89+
rs.git.checkout("visitor-line", start_point="HEAD~1", branch=True)
90+
91+
rs.files.append("story.txt", "I heard someone knocking at the door.")
92+
rs.git.add(all=True)
93+
rs.git.commit(message="Mention knocking")
94+
95+
output = test.run()
96+
assert_output(
97+
output,
98+
GitAutograderStatus.UNSUCCESSFUL,
99+
[MISSING_BRANCH.format(branch_name="sleep-line")],
100+
)
101+
102+
103+
def test_visitor_wrong_start_first_commit():
104+
with loader.start() as (test, rs):
105+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
106+
rs.git.add(all=True)
107+
rs.git.commit(message="Describe night")
108+
109+
rs.files.append("story.txt", "I was alone in my room.")
110+
rs.git.add(all=True)
111+
rs.git.commit(message="Describe location")
112+
113+
rs.files.append("story.txt", "I heard a strange noise.")
114+
rs.git.add(all=True)
115+
rs.git.commit(message="Mention noise")
116+
117+
rs.git.checkout("visitor-line", start_point="HEAD~2", branch=True)
118+
119+
rs.files.append("story.txt", "I heard someone knocking at the door.")
120+
rs.git.add(all=True)
121+
rs.git.commit(message="Mention knocking")
122+
123+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
124+
125+
rs.files.append("story.txt", "I fell asleep on the couch.")
126+
rs.git.add(all=True)
127+
rs.git.commit(message="Mention sleeping")
128+
129+
output = test.run()
130+
assert_output(
131+
output,
132+
GitAutograderStatus.UNSUCCESSFUL,
133+
[WRONG_START.format(branch_name="visitor-line")],
134+
)
135+
136+
137+
def test_visitor_wrong_start_third_commit():
138+
with loader.start() as (test, rs):
139+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
140+
rs.git.add(all=True)
141+
rs.git.commit(message="Describe night")
142+
143+
rs.files.append("story.txt", "I was alone in my room.")
144+
rs.git.add(all=True)
145+
rs.git.commit(message="Describe location")
146+
147+
rs.files.append("story.txt", "I heard a strange noise.")
148+
rs.git.add(all=True)
149+
rs.git.commit(message="Mention noise")
150+
151+
rs.git.checkout("visitor-line", start_point="HEAD", branch=True)
152+
153+
rs.files.append("story.txt", "I heard someone knocking at the door.")
154+
rs.git.add(all=True)
155+
rs.git.commit(message="Mention knocking")
156+
157+
rs.git.checkout("sleep-line", start_point="HEAD~2", branch=True)
158+
159+
rs.files.append("story.txt", "I fell asleep on the couch.")
160+
rs.git.add(all=True)
161+
rs.git.commit(message="Mention sleeping")
162+
163+
output = test.run()
164+
assert_output(
165+
output,
166+
GitAutograderStatus.UNSUCCESSFUL,
167+
[WRONG_START.format(branch_name="visitor-line")],
168+
)
169+
170+
171+
def test_visitor_wrong_content():
172+
with loader.start() as (test, rs):
173+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
174+
rs.git.add(all=True)
175+
rs.git.commit(message="Describe night")
176+
177+
rs.files.append("story.txt", "I was alone in my room.")
178+
rs.git.add(all=True)
179+
rs.git.commit(message="Describe location")
180+
181+
rs.files.append("story.txt", "I heard a strange noise.")
182+
rs.git.add(all=True)
183+
rs.git.commit(message="Mention noise")
184+
185+
rs.git.checkout("visitor-line", start_point="HEAD~1", branch=True)
186+
187+
rs.files.append("story.txt", "Wrong content here.")
188+
rs.git.add(all=True)
189+
rs.git.commit(message="Mention knocking")
190+
191+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
192+
193+
rs.files.append("story.txt", "I fell asleep on the couch.")
194+
rs.git.add(all=True)
195+
rs.git.commit(message="Mention sleeping")
196+
197+
output = test.run()
198+
assert_output(
199+
output,
200+
GitAutograderStatus.UNSUCCESSFUL,
201+
[
202+
WRONG_CONTENT.format(
203+
branch_name="visitor-line",
204+
expected_content="I heard someone knocking at the door.",
205+
)
206+
],
207+
)
208+
209+
210+
def test_sleep_wrong_content():
211+
with loader.start() as (test, rs):
212+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
213+
rs.git.add(all=True)
214+
rs.git.commit(message="Describe night")
215+
216+
rs.files.append("story.txt", "I was alone in my room.")
217+
rs.git.add(all=True)
218+
rs.git.commit(message="Describe location")
219+
220+
rs.files.append("story.txt", "I heard a strange noise.")
221+
rs.git.add(all=True)
222+
rs.git.commit(message="Mention noise")
223+
224+
rs.git.checkout("visitor-line", start_point="HEAD~1", branch=True)
225+
226+
rs.files.append("story.txt", "I heard someone knocking at the door.")
227+
rs.git.add(all=True)
228+
rs.git.commit(message="Mention knocking")
229+
230+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
231+
232+
rs.files.append("story.txt", "Wrong content here.")
233+
rs.git.add(all=True)
234+
rs.git.commit(message="Mention sleeping")
235+
236+
output = test.run()
237+
assert_output(
238+
output,
239+
GitAutograderStatus.UNSUCCESSFUL,
240+
[
241+
WRONG_CONTENT.format(
242+
branch_name="sleep-line",
243+
expected_content="I fell asleep on the couch.",
244+
)
245+
],
246+
)
247+
248+
249+
def test_visitor_missing_commit():
250+
with loader.start() as (test, rs):
251+
rs.files.create_or_update("story.txt", "It was a dark and stormy night.")
252+
rs.git.add(all=True)
253+
rs.git.commit(message="Describe night")
254+
255+
rs.files.append("story.txt", "I was alone in my room.")
256+
rs.git.add(all=True)
257+
rs.git.commit(message="Describe location")
258+
259+
rs.files.append("story.txt", "I heard a strange noise.")
260+
rs.git.add(all=True)
261+
rs.git.commit(message="Mention noise")
262+
263+
rs.git.checkout("visitor-line", start_point="HEAD~1", branch=True)
264+
265+
rs.git.checkout("sleep-line", start_point="HEAD~1", branch=True)
266+
267+
rs.files.append("story.txt", "I fell asleep on the couch.")
268+
rs.git.add(all=True)
269+
rs.git.commit(message="Mention sleeping")
270+
271+
output = test.run()
272+
assert_output(
273+
output,
274+
GitAutograderStatus.UNSUCCESSFUL,
275+
[MISSING_COMMIT.format(branch_name="visitor-line")],
276+
)

branch_previous/tests/__init__.py

Whitespace-only changes.

branch_previous/tests/specs/base.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

branch_previous/tests/specs/sleep_missing_branch.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)