1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
1
# Copyright (C) 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
194
195
self.output_checker = doctest.OutputChecker()
195
196
self.check_options = doctest.ELLIPSIS
197
def run_script(self, test_case, text, null_output_matches_anything=False):
198
def run_script(self, test_case, text):
198
199
"""Run a shell-like script as a test.
200
201
:param test_case: A TestCase instance that should provide the fail(),
202
203
attribute used as a jail root.
204
205
:param text: A shell-like script (see _script_to_commands for syntax).
206
:param null_output_matches_anything: For commands with no specified
207
output, ignore any output that does happen, including output on
210
self.null_output_matches_anything = null_output_matches_anything
211
207
for cmd, input, output, error in _script_to_commands(text):
212
208
self.run_command(test_case, cmd, input, output, error)
216
212
method = getattr(self, mname, None)
217
213
if method is None:
218
214
raise SyntaxError('Command not found "%s"' % (cmd[0],),
219
(None, 1, 1, ' '.join(cmd)))
215
None, 1, ' '.join(cmd))
220
216
if input is None:
249
245
test_case.fail('expected output: %r, but found nothing'
252
null_output_matches_anything = getattr(
253
self, 'null_output_matches_anything', False)
254
if null_output_matches_anything and expected is None:
257
247
expected = expected or ''
258
248
matching = self.output_checker.check_output(
259
249
expected, actual, self.check_options)
482
472
super(TestCaseWithMemoryTransportAndScript, self).setUp()
483
473
self.script_runner = ScriptRunner()
484
# FIXME: See shelf_ui.Shelver._char_based. This allow using shelve in
485
# scripts while providing a line-based input (better solution in
486
# progress). -- vila 2011-09-28
487
self.overrideEnv('INSIDE_EMACS', '1')
489
def run_script(self, script, null_output_matches_anything=False):
490
return self.script_runner.run_script(self, script,
491
null_output_matches_anything=null_output_matches_anything)
475
def run_script(self, script):
476
return self.script_runner.run_script(self, script)
493
478
def run_command(self, cmd, input, output, error):
494
479
return self.script_runner.run_command(self, cmd, input, output, error)
516
501
super(TestCaseWithTransportAndScript, self).setUp()
517
502
self.script_runner = ScriptRunner()
518
# FIXME: See shelf_ui.Shelver._char_based. This allow using shelve in
519
# scripts while providing a line-based input (better solution in
520
# progress). -- vila 2011-09-28
521
self.overrideEnv('INSIDE_EMACS', '1')
523
def run_script(self, script, null_output_matches_anything=False):
524
return self.script_runner.run_script(self, script,
525
null_output_matches_anything=null_output_matches_anything)
504
def run_script(self, script):
505
return self.script_runner.run_script(self, script)
527
507
def run_command(self, cmd, input, output, error):
528
508
return self.script_runner.run_command(self, cmd, input, output, error)
531
def run_script(test_case, script_string, null_output_matches_anything=False):
511
def run_script(test_case, script_string):
532
512
"""Run the given script within a testcase"""
533
return ScriptRunner().run_script(test_case, script_string,
534
null_output_matches_anything=null_output_matches_anything)
513
return ScriptRunner().run_script(test_case, script_string)