1
# Copyright (C) 2009, 2010 Canonical Ltd
1
# Copyright (C) 2009, 2010, 2011 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
196
194
self.output_checker = doctest.OutputChecker()
197
195
self.check_options = doctest.ELLIPSIS
199
def run_script(self, test_case, text):
197
def run_script(self, test_case, text, null_output_matches_anything=False):
200
198
"""Run a shell-like script as a test.
202
200
:param test_case: A TestCase instance that should provide the fail(),
204
202
attribute used as a jail root.
206
204
: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
208
211
for cmd, input, output, error in _script_to_commands(text):
209
212
self.run_command(test_case, cmd, input, output, error)
213
216
method = getattr(self, mname, None)
214
217
if method is None:
215
218
raise SyntaxError('Command not found "%s"' % (cmd[0],),
216
None, 1, ' '.join(cmd))
219
(None, 1, 1, ' '.join(cmd)))
217
220
if input is None:
246
249
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:
248
257
expected = expected or ''
249
258
matching = self.output_checker.check_output(
250
259
expected, actual, self.check_options)
473
482
super(TestCaseWithMemoryTransportAndScript, self).setUp()
474
483
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')
476
def run_script(self, script):
477
return self.script_runner.run_script(self, script)
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)
479
493
def run_command(self, cmd, input, output, error):
480
494
return self.script_runner.run_command(self, cmd, input, output, error)
502
516
super(TestCaseWithTransportAndScript, self).setUp()
503
517
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')
505
def run_script(self, script):
506
return self.script_runner.run_script(self, script)
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)
508
527
def run_command(self, cmd, input, output, error):
509
528
return self.script_runner.run_command(self, cmd, input, output, error)
512
def run_script(test_case, script_string):
531
def run_script(test_case, script_string, null_output_matches_anything=False):
513
532
"""Run the given script within a testcase"""
514
return ScriptRunner().run_script(test_case, script_string)
533
return ScriptRunner().run_script(test_case, script_string,
534
null_output_matches_anything=null_output_matches_anything)