Skip to content

Commit 6613a94

Browse files
committed
Update visits and shortcuts tests for YS2.
1 parent 070aa42 commit 6613a94

11 files changed

Lines changed: 138 additions & 35 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
id,node,lineNumber,tags

examples/yarn2/shortcuts.csv

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id,text,file,node,lineNumber
2+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-0,This is a test of shortcut functionality.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,3
3+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-1,Option 1,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,5
4+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-2,Option 1 selected.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,6
5+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-3,Option 2,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,7
6+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-4,Option 2 selected.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,8
7+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-5,Option 3,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,9
8+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-6,Option 4,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,10
9+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn-Start-7,This is the last line.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/shortcuts.yarn,Start,12

examples/yarn2/shortcuts.yarn

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
title: Start
2+
---
3+
This is a test of shortcut functionality.
4+
5+
-> Option 1
6+
Option 1 selected.
7+
-> Option 2
8+
Option 2 selected.
9+
-> Option 3
10+
-> Option 4
11+
12+
This is the last line.
13+
===

examples/yarn2/shortcuts.yarnc

1.1 KB
Binary file not shown.

examples/yarn2/visits-metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
id,node,lineNumber,tags

examples/yarn2/visits.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id,text,file,node,lineNumber
2+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/visits.yarn-loop-0,This is the loop node.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/visits.yarn,loop,8
3+
line:/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/visits.yarn-end-1,This is the end.,/Users/sweaver/Git/YarnRunner-Python/examples/yarn2/visits.yarn,end,19

examples/yarn2/visits.yarn

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
title: Start
2+
---
3+
<<jump loop>>
4+
===
5+
title: loop
6+
---
7+
8+
This is the loop node.
9+
10+
<<if $visits_loop > 3>>
11+
<<jump end>>
12+
<<endif>>
13+
14+
<<jump loop>>
15+
===
16+
title: end
17+
---
18+
19+
This is the end.
20+
===

examples/yarn2/visits.yarnc

465 Bytes
Binary file not shown.

tests/test_shortcuts.py

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
import os
22
from .context import YarnRunner
33

4-
compiled_yarn_f = open(os.path.join(os.path.dirname(
4+
compiled_yarn_f1 = open(os.path.join(os.path.dirname(
55
__file__), '../examples/yarn1/shortcuts.yarnc'), 'rb')
6-
names_csv_f = open(os.path.join(os.path.dirname(
6+
names_csv_f1 = open(os.path.join(os.path.dirname(
77
__file__), '../examples/yarn1/shortcuts.csv'), 'r')
8+
compiled_yarn_f2 = open(os.path.join(os.path.dirname(
9+
__file__), '../examples/yarn2/shortcuts.yarnc'), 'rb')
10+
names_csv_f2 = open(os.path.join(os.path.dirname(
11+
__file__), '../examples/yarn2/shortcuts.csv'), 'r')
812

9-
runner = YarnRunner(compiled_yarn_f, names_csv_f)
13+
runner1 = YarnRunner(compiled_yarn_f1, names_csv_f1)
14+
runner2 = YarnRunner(compiled_yarn_f2, names_csv_f2)
1015

1116

12-
def test_start_node_text():
13-
assert "This is a test of shortcut functionality." == runner.get_line()
14-
assert not runner.has_line()
15-
assert not runner.finished
17+
def test_start_node_text1():
18+
assert "This is a test of shortcut functionality." == runner1.get_line()
19+
assert not runner1.has_line()
20+
assert not runner1.finished
1621

1722

18-
def test_start_node_choices():
19-
choices = runner.get_choices()
23+
def test_start_node_choices1():
24+
choices = runner1.get_choices()
25+
26+
assert len(choices) == 4
27+
assert choices[0]["text"] == "Option 1"
28+
assert choices[1]["text"] == "Option 2"
29+
assert choices[2]["text"] == "Option 3"
30+
assert choices[3]["text"] == "Option 4"
31+
32+
33+
def test_shortcuts1():
34+
runner1.choose(0)
35+
36+
assert "Option 1 selected." == runner1.get_line()
37+
assert runner1.has_line()
38+
assert "This is the last line." == runner1.get_line()
39+
assert not runner1.has_line()
40+
assert runner1.finished
41+
assert runner1.current_node == 'Start'
42+
43+
44+
def test_start_node_text2():
45+
assert "This is a test of shortcut functionality." == runner2.get_line()
46+
assert not runner2.has_line()
47+
assert not runner2.finished
48+
49+
50+
def test_start_node_choices2():
51+
choices = runner2.get_choices()
2052

2153
assert len(choices) == 4
2254
assert choices[0]["text"] == "Option 1"
@@ -26,11 +58,11 @@ def test_start_node_choices():
2658

2759

2860
def test_shortcuts():
29-
runner.choose(0)
30-
31-
assert "Option 1 selected." == runner.get_line()
32-
assert runner.has_line()
33-
assert "This is the last line." == runner.get_line()
34-
assert not runner.has_line()
35-
assert runner.finished
36-
assert runner.current_node == 'Start'
61+
runner2.choose(0)
62+
63+
assert "Option 1 selected." == runner2.get_line()
64+
assert runner2.has_line()
65+
assert "This is the last line." == runner2.get_line()
66+
assert not runner2.has_line()
67+
assert runner2.finished
68+
assert runner2.current_node == 'Start'

tests/test_variables.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ def test_variables():
1616
assert runner.variables["$value_float"] == 1.25
1717
assert runner.variables["$value_bool"] == True
1818
assert runner.variables["$value_null"] is None
19+
20+
# TODO, the variables.yarnc wouldn't compile under YSC 2.0.1-a2eff4c

0 commit comments

Comments
 (0)