~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

Support '...' in expected strings.

* bzrlib/tests/test_script.py:
(TestScriptExecution.test_ellipsis_output): '...' can be used to
under specified expected outout/errors.

* bzrlib/tests/script.py:
(ScriptRunner.__init__, ScriptRunner._check_output): Use
doctest.OutputChecker.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
When no output is specified, any ouput from the command is accepted
37
37
and let the execution continue. 
38
38
 
 
39
FIXME: not yet true
39
40
If an error occurs and no expected error is specified, the execution stops.
40
41
 
41
 
The matching is done on a full string comparison basis.
 
42
The matching is done on a full string comparison basis unless '...' is used, in
 
43
which case expected output/errors can be lees precise.
42
44
 
43
45
Examples:
44
46
 
60
62
  bzr not-a-command
61
63
  2> bzr: ERROR: unknown command "not-a-command"
62
64
 
 
65
You can use ellipsis (...) to replace any piece of text you don't want to be
 
66
matched exactly.
 
67
 
 
68
  bzr branch not-a-branch
 
69
  2>bzr: ERROR: Not a branch...not-a-branch/".
 
70
 
 
71
 
63
72
"""
64
73
 
65
 
from cStringIO import StringIO
 
74
import doctest
66
75
import os
67
76
import shlex
 
77
from cStringIO import StringIO
68
78
 
69
79
from bzrlib import (
70
80
    osutils,
196
206
 
197
207
    def __init__(self, test_case):
198
208
        self.test_case = test_case
 
209
        self.output_checker = doctest.OutputChecker()
 
210
        self.check_options = doctest.ELLIPSIS
199
211
 
200
212
    def run_script(self, text):
201
213
        for cmd, input, output, error in _script_to_commands(text):
202
 
            self.run_command(cmd, input, output, error)
 
214
            out, err = self.run_command(cmd, input, output, error)
203
215
 
204
216
    def _check_output(self, expected, actual):
205
217
        if expected is None:
206
218
            # Specifying None means: any output is accepted
207
219
            return
208
 
        self.test_case.assertEquals(expected, actual)
 
220
        if actual is None:
 
221
            self.test_case.fail('Unexpected: %s' % actual)
 
222
        matching = self.output_checker.check_output(
 
223
            expected, actual, self.check_options)
 
224
        if not matching:
 
225
            # Note that we can't use output_checker.output_difference() here
 
226
            # because... the API is boken (expected must be a doctest specific
 
227
            # object of whicha 'want' attribute will be our 'expected'
 
228
            # parameter. So we just fallbacl to our good old assertEqualDiff
 
229
            # since we know there are differences and the output should be
 
230
            # decemtly readable.
 
231
            self.test_case.assertEqualDiff(expected, actual)
209
232
 
210
233
    def run_command(self, cmd, input, output, error):
211
234
        mname = 'do_' + cmd[0]