bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
1 |
# Copyright (C) 2005 by 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 version 2 as published by
|
|
5 |
# the Free Software Foundation.
|
|
6 |
#
|
|
7 |
# This program is distributed in the hope that it will be useful,
|
|
8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
# GNU General Public License for more details.
|
|
11 |
#
|
|
12 |
# You should have received a copy of the GNU General Public License
|
|
13 |
# along with this program; if not, write to the Free Software
|
|
14 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
15 |
||
16 |
"""Tests for the test framework
|
|
17 |
"""
|
|
18 |
||
19 |
import os |
|
20 |
import sys |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
21 |
import unittest |
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
22 |
|
|
1526.1.3
by Robert Collins
Merge from upstream. |
23 |
from bzrlib.tests import ( |
24 |
_load_module_by_name, |
|
25 |
TestCase, |
|
26 |
TestCaseInTempDir, |
|
27 |
TestSkipped, |
|
28 |
TextTestRunner, |
|
29 |
)
|
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
30 |
|
31 |
||
32 |
class SelftestTests(TestCase): |
|
33 |
||
34 |
def test_import_tests(self): |
|
35 |
mod = _load_module_by_name('bzrlib.tests.test_selftest') |
|
36 |
self.assertEqual(mod.SelftestTests, SelftestTests) |
|
37 |
||
38 |
def test_import_test_failure(self): |
|
39 |
self.assertRaises(ImportError, |
|
40 |
_load_module_by_name, |
|
41 |
'bzrlib.no-name-yet') |
|
42 |
||
43 |
||
44 |
class MetaTestLog(TestCase): |
|
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
45 |
|
|
1185.51.1
by Martin Pool
Better message when failing to import a test suite. |
46 |
def test_logging(self): |
47 |
"""Test logs are captured when a test fails.""" |
|
48 |
self.log('a test message') |
|
49 |
self._log_file.flush() |
|
50 |
self.assertContainsRe(self._get_log(), 'a test message\n') |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
51 |
|
52 |
||
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
53 |
class TestTreeShape(TestCaseInTempDir): |
54 |
||
55 |
def test_unicode_paths(self): |
|
56 |
filename = u'hell\u00d8' |
|
|
1526.1.4
by Robert Collins
forgot my self. |
57 |
try: |
58 |
self.build_tree_contents([(filename, 'contents of hello')]) |
|
59 |
except UnicodeEncodeError: |
|
60 |
raise TestSkipped("can't build unicode working tree in " |
|
61 |
"filesystem encoding %s" % sys.getfilesystemencoding()) |
|
|
1526.1.1
by Robert Collins
Run the test suite with no locale as well as the default locale. Also add a test for build_tree_shape to selftest. |
62 |
self.failUnlessExists(filename) |
|
1526.1.3
by Robert Collins
Merge from upstream. |
63 |
|
64 |
||
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
65 |
class TestSkippedTest(TestCase): |
66 |
"""Try running a test which is skipped, make sure it's reported properly.""" |
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
67 |
|
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
68 |
def test_skipped_test(self): |
69 |
# must be hidden in here so it's not run as a real test
|
|
70 |
def skipping_test(): |
|
71 |
raise TestSkipped('test intentionally skipped') |
|
|
1526.1.3
by Robert Collins
Merge from upstream. |
72 |
runner = TextTestRunner(stream=self._log_file) |
|
1185.33.95
by Martin Pool
New TestSkipped facility, and tests for it. |
73 |
test = unittest.FunctionTestCase(skipping_test) |
74 |
result = runner.run(test) |
|
75 |
self.assertTrue(result.wasSuccessful()) |
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
76 |
|
77 |
||
78 |
class TestTransportProviderAdapter(TestCase): |
|
|
1530.1.21
by Robert Collins
Review feedback fixes. |
79 |
"""A group of tests that test the transport implementation adaption core. |
80 |
||
81 |
This will be generalised in the future which is why it is in this
|
|
82 |
test file even though it is specific to transport tests at the moment.
|
|
83 |
"""
|
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
84 |
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
85 |
def test_get_transport_permutations(self): |
|
1530.1.21
by Robert Collins
Review feedback fixes. |
86 |
# this checks that we the module get_test_permutations call
|
87 |
# is made by the adapter get_transport_test_permitations method.
|
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
88 |
class MockModule(object): |
89 |
def get_test_permutations(self): |
|
90 |
return sample_permutation |
|
91 |
sample_permutation = [(1,2), (3,4)] |
|
92 |
from bzrlib.transport import TransportTestProviderAdapter |
|
93 |
adapter = TransportTestProviderAdapter() |
|
94 |
self.assertEqual(sample_permutation, |
|
95 |
adapter.get_transport_test_permutations(MockModule())) |
|
96 |
||
97 |
def test_adapter_checks_all_modules(self): |
|
|
1530.1.21
by Robert Collins
Review feedback fixes. |
98 |
# this checks that the adapter returns as many permurtations as
|
99 |
# there are in all the registered# transport modules for there
|
|
100 |
# - we assume if this matches its probably doing the right thing
|
|
101 |
# especially in combination with the tests for setting the right
|
|
102 |
# classes below.
|
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
103 |
from bzrlib.transport import (TransportTestProviderAdapter, |
104 |
_get_transport_modules
|
|
105 |
)
|
|
106 |
modules = _get_transport_modules() |
|
107 |
permutation_count = 0 |
|
108 |
for module in modules: |
|
109 |
permutation_count += len(reduce(getattr, |
|
110 |
(module + ".get_test_permutations").split('.')[1:], |
|
111 |
__import__(module))()) |
|
112 |
input_test = TestTransportProviderAdapter( |
|
113 |
"test_adapter_sets_transport_class") |
|
114 |
adapter = TransportTestProviderAdapter() |
|
115 |
self.assertEqual(permutation_count, |
|
116 |
len(list(iter(adapter.adapt(input_test))))) |
|
117 |
||
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
118 |
def test_adapter_sets_transport_class(self): |
|
1530.1.21
by Robert Collins
Review feedback fixes. |
119 |
# when the adapter adapts a test it needs to
|
120 |
# place one of the permutations from the transport
|
|
121 |
# providers in each test case copy. This checks
|
|
122 |
# that it does not just use the same one all the time.
|
|
123 |
# and that the id is set correctly so that debugging is
|
|
124 |
# easy.
|
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
125 |
from bzrlib.transport.local import (LocalTransport, |
126 |
LocalRelpathServer, |
|
127 |
LocalAbspathServer, |
|
128 |
LocalURLServer
|
|
129 |
)
|
|
130 |
from bzrlib.transport.sftp import (SFTPTransport, |
|
131 |
SFTPAbsoluteServer, |
|
|
1530.1.8
by Robert Collins
More NEWS, move sibling sftp tests into new framework, nuke legacy local transport tests. |
132 |
SFTPHomeDirServer, |
133 |
SFTPSiblingAbsoluteServer, |
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
134 |
)
|
135 |
from bzrlib.transport.http import (HttpTransport, |
|
136 |
HttpServer
|
|
137 |
)
|
|
138 |
from bzrlib.transport.ftp import FtpTransport |
|
|
1530.1.3
by Robert Collins
transport implementations now tested consistently. |
139 |
from bzrlib.transport.memory import (MemoryTransport, |
140 |
MemoryServer
|
|
141 |
)
|
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
142 |
from bzrlib.transport import TransportTestProviderAdapter |
143 |
# FIXME. What we want is a factory for the things
|
|
144 |
# needed to test the implementation. I.e. for transport we want:
|
|
145 |
# the class that connections should get; a local server factory
|
|
146 |
# so we would want the following permutations:
|
|
147 |
# LocalTransport relpath-factory
|
|
148 |
# LocalTransport abspath-factory
|
|
149 |
# LocalTransport file://-factory
|
|
150 |
# SFTPTransport homedir-factory
|
|
151 |
# SFTPTransport abssolute-factory
|
|
152 |
# HTTPTransport http-factory
|
|
153 |
# HTTPTransport https-factory
|
|
154 |
# etc, but we are currently lacking in this, so print out that
|
|
155 |
# this should be fixed.
|
|
156 |
input_test = TestTransportProviderAdapter( |
|
157 |
"test_adapter_sets_transport_class") |
|
158 |
suite = TransportTestProviderAdapter().adapt(input_test) |
|
159 |
test_iter = iter(suite) |
|
|
1530.1.11
by Robert Collins
Push the transport permutations list into each transport module allowing for automatic testing of new modules that are registered as transports. |
160 |
http_test = test_iter.next() |
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
161 |
local_relpath_test = test_iter.next() |
162 |
local_abspath_test = test_iter.next() |
|
163 |
local_urlpath_test = test_iter.next() |
|
|
1530.1.19
by Robert Collins
Make transport test adapter tests reliable. |
164 |
memory_test = test_iter.next() |
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
165 |
sftp_abs_test = test_iter.next() |
166 |
sftp_homedir_test = test_iter.next() |
|
|
1530.1.8
by Robert Collins
More NEWS, move sibling sftp tests into new framework, nuke legacy local transport tests. |
167 |
sftp_sibling_abs_test = test_iter.next() |
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
168 |
# ftp_test = test_iter.next()
|
169 |
self.assertRaises(StopIteration, test_iter.next) |
|
170 |
self.assertEqual(LocalTransport, local_relpath_test.transport_class) |
|
171 |
self.assertEqual(LocalRelpathServer, local_relpath_test.transport_server) |
|
172 |
||
173 |
self.assertEqual(LocalTransport, local_abspath_test.transport_class) |
|
174 |
self.assertEqual(LocalAbspathServer, local_abspath_test.transport_server) |
|
175 |
||
176 |
self.assertEqual(LocalTransport, local_urlpath_test.transport_class) |
|
177 |
self.assertEqual(LocalURLServer, local_urlpath_test.transport_server) |
|
178 |
||
179 |
self.assertEqual(SFTPTransport, sftp_abs_test.transport_class) |
|
180 |
self.assertEqual(SFTPAbsoluteServer, sftp_abs_test.transport_server) |
|
181 |
self.assertEqual(SFTPTransport, sftp_homedir_test.transport_class) |
|
182 |
self.assertEqual(SFTPHomeDirServer, sftp_homedir_test.transport_server) |
|
|
1530.1.8
by Robert Collins
More NEWS, move sibling sftp tests into new framework, nuke legacy local transport tests. |
183 |
self.assertEqual(SFTPTransport, sftp_sibling_abs_test.transport_class) |
184 |
self.assertEqual(SFTPSiblingAbsoluteServer, |
|
185 |
sftp_sibling_abs_test.transport_server) |
|
|
1530.1.3
by Robert Collins
transport implementations now tested consistently. |
186 |
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
187 |
self.assertEqual(HttpTransport, http_test.transport_class) |
188 |
self.assertEqual(HttpServer, http_test.transport_server) |
|
189 |
# self.assertEqual(FtpTransport, ftp_test.transport_class)
|
|
|
1530.1.3
by Robert Collins
transport implementations now tested consistently. |
190 |
|
191 |
self.assertEqual(MemoryTransport, memory_test.transport_class) |
|
192 |
self.assertEqual(MemoryServer, memory_test.transport_server) |
|
|
1530.1.1
by Robert Collins
Minimal infrastructure to test TransportTestProviderAdapter. |
193 |
|
|
1530.1.3
by Robert Collins
transport implementations now tested consistently. |
194 |
# we could test all of them for .id, but two is probably sufficient.
|
195 |
self.assertEqual("bzrlib.tests.test_selftest." |
|
196 |
"TestTransportProviderAdapter."
|
|
197 |
"test_adapter_sets_transport_class(MemoryServer)", |
|
198 |
memory_test.id()) |
|
199 |
self.assertEqual("bzrlib.tests.test_selftest." |
|
200 |
"TestTransportProviderAdapter."
|
|
201 |
"test_adapter_sets_transport_class(LocalRelpathServer)", |
|
202 |
local_relpath_test.id()) |
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
203 |
|
204 |
||
205 |
class TestBranchProviderAdapter(TestCase): |
|
206 |
"""A group of tests that test the branch implementation test adapter.""" |
|
207 |
||
208 |
def test_adapted_tests(self): |
|
209 |
# check that constructor parameters are passed through to the adapted
|
|
210 |
# test.
|
|
211 |
from bzrlib.branch import BranchTestProviderAdapter |
|
212 |
input_test = TestBranchProviderAdapter( |
|
213 |
"test_adapted_tests") |
|
214 |
server1 = "a" |
|
215 |
server2 = "b" |
|
216 |
formats = ["c", "d"] |
|
217 |
adapter = BranchTestProviderAdapter(server1, server2, formats) |
|
218 |
suite = adapter.adapt(input_test) |
|
219 |
tests = list(iter(suite)) |
|
220 |
self.assertEqual(2, len(tests)) |
|
221 |
self.assertEqual(tests[0].branch_format, formats[0]) |
|
222 |
self.assertEqual(tests[0].transport_server, server1) |
|
223 |
self.assertEqual(tests[0].transport_readonly_server, server2) |
|
224 |
self.assertEqual(tests[1].branch_format, formats[1]) |
|
225 |
self.assertEqual(tests[1].transport_server, server1) |
|
226 |
self.assertEqual(tests[1].transport_readonly_server, server2) |