~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-22 21:54:24 UTC
  • mfrom: (5546.1.1 remove-old-dev-formats)
  • Revision ID: pqm@pqm.ubuntu.com-20101122215424-tfww6o1rayiyq1m7
(spiv) Remove RepositoryFormatCHK1 and RepositoryFormatCHK2. (Andrew
 Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from cStringIO import StringIO
29
29
 
30
30
from bzrlib import (
 
31
    errors,
31
32
    osutils,
32
33
    tests,
33
34
    )
195
196
        self.output_checker = doctest.OutputChecker()
196
197
        self.check_options = doctest.ELLIPSIS
197
198
 
198
 
    def run_script(self, test_case, text):
 
199
    def run_script(self, test_case, text, null_output_matches_anything=False):
199
200
        """Run a shell-like script as a test.
200
201
 
201
202
        :param test_case: A TestCase instance that should provide the fail(),
203
204
            attribute used as a jail root.
204
205
 
205
206
        :param text: A shell-like script (see _script_to_commands for syntax).
 
207
 
 
208
        :param null_output_matches_anything: For commands with no specified
 
209
            output, ignore any output that does happen, including output on
 
210
            standard error.
206
211
        """
 
212
        self.null_output_matches_anything = null_output_matches_anything
207
213
        for cmd, input, output, error in _script_to_commands(text):
208
214
            self.run_command(test_case, cmd, input, output, error)
209
215
 
212
218
        method = getattr(self, mname, None)
213
219
        if method is None:
214
220
            raise SyntaxError('Command not found "%s"' % (cmd[0],),
215
 
                              None, 1, ' '.join(cmd))
 
221
                              (None, 1, 1, ' '.join(cmd)))
216
222
        if input is None:
217
223
            str_input = ''
218
224
        else:
221
227
        retcode, actual_output, actual_error = method(test_case,
222
228
                                                      str_input, args)
223
229
 
224
 
        self._check_output(output, actual_output, test_case)
225
 
        self._check_output(error, actual_error, test_case)
 
230
        try:
 
231
            self._check_output(output, actual_output, test_case)
 
232
        except AssertionError, e:
 
233
            raise AssertionError(str(e) + " in stdout of command %s" % cmd)
 
234
        try:
 
235
            self._check_output(error, actual_error, test_case)
 
236
        except AssertionError, e:
 
237
            raise AssertionError(str(e) +
 
238
                " in stderr of running command %s" % cmd)
226
239
        if retcode and not error and actual_error:
227
240
            test_case.fail('In \n\t%s\nUnexpected error: %s'
228
241
                           % (' '.join(cmd), actual_error))
229
242
        return retcode, actual_output, actual_error
230
243
 
231
244
    def _check_output(self, expected, actual, test_case):
232
 
        if expected is None:
233
 
            # Specifying None means: any output is accepted
 
245
        if not actual:
 
246
            if expected is None:
 
247
                return
 
248
            elif expected == '...\n':
 
249
                return
 
250
            else:
 
251
                test_case.fail('expected output: %r, but found nothing'
 
252
                            % (expected,))
 
253
 
 
254
        null_output_matches_anything = getattr(
 
255
            self, 'null_output_matches_anything', False)
 
256
        if null_output_matches_anything and expected is None:
234
257
            return
235
 
        if actual is None:
236
 
            test_case.fail('We expected output: %r, but found None'
237
 
                           % (expected,))
 
258
 
 
259
        expected = expected or ''
238
260
        matching = self.output_checker.check_output(
239
261
            expected, actual, self.check_options)
240
262
        if not matching:
462
484
        super(TestCaseWithMemoryTransportAndScript, self).setUp()
463
485
        self.script_runner = ScriptRunner()
464
486
 
465
 
    def run_script(self, script):
466
 
        return self.script_runner.run_script(self, script)
 
487
    def run_script(self, script, null_output_matches_anything=False):
 
488
        return self.script_runner.run_script(self, script, 
 
489
                   null_output_matches_anything=null_output_matches_anything)
467
490
 
468
491
    def run_command(self, cmd, input, output, error):
469
492
        return self.script_runner.run_command(self, cmd, input, output, error)
491
514
        super(TestCaseWithTransportAndScript, self).setUp()
492
515
        self.script_runner = ScriptRunner()
493
516
 
494
 
    def run_script(self, script):
495
 
        return self.script_runner.run_script(self, script)
 
517
    def run_script(self, script, null_output_matches_anything=False):
 
518
        return self.script_runner.run_script(self, script,
 
519
                   null_output_matches_anything=null_output_matches_anything)
496
520
 
497
521
    def run_command(self, cmd, input, output, error):
498
522
        return self.script_runner.run_command(self, cmd, input, output, error)
499
523
 
500
524
 
501
 
def run_script(test_case, script_string):
 
525
def run_script(test_case, script_string, null_output_matches_anything=False):
502
526
    """Run the given script within a testcase"""
503
 
    return ScriptRunner().run_script(test_case, script_string)
 
527
    return ScriptRunner().run_script(test_case, script_string,
 
528
               null_output_matches_anything=null_output_matches_anything)
 
529