/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/script.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-21 11:13:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4762.
  • Revision ID: andrew.bennetts@canonical.com-20091021111340-w7x4d5yf83qwjncc
Add test that WSGI glue allows request handlers to access paths above that request's. backing transport, so long as it is within the WSGI app's backing transport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 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
107
107
                error = []
108
108
            error.append(line[2:] + '\n')
109
109
        else:
110
 
            # can happen if the first line is not recognized as a command, eg
111
 
            # if the prompt has leading whitespace
112
110
            if output is None:
113
111
                if cmd_cur is None:
114
 
                    raise SyntaxError('No command for line %r' % (line,),
 
112
                    raise SyntaxError('No command for that output',
115
113
                                      (file_name, lineno, 1, orig))
116
114
                output = []
117
115
            output.append(line + '\n')
219
217
            # Specifying None means: any output is accepted
220
218
            return
221
219
        if actual is None:
222
 
            test_case.fail('We expected output: %r, but found None'
223
 
                           % (expected,))
 
220
            test_case.fail('Unexpected: %s' % actual)
224
221
        matching = self.output_checker.check_output(
225
222
            expected, actual, self.check_options)
226
223
        if not matching:
292
289
            try:
293
290
                inputs.append(self._read_input(None, in_name))
294
291
            except IOError, e:
295
 
                # Some filenames are illegal on Windows and generate EINVAL
296
 
                # rather than just saying the filename doesn't exist
297
 
                if e.errno in (errno.ENOENT, errno.EINVAL):
 
292
                if e.errno == errno.ENOENT:
298
293
                    return (1, None,
299
294
                            '%s: No such file or directory\n' % (in_name,))
300
 
                raise
301
295
        # Basically cat copy input to output
302
296
        output = ''.join(inputs)
303
297
        # Handle output redirections
304
298
        try:
305
299
            output = self._write_output(output, out_name, out_mode)
306
300
        except IOError, e:
307
 
            # If out_name cannot be created, we may get 'ENOENT', however if
308
 
            # out_name is something like '', we can get EINVAL
309
 
            if e.errno in (errno.ENOENT, errno.EINVAL):
 
301
            if e.errno == errno.ENOENT:
310
302
                return 1, None, '%s: No such file or directory\n' % (out_name,)
311
 
            raise
312
303
        return 0, output, None
313
304
 
314
305
    def do_echo(self, test_case, input, args):
315
306
        (in_name, out_name, out_mode, args) = _scan_redirection_options(args)
316
 
        if input or in_name:
317
 
            raise SyntaxError('echo doesn\'t read from stdin')
 
307
        if input and args:
 
308
                raise SyntaxError('Specify parameters OR use redirection')
318
309
        if args:
319
310
            input = ' '.join(args)
 
311
        try:
 
312
            input = self._read_input(input, in_name)
 
313
        except IOError, e:
 
314
            if e.errno == errno.ENOENT:
 
315
                return 1, None, '%s: No such file or directory\n' % (in_name,)
320
316
        # Always append a \n'
321
317
        input += '\n'
322
318
        # Process output
325
321
        try:
326
322
            output = self._write_output(output, out_name, out_mode)
327
323
        except IOError, e:
328
 
            if e.errno in (errno.ENOENT, errno.EINVAL):
 
324
            if e.errno == errno.ENOENT:
329
325
                return 1, None, '%s: No such file or directory\n' % (out_name,)
330
 
            raise
331
326
        return 0, output, None
332
327
 
333
328
    def _get_jail_root(self, test_case):
402
397
            retcode = 0
403
398
        return retcode, None, err
404
399
 
405
 
    def do_mv(self, test_case, input, args):
406
 
        err = None
407
 
        def error(msg, src, dst):
408
 
            return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
409
 
 
410
 
        if not args or len(args) != 2:
411
 
            raise SyntaxError("Usage: mv path1 path2")
412
 
        src, dst = args
413
 
        try:
414
 
            real_dst = dst
415
 
            if os.path.isdir(dst):
416
 
                real_dst = os.path.join(dst, os.path.basename(src))
417
 
            os.rename(src, real_dst)
418
 
        except OSError, e:
419
 
            if e.errno == errno.ENOENT:
420
 
                err = error('No such file or directory', src, dst)
421
 
            else:
422
 
                raise
423
 
        if err:
424
 
            retcode = 1
425
 
        else:
426
 
            retcode = 0
427
 
        return retcode, None, err
428
 
 
429
 
 
430
400
 
431
401
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
432
402
    """Helper class to experiment shell-like test and memory fs.