~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 06:14:37 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013061437-2e2m9gro1eusnbb8
Tweaks to the sphinx build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
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
25
25
import os
26
26
import shlex
27
27
import textwrap
 
28
from cStringIO import StringIO
28
29
 
29
30
from bzrlib import (
30
31
    osutils,
194
195
        self.output_checker = doctest.OutputChecker()
195
196
        self.check_options = doctest.ELLIPSIS
196
197
 
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.
199
200
 
200
201
        :param test_case: A TestCase instance that should provide the fail(),
202
203
            attribute used as a jail root.
203
204
 
204
205
        :param text: A shell-like script (see _script_to_commands for syntax).
205
 
 
206
 
        :param null_output_matches_anything: For commands with no specified
207
 
            output, ignore any output that does happen, including output on
208
 
            standard error.
209
206
        """
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)
213
209
 
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:
221
217
            str_input = ''
222
218
        else:
248
244
            else:
249
245
                test_case.fail('expected output: %r, but found nothing'
250
246
                            % (expected,))
251
 
 
252
 
        null_output_matches_anything = getattr(
253
 
            self, 'null_output_matches_anything', False)
254
 
        if null_output_matches_anything and expected is None:
255
 
            return
256
 
 
257
247
        expected = expected or ''
258
248
        matching = self.output_checker.check_output(
259
249
            expected, actual, self.check_options)
481
471
    def setUp(self):
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')
488
474
 
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)
492
477
 
493
478
    def run_command(self, cmd, input, output, error):
494
479
        return self.script_runner.run_command(self, cmd, input, output, error)
515
500
    def setUp(self):
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')
522
503
 
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)
526
506
 
527
507
    def run_command(self, cmd, input, output, error):
528
508
        return self.script_runner.run_command(self, cmd, input, output, error)
529
509
 
530
510
 
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)
535
 
 
 
513
    return ScriptRunner().run_script(test_case, script_string)