/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 breezy/tests/script.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        lineno += 1
94
94
        # Keep a copy for error reporting
95
95
        orig = line
96
 
        comment =  line.find('#')
 
96
        comment = line.find('#')
97
97
        if comment >= 0:
98
98
            # Delete comments
99
99
            # NB: this syntax means comments are allowed inside output, which
142
142
 
143
143
    :param args: The command line arguments
144
144
 
145
 
    :return: A tuple containing: 
 
145
    :return: A tuple containing:
146
146
        - The file name redirected from or None
147
147
        - The file name redirected to or None
148
148
        - The mode to open the output file or None
178
178
 
179
179
class ScriptRunner(object):
180
180
    """Run a shell-like script from a test.
181
 
    
 
181
 
182
182
    Can be used as:
183
183
 
184
184
    from breezy.tests import script
236
236
        try:
237
237
            self._check_output(error, actual_error, test_case)
238
238
        except AssertionError as e:
239
 
            raise AssertionError(str(e) +
240
 
                " in stderr of running command %s" % cmd)
 
239
            raise AssertionError(str(e)
 
240
                                 + " in stderr of running command %s" % cmd)
241
241
        if retcode and not error and actual_error:
242
242
            test_case.fail('In \n\t%s\nUnexpected error: %s'
243
243
                           % (' '.join(cmd), actual_error))
251
251
                return
252
252
            else:
253
253
                test_case.fail('expected output: %r, but found nothing'
254
 
                            % (expected,))
 
254
                               % (expected,))
255
255
 
256
256
        null_output_matches_anything = getattr(
257
257
            self, 'null_output_matches_anything', False)
284
284
            # Strip the simple and double quotes since we don't care about
285
285
            # them.  We leave the backquotes in place though since they have a
286
286
            # different semantic.
287
 
            if arg[0] in  ('"', "'") and arg[0] == arg[-1]:
 
287
            if arg[0] in ('"', "'") and arg[0] == arg[-1]:
288
288
                yield arg[1:-1]
289
289
            else:
290
290
                if glob.has_magic(arg):
431
431
        err = None
432
432
 
433
433
        def error(msg, path):
434
 
            return  "rm: cannot remove '%s': %s\n" % (path, msg)
 
434
            return "rm: cannot remove '%s': %s\n" % (path, msg)
435
435
 
436
436
        force, recursive = False, False
437
437
        opts = None
461
461
                        break
462
462
                elif e.errno == errno.ENOENT:
463
463
                    if not force:
464
 
                        err =  error('No such file or directory', p)
 
464
                        err = error('No such file or directory', p)
465
465
                        break
466
466
                else:
467
467
                    raise
473
473
 
474
474
    def do_mv(self, test_case, input, args):
475
475
        err = None
 
476
 
476
477
        def error(msg, src, dst):
477
478
            return "mv: cannot move %s to %s: %s\n" % (src, dst, msg)
478
479
 
496
497
        return retcode, None, err
497
498
 
498
499
 
499
 
 
500
500
class TestCaseWithMemoryTransportAndScript(tests.TestCaseWithMemoryTransport):
501
501
    """Helper class to experiment shell-like test and memory fs.
502
502
 
514
514
        self.overrideEnv('INSIDE_EMACS', '1')
515
515
 
516
516
    def run_script(self, script, null_output_matches_anything=False):
517
 
        return self.script_runner.run_script(self, script, 
518
 
                   null_output_matches_anything=null_output_matches_anything)
 
517
        return self.script_runner.run_script(self, script,
 
518
                                             null_output_matches_anything=null_output_matches_anything)
519
519
 
520
520
    def run_command(self, cmd, input, output, error):
521
521
        return self.script_runner.run_command(self, cmd, input, output, error)
549
549
 
550
550
    def run_script(self, script, null_output_matches_anything=False):
551
551
        return self.script_runner.run_script(self, script,
552
 
                   null_output_matches_anything=null_output_matches_anything)
 
552
                                             null_output_matches_anything=null_output_matches_anything)
553
553
 
554
554
    def run_command(self, cmd, input, output, error):
555
555
        return self.script_runner.run_command(self, cmd, input, output, error)
558
558
def run_script(test_case, script_string, null_output_matches_anything=False):
559
559
    """Run the given script within a testcase"""
560
560
    return ScriptRunner().run_script(test_case, script_string,
561
 
               null_output_matches_anything=null_output_matches_anything)
562
 
 
 
561
                                     null_output_matches_anything=null_output_matches_anything)