-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_skill.py
155 lines (139 loc) · 8.46 KB
/
test_skill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import os
from sure import expect
from pytlas.settings import CONFIG
from pytlas.testing import create_skill_agent
# Testing a pytlas skill is easy.
# Start by instantiating an agent trained only for this skill.
test_response = \
"""
Test
An Interactive Fiction by lekstonjm
Release 1 / Serial number 191109 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N)
World
Test room
You can see a Poster here.
"""
class TestInteractiveFictionkill:
def test_it_should_ask_for_game_saves_folder(self):
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.parse("play interactive fiction named Test.zblorb")
call = agent.model.on_ask.get_call()
expect(call.text).to.equal('Game saves folder has not been set. Your game saves will be writen in the current folder "{0}".\nDo you want continue?'.format(os.getcwd()))
def test_it_should_failed_to_find_stories_folder(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
call = agent.model.on_ask.get_call()
expect(call.text).to.equal('Stories folder has not been set. Stories will be load from the current folder "{0}".\nDo you want continue?'.format(os.getcwd()))
def test_it_should_failed_to_find_story(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named invalid.zblorb")
call = agent.model.on_answer.get_call()
expect(call.text).to.equal('Sorry, no story named {0} has been found in {1}.'.format('invalid.zblorb', test_stories_folder_path))
def test_it_should_failed_to_find_zvm(self):
test_zvm_path = os.path.join(os.path.dirname(__file__),'invalid_zvm')
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('zvm_path',test_zvm_path,section='interactive_fiction')
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
call = agent.model.on_answer.get_call()
expect(call.text).to.equal('Unable to start {0}'.format(test_zvm_path))
def test_it_should_launch_the_storie(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
call = agent.model.on_answer.get_call()
expect(call.text).to.equal(test_response.strip())
def test_it_should_display_hello_world(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
agent.parse('read the Poster')
call = agent.model.on_answer.get_call()
expect(call.text).to.equal("read the Poster\nHello world!")
def test_it_should_save_game(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
game_save_name = 'test_save'
game_save_filename = '{0}.{1}'.format(game_save_name, 'glksave')
game_save_path = os.path.join(test_game_saves_folder_path, game_save_filename)
if os.path.isfile(game_save_path):
os.remove(game_save_path)
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
agent.parse("save the game as {0}".format(game_save_name))
call = agent.model.on_answer.get_call()
is_file = os.path.isfile(game_save_path)
if is_file:
os.remove(game_save_path)
expect(is_file).to.equal(True)
expect(call.text).to.equal("save\n\nPlease enter a file name (without an extension): Ok.")
def test_it_should_failed_to_restore_saved_game(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
game_save_name = 'invalid_test_save'
game_save_filename = '{0}.{1}'.format(game_save_name, 'glksave')
game_save_path = os.path.join(test_game_saves_folder_path, game_save_filename)
if os.path.isfile(game_save_path):
os.remove(game_save_path)
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
agent.parse("restore the game {0}".format(game_save_name))
call = agent.model.on_answer.get_call()
expect(call.text).to.equal("restore\n\nPlease enter a file name (without an extension): Restore failed.")
def test_it_should_restore_saved_game(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
game_save_name = 'test_save'
game_save_filename = '{0}.{1}'.format(game_save_name, 'glksave')
game_save_path = os.path.join(test_game_saves_folder_path, game_save_filename)
if os.path.isfile(game_save_path):
os.remove(game_save_path)
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
agent.parse("save the game as {0}".format(game_save_name))
agent.parse("restore the game {0}".format(game_save_name))
call = agent.model.on_answer.get_call()
if os.path.isfile(game_save_path):
os.remove(game_save_path)
expect(call.text).to.equal("restore\n\nPlease enter a file name (without an extension): Ok.")
def test_it_should_quit_the_game(self):
test_game_saves_folder_path = os.path.join(os.path.dirname(__file__),'test')
test_stories_folder_path = os.path.join(os.path.dirname(__file__),'test/test.materials/Release')
agent = create_skill_agent(os.path.dirname(__file__), lang='en')
agent.settings.reset()
agent.settings.set('game_saves_folder',test_game_saves_folder_path,section='interactive_fiction')
agent.settings.set('stories_folder',test_stories_folder_path,section='interactive_fiction')
agent.parse("play interactive fiction named Test.zblorb")
agent.parse('quit the game')
call = agent.model.on_answer.get_call()
expect(call.text).to.equal('Goodbye')