~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cmd_test_script.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Front-end command for shell-like test scripts.
18
 
 
19
 
See doc/developers/testing.txt for more explanations.
20
 
This module should be importable even if testtools aren't available.
21
 
"""
22
 
 
23
 
from __future__ import absolute_import
24
 
 
25
 
import os
26
 
 
27
 
from bzrlib import (
28
 
    commands,
29
 
    option,
30
 
    )
31
 
 
32
 
 
33
 
class cmd_test_script(commands.Command):
34
 
    """Run a shell-like test from a file."""
35
 
 
36
 
    hidden = True
37
 
    takes_args = ['infile']
38
 
    takes_options = [
39
 
        option.Option('null-output',
40
 
                       help='Null command outputs match any output.'),
41
 
        ]
42
 
 
43
 
    @commands.display_command
44
 
    def run(self, infile, null_output=False):
45
 
        # local imports to defer testtools dependency
46
 
        from bzrlib import tests
47
 
        from bzrlib.tests.script import TestCaseWithTransportAndScript
48
 
 
49
 
        f = open(infile)
50
 
        try:
51
 
            script = f.read()
52
 
        finally:
53
 
            f.close()
54
 
 
55
 
        class Test(TestCaseWithTransportAndScript):
56
 
 
57
 
            script = None # Set before running
58
 
 
59
 
            def test_it(self):
60
 
                self.run_script(script,
61
 
                                null_output_matches_anything=null_output)
62
 
 
63
 
        runner = tests.TextTestRunner(stream=self.outf)
64
 
        test = Test('test_it')
65
 
        test.path = os.path.realpath(infile)
66
 
        res = runner.run(test)
67
 
        return len(res.errors) + len(res.failures)