Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 40e0ebe

Browse files
Add indentation + DAG test
1 parent beffc0a commit 40e0ebe

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

runestone/parsons/test/_sources/index.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,34 @@ Proof Blocks
147147
$c'(u) \ne c'(v)$ #tag:7;depends:6,3;
148148
=====
149149
$c'$ is a 2-coloring of $H$, so $H$ is 2-colorable. (end of proof) #tag:8;depends:7;
150+
151+
============
152+
Code DAG
153+
============
154+
155+
.. parsonsprob:: test_parsons_dag_indent
156+
:grader: dag
157+
158+
Test that indentation works with dag
159+
160+
.. code-block:: python
161+
162+
def foo:
163+
if True:
164+
return 2
165+
def bar:
166+
return 40
167+
print(foo() + bar())
168+
169+
-----
170+
def foo(): #tag:foo;depends:;
171+
=====
172+
if True: #tag:foo_if; depends:foo;
173+
=====
174+
return 2 #tag:f1; depends:foo_if;
175+
=====
176+
def bar(): #tag:bar;depends:;
177+
=====
178+
return 40 #tag:b1; depends:bar;
179+
=====
180+
print(foo() + bar()) #tag:asdf; depends: f1,b1;

runestone/parsons/test/test_parsons.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,58 @@ def drag_block(block, before_block):
356356
assert message.get_attribute("class") == "alert alert-info"
357357

358358

359+
def test_dag_grader_indentation(selenium_utils_get):
360+
selenium_utils_get.wait_until_ready("test_parsons_dag_indent")
361+
362+
source = selenium_utils_get.driver.find_element(By.ID, "parsons-7-source")
363+
answer = selenium_utils_get.driver.find_element(By.ID, "parsons-7-answer")
364+
checkme = selenium_utils_get.driver.find_element(By.ID, "parsons-7-check")
365+
reset = selenium_utils_get.driver.find_element(By.ID, "parsons-7-reset")
366+
367+
def drag_to_answer(blockNum):
368+
targetLoc = answer.location
369+
block = source.find_element(By.ID, "parsons-7-block-" + str(blockNum))
370+
xOffset = answer.location["x"] - block.location["x"] + 1
371+
yOffset = answer.location["y"] - block.location["y"] + 1
372+
ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(
373+
block, xOffset, yOffset
374+
).perform()
375+
376+
reset.click()
377+
378+
for i in range(5, -1, -1):
379+
element = source.find_element(By.ID, "parsons-7-block-" + str(i))
380+
drag_to_answer(i)
381+
checkme.click()
382+
383+
message = selenium_utils_get.driver.find_element(By.ID, "parsons-7-message")
384+
assert "alert-danger" in message.get_attribute("class")
385+
386+
checkme.click()
387+
b1 = answer.find_element(By.ID, "parsons-7-block-1")
388+
b2 = answer.find_element(By.ID, "parsons-7-block-2")
389+
b4 = answer.find_element(By.ID, "parsons-7-block-4")
390+
assert "indentRight" in b1.get_attribute("class")
391+
assert "indentRight" in b2.get_attribute("class")
392+
assert "indentRight" in b4.get_attribute("class")
393+
394+
ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(
395+
answer.find_element(By.ID, "parsons-7-block-1"), 10, 0
396+
).perform()
397+
ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(
398+
answer.find_element(By.ID, "parsons-7-block-2"), 60, 0
399+
).perform()
400+
ActionChains(selenium_utils_get.driver).drag_and_drop_by_offset(
401+
answer.find_element(By.ID, "parsons-7-block-4"), 10, 0
402+
).perform()
403+
wait_for_animation(selenium_utils_get, "#parsons-7-block-4")
404+
405+
checkme.click()
406+
assert "indentRight" not in b1.get_attribute("class")
407+
assert "indentRight" not in b2.get_attribute("class")
408+
assert "indentRight" not in b4.get_attribute("class")
409+
410+
359411
def wait_for_animation(selenium_utils, selector):
360412
while is_element_animated(selenium_utils, selector):
361413
time.sleep(0.5)

0 commit comments

Comments
 (0)