"dependencies": [
"What is your quest?"
]
+ },
+ {
+ "class": "ScriptQuestion",
+ "interpreter": "sh",
+ "prompt": "list all the files in the current directory",
+ "answer": "ls",
+ "setup": [
+ "touch file-1 file-2 file-3"
+ ],
+ "help": "http://pubs.opengroup.org/onlinepubs/009696699/idx/utilities.html"
}
]
}
return self.normalize(answer) == self.normalize(self.answer)
+class ScriptQuestion (Question):
+ _state_attributes = Question._state_attributes + [
+ 'interpreter',
+ 'setup',
+ 'teardown',
+ ]
+
+ def __setstate__(self, state):
+ if 'interpreter' not in state:
+ state['interpreter'] = 'sh' # POSIX-compatible shell
+ for key in ['setup', 'teardown']:
+ if key not in state:
+ state[key] = []
+ super(ScriptQuestion, self).__setstate__(state)
+
+ def check(self, answer):
+ script = '\n'.join(self.setup + [answer] + self.teardown)
+ raise ValueError(script)
+
+
for name,obj in list(locals().items()):
if name.startswith('_'):
continue