13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for Transport implementations.
61
61
from bzrlib.transport.memory import MemoryTransport
64
class TransportTestProviderAdapter(TestScenarioApplier):
65
"""A tool to generate a suite testing all transports for a single test.
67
This is done by copying the test once for each transport and injecting
68
the transport_class and transport_server classes into each copy. Each copy
69
is also given a new id() to make it easy to identify.
73
self.scenarios = self._test_permutations()
75
def get_transport_test_permutations(self, module):
76
"""Get the permutations module wants to have tested."""
77
if getattr(module, 'get_test_permutations', None) is None:
79
"transport module %s doesn't provide get_test_permutations()"
82
return module.get_test_permutations()
84
def _test_permutations(self):
85
"""Return a list of the klass, server_factory pairs to test."""
87
for module in _get_transport_modules():
89
permutations = self.get_transport_test_permutations(
90
reduce(getattr, (module).split('.')[1:], __import__(module)))
91
for (klass, server_factory) in permutations:
92
scenario = (server_factory.__name__,
93
{"transport_class":klass,
94
"transport_server":server_factory})
95
result.append(scenario)
96
except errors.DependencyNotPresent, e:
97
# Continue even if a dependency prevents us
98
# from adding this test
64
def get_transport_test_permutations(module):
65
"""Get the permutations module wants to have tested."""
66
if getattr(module, 'get_test_permutations', None) is None:
68
"transport module %s doesn't provide get_test_permutations()"
71
return module.get_test_permutations()
74
def transport_test_permutations():
75
"""Return a list of the klass, server_factory pairs to test."""
77
for module in _get_transport_modules():
79
permutations = get_transport_test_permutations(
80
reduce(getattr, (module).split('.')[1:], __import__(module)))
81
for (klass, server_factory) in permutations:
82
scenario = ('%s,%s' % (klass.__name__, server_factory.__name__),
83
{"transport_class":klass,
84
"transport_server":server_factory})
85
result.append(scenario)
86
except errors.DependencyNotPresent, e:
87
# Continue even if a dependency prevents us
88
# from adding this test
103
93
def load_tests(standard_tests, module, loader):
104
94
"""Multiply tests for tranport implementations."""
105
95
result = loader.suiteClass()
106
adapter = TransportTestProviderAdapter()
107
for test in tests.iter_suite_tests(standard_tests):
108
result.addTests(adapter.adapt(test))
96
scenarios = transport_test_permutations()
97
return multiply_tests(standard_tests, scenarios, result)
112
100
class TransportTests(TestTransportImplementation):
167
155
self.assertEqual(True, t.has('a'))
168
156
self.assertEqual(False, t.has('c'))
169
157
self.assertEqual(True, t.has(urlutils.escape('%')))
170
self.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])),
171
[True, True, False, False, True, False, True, False])
158
self.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd',
159
'e', 'f', 'g', 'h'])),
160
[True, True, False, False,
161
True, False, True, False])
172
162
self.assertEqual(True, t.has_any(['a', 'b', 'c']))
173
self.assertEqual(False, t.has_any(['c', 'd', 'f', urlutils.escape('%%')]))
174
self.assertEqual(list(t.has_multi(iter(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']))),
175
[True, True, False, False, True, False, True, False])
163
self.assertEqual(False, t.has_any(['c', 'd', 'f',
164
urlutils.escape('%%')]))
165
self.assertEqual(list(t.has_multi(iter(['a', 'b', 'c', 'd',
166
'e', 'f', 'g', 'h']))),
167
[True, True, False, False,
168
True, False, True, False])
176
169
self.assertEqual(False, t.has_any(['c', 'c', 'c']))
177
170
self.assertEqual(True, t.has_any(['b', 'b', 'b']))
210
203
for content, f in itertools.izip(contents, content_f):
211
204
self.assertEqual(content, f.read())
206
def test_get_unknown_file(self):
207
t = self.get_transport()
209
contents = ['contents of a\n',
212
self.build_tree(files, transport=t, line_endings='binary')
213
213
self.assertRaises(NoSuchFile, t.get, 'c')
214
214
self.assertListRaises(NoSuchFile, t.get_multi, ['a', 'b', 'c'])
215
215
self.assertListRaises(NoSuchFile, t.get_multi, iter(['a', 'b', 'c']))
1506
1524
transport.put_bytes('foo', 'bar')
1507
1525
transport3 = self.get_transport()
1508
1526
self.check_transport_contents('bar', transport3, 'foo')
1509
# its base should be usable.
1510
transport4 = get_transport(transport.base)
1511
self.check_transport_contents('bar', transport4, 'foo')
1513
1528
# now opening at a relative url should give use a sane result:
1514
1529
transport.mkdir('newdir')
1515
transport5 = get_transport(transport.base + "newdir")
1530
transport5 = self.get_transport('newdir')
1516
1531
transport6 = transport5.clone('..')
1517
1532
self.check_transport_contents('bar', transport6, 'foo')