/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5510.1.2 by Martin von Gagern
Avoid test-script command depending on testtools.
1
# Copyright (C) 2009, 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 developers/testing.html for more explanations.
20
This module should be importable even if testtools aren't available.
21
"""
22
23
import os
24
25
from bzrlib import (
26
    commands,
27
    )
28
29
from bzrlib.lazy_import import lazy_import
30
lazy_import(globals(), '''
31
    from bzrlib import (
32
        tests,
33
        )
34
    from bzrlib.tests.script import (
35
        TestCaseWithTransportAndScript,
36
        )
37
''')
38
39
class cmd_test_script(commands.Command):
40
    """Run a shell-like test from a file."""
41
42
    hidden = True
43
    takes_args = ['infile']
44
45
    @commands.display_command
46
    def run(self, infile):
47
48
        f = open(infile)
49
        try:
50
            script = f.read()
51
        finally:
52
            f.close()
53
54
        class Test(TestCaseWithTransportAndScript):
55
56
            script = None # Set before running
57
58
            def test_it(self):
59
                self.run_script(script)
60
61
        runner = tests.TextTestRunner(stream=self.outf)
62
        test = Test('test_it')
63
        test.path = os.path.realpath(infile)
64
        res = runner.run(test)
65
        return len(res.errors) + len(res.failures)