1
# Copyright (C) 2005, 2006 by Canonical Ltd
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.
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.
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
16
"""Tests for the test framework."""
19
from StringIO import StringIO
26
from bzrlib.progress import _BaseProgressBar
27
from bzrlib.tests import (
31
TestCaseWithTransport,
36
from bzrlib.tests.TestUtil import _load_module_by_name
37
import bzrlib.errors as errors
40
class SelftestTests(TestCase):
42
def test_import_tests(self):
43
mod = _load_module_by_name('bzrlib.tests.test_selftest')
44
self.assertEqual(mod.SelftestTests, SelftestTests)
46
def test_import_test_failure(self):
47
self.assertRaises(ImportError,
52
class MetaTestLog(TestCase):
54
def test_logging(self):
55
"""Test logs are captured when a test fails."""
56
self.log('a test message')
57
self._log_file.flush()
58
self.assertContainsRe(self._get_log(), 'a test message\n')
61
class TestTreeShape(TestCaseInTempDir):
63
def test_unicode_paths(self):
64
filename = u'hell\u00d8'
66
self.build_tree_contents([(filename, 'contents of hello')])
67
except UnicodeEncodeError:
68
raise TestSkipped("can't build unicode working tree in "
69
"filesystem encoding %s" % sys.getfilesystemencoding())
70
self.failUnlessExists(filename)
73
class TestTransportProviderAdapter(TestCase):
74
"""A group of tests that test the transport implementation adaption core.
76
This is a meta test that the tests are applied to all available
79
This will be generalised in the future which is why it is in this
80
test file even though it is specific to transport tests at the moment.
83
def test_get_transport_permutations(self):
84
# this checks that we the module get_test_permutations call
85
# is made by the adapter get_transport_test_permitations method.
86
class MockModule(object):
87
def get_test_permutations(self):
88
return sample_permutation
89
sample_permutation = [(1,2), (3,4)]
90
from bzrlib.transport import TransportTestProviderAdapter
91
adapter = TransportTestProviderAdapter()
92
self.assertEqual(sample_permutation,
93
adapter.get_transport_test_permutations(MockModule()))
95
def test_adapter_checks_all_modules(self):
96
# this checks that the adapter returns as many permurtations as
97
# there are in all the registered# transport modules for there
98
# - we assume if this matches its probably doing the right thing
99
# especially in combination with the tests for setting the right
101
from bzrlib.transport import (TransportTestProviderAdapter,
102
_get_transport_modules
104
modules = _get_transport_modules()
105
permutation_count = 0
106
for module in modules:
108
permutation_count += len(reduce(getattr,
109
(module + ".get_test_permutations").split('.')[1:],
110
__import__(module))())
111
except errors.DependencyNotPresent:
113
input_test = TestTransportProviderAdapter(
114
"test_adapter_sets_transport_class")
115
adapter = TransportTestProviderAdapter()
116
self.assertEqual(permutation_count,
117
len(list(iter(adapter.adapt(input_test)))))
119
def test_adapter_sets_transport_class(self):
120
# Check that the test adapter inserts a transport and server into the
123
# This test used to know about all the possible transports and the
124
# order they were returned but that seems overly brittle (mbp
126
input_test = TestTransportProviderAdapter(
127
"test_adapter_sets_transport_class")
128
from bzrlib.transport import TransportTestProviderAdapter
129
suite = TransportTestProviderAdapter().adapt(input_test)
130
tests = list(iter(suite))
131
self.assertTrue(len(tests) > 6)
132
# there are at least that many builtin transports
134
self.assertTrue(issubclass(one_test.transport_class,
135
bzrlib.transport.Transport))
136
self.assertTrue(issubclass(one_test.transport_server,
137
bzrlib.transport.Server))
140
class TestBranchProviderAdapter(TestCase):
141
"""A group of tests that test the branch implementation test adapter."""
143
def test_adapted_tests(self):
144
# check that constructor parameters are passed through to the adapted
146
from bzrlib.branch import BranchTestProviderAdapter
147
input_test = TestBranchProviderAdapter(
148
"test_adapted_tests")
151
formats = [("c", "C"), ("d", "D")]
152
adapter = BranchTestProviderAdapter(server1, server2, formats)
153
suite = adapter.adapt(input_test)
154
tests = list(iter(suite))
155
self.assertEqual(2, len(tests))
156
self.assertEqual(tests[0].branch_format, formats[0][0])
157
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
158
self.assertEqual(tests[0].transport_server, server1)
159
self.assertEqual(tests[0].transport_readonly_server, server2)
160
self.assertEqual(tests[1].branch_format, formats[1][0])
161
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
162
self.assertEqual(tests[1].transport_server, server1)
163
self.assertEqual(tests[1].transport_readonly_server, server2)
166
class TestBzrDirProviderAdapter(TestCase):
167
"""A group of tests that test the bzr dir implementation test adapter."""
169
def test_adapted_tests(self):
170
# check that constructor parameters are passed through to the adapted
172
from bzrlib.bzrdir import BzrDirTestProviderAdapter
173
input_test = TestBzrDirProviderAdapter(
174
"test_adapted_tests")
178
adapter = BzrDirTestProviderAdapter(server1, server2, formats)
179
suite = adapter.adapt(input_test)
180
tests = list(iter(suite))
181
self.assertEqual(2, len(tests))
182
self.assertEqual(tests[0].bzrdir_format, formats[0])
183
self.assertEqual(tests[0].transport_server, server1)
184
self.assertEqual(tests[0].transport_readonly_server, server2)
185
self.assertEqual(tests[1].bzrdir_format, formats[1])
186
self.assertEqual(tests[1].transport_server, server1)
187
self.assertEqual(tests[1].transport_readonly_server, server2)
190
class TestRepositoryProviderAdapter(TestCase):
191
"""A group of tests that test the repository implementation test adapter."""
193
def test_adapted_tests(self):
194
# check that constructor parameters are passed through to the adapted
196
from bzrlib.repository import RepositoryTestProviderAdapter
197
input_test = TestRepositoryProviderAdapter(
198
"test_adapted_tests")
201
formats = [("c", "C"), ("d", "D")]
202
adapter = RepositoryTestProviderAdapter(server1, server2, formats)
203
suite = adapter.adapt(input_test)
204
tests = list(iter(suite))
205
self.assertEqual(2, len(tests))
206
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
207
self.assertEqual(tests[0].repository_format, formats[0][0])
208
self.assertEqual(tests[0].transport_server, server1)
209
self.assertEqual(tests[0].transport_readonly_server, server2)
210
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
211
self.assertEqual(tests[1].repository_format, formats[1][0])
212
self.assertEqual(tests[1].transport_server, server1)
213
self.assertEqual(tests[1].transport_readonly_server, server2)
216
class TestInterRepositoryProviderAdapter(TestCase):
217
"""A group of tests that test the InterRepository test adapter."""
219
def test_adapted_tests(self):
220
# check that constructor parameters are passed through to the adapted
222
from bzrlib.repository import InterRepositoryTestProviderAdapter
223
input_test = TestInterRepositoryProviderAdapter(
224
"test_adapted_tests")
227
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
228
adapter = InterRepositoryTestProviderAdapter(server1, server2, formats)
229
suite = adapter.adapt(input_test)
230
tests = list(iter(suite))
231
self.assertEqual(2, len(tests))
232
self.assertEqual(tests[0].interrepo_class, formats[0][0])
233
self.assertEqual(tests[0].repository_format, formats[0][1])
234
self.assertEqual(tests[0].repository_format_to, formats[0][2])
235
self.assertEqual(tests[0].transport_server, server1)
236
self.assertEqual(tests[0].transport_readonly_server, server2)
237
self.assertEqual(tests[1].interrepo_class, formats[1][0])
238
self.assertEqual(tests[1].repository_format, formats[1][1])
239
self.assertEqual(tests[1].repository_format_to, formats[1][2])
240
self.assertEqual(tests[1].transport_server, server1)
241
self.assertEqual(tests[1].transport_readonly_server, server2)
244
class TestInterVersionedFileProviderAdapter(TestCase):
245
"""A group of tests that test the InterVersionedFile test adapter."""
247
def test_adapted_tests(self):
248
# check that constructor parameters are passed through to the adapted
250
from bzrlib.versionedfile import InterVersionedFileTestProviderAdapter
251
input_test = TestInterRepositoryProviderAdapter(
252
"test_adapted_tests")
255
formats = [(str, "C1", "C2"), (int, "D1", "D2")]
256
adapter = InterVersionedFileTestProviderAdapter(server1, server2, formats)
257
suite = adapter.adapt(input_test)
258
tests = list(iter(suite))
259
self.assertEqual(2, len(tests))
260
self.assertEqual(tests[0].interversionedfile_class, formats[0][0])
261
self.assertEqual(tests[0].versionedfile_factory, formats[0][1])
262
self.assertEqual(tests[0].versionedfile_factory_to, formats[0][2])
263
self.assertEqual(tests[0].transport_server, server1)
264
self.assertEqual(tests[0].transport_readonly_server, server2)
265
self.assertEqual(tests[1].interversionedfile_class, formats[1][0])
266
self.assertEqual(tests[1].versionedfile_factory, formats[1][1])
267
self.assertEqual(tests[1].versionedfile_factory_to, formats[1][2])
268
self.assertEqual(tests[1].transport_server, server1)
269
self.assertEqual(tests[1].transport_readonly_server, server2)
272
class TestRevisionStoreProviderAdapter(TestCase):
273
"""A group of tests that test the RevisionStore test adapter."""
275
def test_adapted_tests(self):
276
# check that constructor parameters are passed through to the adapted
278
from bzrlib.store.revision import RevisionStoreTestProviderAdapter
279
input_test = TestRevisionStoreProviderAdapter(
280
"test_adapted_tests")
281
# revision stores need a store factory - i.e. RevisionKnit
282
#, a readonly and rw transport
286
store_factories = ["c", "d"]
287
adapter = RevisionStoreTestProviderAdapter(server1, server2, store_factories)
288
suite = adapter.adapt(input_test)
289
tests = list(iter(suite))
290
self.assertEqual(2, len(tests))
291
self.assertEqual(tests[0].store_factory, store_factories[0][0])
292
self.assertEqual(tests[0].transport_server, server1)
293
self.assertEqual(tests[0].transport_readonly_server, server2)
294
self.assertEqual(tests[1].store_factory, store_factories[1][0])
295
self.assertEqual(tests[1].transport_server, server1)
296
self.assertEqual(tests[1].transport_readonly_server, server2)
299
class TestWorkingTreeProviderAdapter(TestCase):
300
"""A group of tests that test the workingtree implementation test adapter."""
302
def test_adapted_tests(self):
303
# check that constructor parameters are passed through to the adapted
305
from bzrlib.workingtree import WorkingTreeTestProviderAdapter
306
input_test = TestWorkingTreeProviderAdapter(
307
"test_adapted_tests")
310
formats = [("c", "C"), ("d", "D")]
311
adapter = WorkingTreeTestProviderAdapter(server1, server2, formats)
312
suite = adapter.adapt(input_test)
313
tests = list(iter(suite))
314
self.assertEqual(2, len(tests))
315
self.assertEqual(tests[0].workingtree_format, formats[0][0])
316
self.assertEqual(tests[0].bzrdir_format, formats[0][1])
317
self.assertEqual(tests[0].transport_server, server1)
318
self.assertEqual(tests[0].transport_readonly_server, server2)
319
self.assertEqual(tests[1].workingtree_format, formats[1][0])
320
self.assertEqual(tests[1].bzrdir_format, formats[1][1])
321
self.assertEqual(tests[1].transport_server, server1)
322
self.assertEqual(tests[1].transport_readonly_server, server2)
325
class TestTestCaseWithTransport(TestCaseWithTransport):
326
"""Tests for the convenience functions TestCaseWithTransport introduces."""
328
def test_get_readonly_url_none(self):
329
from bzrlib.transport import get_transport
330
from bzrlib.transport.memory import MemoryServer
331
from bzrlib.transport.readonly import ReadonlyTransportDecorator
332
self.transport_server = MemoryServer
333
self.transport_readonly_server = None
334
# calling get_readonly_transport() constructs a decorator on the url
336
url = self.get_readonly_url()
337
url2 = self.get_readonly_url('foo/bar')
338
t = get_transport(url)
339
t2 = get_transport(url2)
340
self.failUnless(isinstance(t, ReadonlyTransportDecorator))
341
self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
342
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
344
def test_get_readonly_url_http(self):
345
from bzrlib.transport import get_transport
346
from bzrlib.transport.local import LocalRelpathServer
347
from bzrlib.transport.http import HttpServer, HttpTransportBase
348
self.transport_server = LocalRelpathServer
349
self.transport_readonly_server = HttpServer
350
# calling get_readonly_transport() gives us a HTTP server instance.
351
url = self.get_readonly_url()
352
url2 = self.get_readonly_url('foo/bar')
353
# the transport returned may be any HttpTransportBase subclass
354
t = get_transport(url)
355
t2 = get_transport(url2)
356
self.failUnless(isinstance(t, HttpTransportBase))
357
self.failUnless(isinstance(t2, HttpTransportBase))
358
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
360
def test_is_directory(self):
361
"""Test assertIsDirectory assertion"""
362
t = self.get_transport()
363
self.build_tree(['a_dir/', 'a_file'], transport=t)
364
self.assertIsDirectory('a_dir', t)
365
self.assertRaises(AssertionError, self.assertIsDirectory, 'a_file', t)
366
self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
369
class TestChrootedTest(ChrootedTestCase):
371
def test_root_is_root(self):
372
from bzrlib.transport import get_transport
373
t = get_transport(self.get_readonly_url())
375
self.assertEqual(url, t.clone('..').base)
378
class MockProgress(_BaseProgressBar):
379
"""Progress-bar standin that records calls.
381
Useful for testing pb using code.
385
_BaseProgressBar.__init__(self)
389
self.calls.append(('tick',))
391
def update(self, msg=None, current=None, total=None):
392
self.calls.append(('update', msg, current, total))
395
self.calls.append(('clear',))
398
class TestTestResult(TestCase):
400
def test_progress_bar_style_quiet(self):
401
# test using a progress bar.
402
dummy_test = TestTestResult('test_progress_bar_style_quiet')
403
dummy_error = (Exception, None, [])
404
mypb = MockProgress()
405
mypb.update('Running tests', 0, 4)
406
last_calls = mypb.calls[:]
407
result = bzrlib.tests._MyResult(self._log_file,
411
self.assertEqual(last_calls, mypb.calls)
414
result.startTest(dummy_test)
415
# starting a test prints the test name
416
self.assertEqual(last_calls + [('update', '...tyle_quiet', 0, None)], mypb.calls)
417
last_calls = mypb.calls[:]
418
result.addError(dummy_test, dummy_error)
419
self.assertEqual(last_calls + [('update', 'ERROR ', 1, None)], mypb.calls)
420
last_calls = mypb.calls[:]
423
result.startTest(dummy_test)
424
self.assertEqual(last_calls + [('update', '...tyle_quiet', 1, None)], mypb.calls)
425
last_calls = mypb.calls[:]
426
result.addFailure(dummy_test, dummy_error)
427
self.assertEqual(last_calls + [('update', 'FAIL ', 2, None)], mypb.calls)
428
last_calls = mypb.calls[:]
431
result.startTest(dummy_test)
432
self.assertEqual(last_calls + [('update', '...tyle_quiet', 2, None)], mypb.calls)
433
last_calls = mypb.calls[:]
434
result.addSuccess(dummy_test)
435
self.assertEqual(last_calls + [('update', 'OK ', 3, None)], mypb.calls)
436
last_calls = mypb.calls[:]
439
result.startTest(dummy_test)
440
self.assertEqual(last_calls + [('update', '...tyle_quiet', 3, None)], mypb.calls)
441
last_calls = mypb.calls[:]
442
result.addSkipped(dummy_test, dummy_error)
443
self.assertEqual(last_calls + [('update', 'SKIP ', 4, None)], mypb.calls)
444
last_calls = mypb.calls[:]
446
def test_elapsed_time_with_benchmarking(self):
447
result = bzrlib.tests._MyResult(self._log_file,
451
result._recordTestStartTime()
453
result.extractBenchmarkTime(self)
454
timed_string = result._testTimeString()
455
# without explicit benchmarking, we should get a simple time.
456
self.assertContainsRe(timed_string, "^ [ 1-9][0-9]ms$")
457
# if a benchmark time is given, we want a x of y style result.
458
self.time(time.sleep, 0.001)
459
result.extractBenchmarkTime(self)
460
timed_string = result._testTimeString()
461
self.assertContainsRe(timed_string, "^ [ 1-9][0-9]ms/ [ 1-9][0-9]ms$")
462
# extracting the time from a non-bzrlib testcase sets to None
463
result._recordTestStartTime()
464
result.extractBenchmarkTime(
465
unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
466
timed_string = result._testTimeString()
467
self.assertContainsRe(timed_string, "^ [ 1-9][0-9]ms$")
468
# cheat. Yes, wash thy mouth out with soap.
469
self._benchtime = None
471
def _time_hello_world_encoding(self):
472
"""Profile two sleep calls
474
This is used to exercise the test framework.
476
self.time(unicode, 'hello', errors='replace')
477
self.time(unicode, 'world', errors='replace')
479
def test_lsprofiling(self):
480
"""Verbose test result prints lsprof statistics from test cases."""
484
raise TestSkipped("lsprof not installed.")
485
result_stream = StringIO()
486
result = bzrlib.tests._MyResult(
487
unittest._WritelnDecorator(result_stream),
491
# we want profile a call of some sort and check it is output by
492
# addSuccess. We dont care about addError or addFailure as they
493
# are not that interesting for performance tuning.
494
# make a new test instance that when run will generate a profile
495
example_test_case = TestTestResult("_time_hello_world_encoding")
496
example_test_case._gather_lsprof_in_benchmarks = True
497
# execute the test, which should succeed and record profiles
498
example_test_case.run(result)
499
# lsprofile_something()
500
# if this worked we want
501
# LSProf output for <built in function unicode> (['hello'], {'errors': 'replace'})
502
# CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
503
# (the lsprof header)
504
# ... an arbitrary number of lines
505
# and the function call which is time.sleep.
506
# 1 0 ??? ??? ???(sleep)
507
# and then repeated but with 'world', rather than 'hello'.
508
# this should appear in the output stream of our test result.
509
self.assertContainsRe(result_stream.getvalue(),
510
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)\n"
511
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
512
r"( +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n)?"
513
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n"
514
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
515
r"( +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n)?"
519
class TestRunner(TestCase):
521
def dummy_test(self):
524
def run_test_runner(self, testrunner, test):
525
"""Run suite in testrunner, saving global state and restoring it.
527
This current saves and restores:
528
TestCaseInTempDir.TEST_ROOT
530
There should be no tests in this file that use bzrlib.tests.TextTestRunner
531
without using this convenience method, because of our use of global state.
533
old_root = TestCaseInTempDir.TEST_ROOT
535
TestCaseInTempDir.TEST_ROOT = None
536
return testrunner.run(test)
538
TestCaseInTempDir.TEST_ROOT = old_root
540
def test_accepts_and_uses_pb_parameter(self):
541
test = TestRunner('dummy_test')
542
mypb = MockProgress()
543
self.assertEqual([], mypb.calls)
544
runner = TextTestRunner(stream=self._log_file, pb=mypb)
545
result = self.run_test_runner(runner, test)
546
self.assertEqual(1, result.testsRun)
547
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
548
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
549
self.assertEqual(('update', 'OK ', 1, None), mypb.calls[2])
550
self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
551
self.assertEqual(('clear',), mypb.calls[4])
552
self.assertEqual(5, len(mypb.calls))
554
def test_skipped_test(self):
555
# run a test that is skipped, and check the suite as a whole still
557
# skipping_test must be hidden in here so it's not run as a real test
559
raise TestSkipped('test intentionally skipped')
560
runner = TextTestRunner(stream=self._log_file, keep_output=True)
561
test = unittest.FunctionTestCase(skipping_test)
562
result = self.run_test_runner(runner, test)
563
self.assertTrue(result.wasSuccessful())
566
class TestTestCase(TestCase):
567
"""Tests that test the core bzrlib TestCase."""
569
def inner_test(self):
570
# the inner child test
573
def outer_child(self):
574
# the outer child test
576
self.inner_test = TestTestCase("inner_child")
577
result = bzrlib.tests._MyResult(self._log_file,
580
self.inner_test.run(result)
583
def test_trace_nesting(self):
584
# this tests that each test case nests its trace facility correctly.
585
# we do this by running a test case manually. That test case (A)
586
# should setup a new log, log content to it, setup a child case (B),
587
# which should log independently, then case (A) should log a trailer
589
# we do two nested children so that we can verify the state of the
590
# logs after the outer child finishes is correct, which a bad clean
591
# up routine in tearDown might trigger a fault in our test with only
592
# one child, we should instead see the bad result inside our test with
594
# the outer child test
595
original_trace = bzrlib.trace._trace_file
596
outer_test = TestTestCase("outer_child")
597
result = bzrlib.tests._MyResult(self._log_file,
600
outer_test.run(result)
601
self.assertEqual(original_trace, bzrlib.trace._trace_file)
603
def method_that_times_a_bit_twice(self):
604
# call self.time twice to ensure it aggregates
605
self.time(time.sleep, 0.007)
606
self.time(time.sleep, 0.007)
608
def test_time_creates_benchmark_in_result(self):
609
"""Test that the TestCase.time() method accumulates a benchmark time."""
610
sample_test = TestTestCase("method_that_times_a_bit_twice")
611
output_stream = StringIO()
612
result = bzrlib.tests._MyResult(
613
unittest._WritelnDecorator(output_stream),
616
sample_test.run(result)
617
self.assertContainsRe(
618
output_stream.getvalue(),
619
"[1-9][0-9]ms/ [1-9][0-9]ms\n$")
621
def test__gather_lsprof_in_benchmarks(self):
622
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.
624
Each self.time() call is individually and separately profiled.
629
raise TestSkipped("lsprof not installed.")
630
# overrides the class member with an instance member so no cleanup
632
self._gather_lsprof_in_benchmarks = True
633
self.time(time.sleep, 0.000)
634
self.time(time.sleep, 0.003)
635
self.assertEqual(2, len(self._benchcalls))
636
self.assertEqual((time.sleep, (0.000,), {}), self._benchcalls[0][0])
637
self.assertEqual((time.sleep, (0.003,), {}), self._benchcalls[1][0])
638
self.assertIsInstance(self._benchcalls[0][1], bzrlib.lsprof.Stats)
639
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
642
class TestExtraAssertions(TestCase):
643
"""Tests for new test assertions in bzrlib test suite"""
645
def test_assert_isinstance(self):
646
self.assertIsInstance(2, int)
647
self.assertIsInstance(u'', basestring)
648
self.assertRaises(AssertionError, self.assertIsInstance, None, int)
649
self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
651
def test_assertEndsWith(self):
652
self.assertEndsWith('foo', 'oo')
653
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
656
class TestConvenienceMakers(TestCaseWithTransport):
657
"""Test for the make_* convenience functions."""
659
def test_make_branch_and_tree_with_format(self):
660
# we should be able to supply a format to make_branch_and_tree
661
self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1())
662
self.make_branch_and_tree('b', format=bzrlib.bzrdir.BzrDirFormat6())
663
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format,
664
bzrlib.bzrdir.BzrDirMetaFormat1)
665
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
666
bzrlib.bzrdir.BzrDirFormat6)
669
class TestSelftest(TestCase):
670
"""Tests of bzrlib.tests.selftest."""
672
def test_selftest_benchmark_parameter_invokes_test_suite__benchmark__(self):
675
factory_called.append(True)
679
self.apply_redirected(out, err, None, bzrlib.tests.selftest,
680
test_suite_factory=factory)
681
self.assertEqual([True], factory_called)
683
def test_run_bzr_external(self):
684
"""The run_bzr_helper_external comand behaves nicely."""
685
result = self.run_bzr_external('--version')
686
self.assertContainsRe(result[0], 'is free software')
687
self.assertRaises(AssertionError, self.run_bzr_external, '--versionn')
688
result = self.run_bzr_external('--versionn', retcode=3)
689
self.assertContainsRe(result[1], 'unknown command')
690
err = self.run_bzr_external('merge --merge-type "magic merge"',
692
self.assertContainsRe(err, 'No known merge type magic merge')
693
err = self.run_bzr_external('merge', '--merge-type', 'magic merge',
695
self.assertContainsRe(err, 'No known merge type magic merge')