bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
5452.4.3
by John Arbash Meinel
 Merge bzr.dev to resolve bzr-2.3.txt (aka NEWS)  | 
1  | 
# Copyright (C) 2010 Canonical Ltd
 | 
| 
5510.1.2
by Martin von Gagern
 Avoid test-script command depending on testtools.  | 
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  | 
||
| 
5510.1.3
by Martin von Gagern
 Change lazy import to local import.  | 
25  | 
from bzrlib import commands  | 
| 
5510.1.2
by Martin von Gagern
 Avoid test-script command depending on testtools.  | 
26  | 
|
| 
5510.1.4
by Martin von Gagern
 Minor polishing suggested by John A Meinel.  | 
27  | 
|
| 
5510.1.2
by Martin von Gagern
 Avoid test-script command depending on testtools.  | 
28  | 
class cmd_test_script(commands.Command):  | 
29  | 
"""Run a shell-like test from a file."""  | 
|
30  | 
||
31  | 
hidden = True  | 
|
32  | 
takes_args = ['infile']  | 
|
33  | 
||
34  | 
@commands.display_command  | 
|
35  | 
def run(self, infile):  | 
|
| 
5510.1.4
by Martin von Gagern
 Minor polishing suggested by John A Meinel.  | 
36  | 
        # local imports to defer testtools dependency
 | 
| 
5510.1.3
by Martin von Gagern
 Change lazy import to local import.  | 
37  | 
from bzrlib import tests  | 
38  | 
from bzrlib.tests.script import TestCaseWithTransportAndScript  | 
|
| 
5510.1.2
by Martin von Gagern
 Avoid test-script command depending on testtools.  | 
39  | 
|
40  | 
f = open(infile)  | 
|
41  | 
try:  | 
|
42  | 
script = f.read()  | 
|
43  | 
finally:  | 
|
44  | 
f.close()  | 
|
45  | 
||
46  | 
class Test(TestCaseWithTransportAndScript):  | 
|
47  | 
||
48  | 
script = None # Set before running  | 
|
49  | 
||
50  | 
def test_it(self):  | 
|
51  | 
self.run_script(script)  | 
|
52  | 
||
53  | 
runner = tests.TextTestRunner(stream=self.outf)  | 
|
54  | 
test = Test('test_it')  | 
|
55  | 
test.path = os.path.realpath(infile)  | 
|
56  | 
res = runner.run(test)  | 
|
57  | 
return len(res.errors) + len(res.failures)  |