336
337
formats = [workingtree_4.WorkingTreeFormat4(),
337
workingtree_3.WorkingTreeFormat3(),]
338
scenarios = make_scenarios(server1, server2, formats)
338
workingtree_3.WorkingTreeFormat3(),
339
workingtree_4.WorkingTreeFormat6()]
340
scenarios = make_scenarios(server1, server2, formats,
341
remote_server='c', remote_readonly_server='d',
342
remote_backing_server='e')
339
343
self.assertEqual([
340
344
('WorkingTreeFormat4',
341
345
{'bzrdir_format': formats[0]._matchingbzrdir,
346
350
{'bzrdir_format': formats[1]._matchingbzrdir,
347
351
'transport_readonly_server': 'b',
348
352
'transport_server': 'a',
349
'workingtree_format': formats[1]})],
353
'workingtree_format': formats[1]}),
354
('WorkingTreeFormat6',
355
{'bzrdir_format': formats[2]._matchingbzrdir,
356
'transport_readonly_server': 'b',
357
'transport_server': 'a',
358
'workingtree_format': formats[2]}),
359
('WorkingTreeFormat6,remote',
360
{'bzrdir_format': formats[2]._matchingbzrdir,
361
'repo_is_remote': True,
362
'transport_readonly_server': 'd',
363
'transport_server': 'c',
364
'vfs_transport_factory': 'e',
365
'workingtree_format': formats[2]}),
353
369
class TestTreeScenarios(tests.TestCase):
355
371
def test_scenarios(self):
356
372
# the tree implementation scenario generator is meant to setup one
357
# instance for each working tree format, and one additional instance
373
# instance for each working tree format, one additional instance
358
374
# that will use the default wt format, but create a revision tree for
359
# the tests. this means that the wt ones should have the
360
# workingtree_to_test_tree attribute set to 'return_parameter' and the
361
# revision one set to revision_tree_from_workingtree.
375
# the tests, and one more that uses the default wt format as a
376
# lightweight checkout of a remote repository. This means that the wt
377
# ones should have the workingtree_to_test_tree attribute set to
378
# 'return_parameter' and the revision one set to
379
# revision_tree_from_workingtree.
363
381
from bzrlib.tests.per_tree import (
364
382
_dirstate_tree_from_workingtree,
391
smart_server = test_server.SmartTCPServer_for_testing
392
smart_readonly_server = test_server.ReadonlySmartTCPServer_for_testing
393
mem_server = memory.MemoryServer
373
394
formats = [workingtree_4.WorkingTreeFormat4(),
374
395
workingtree_3.WorkingTreeFormat3(),]
375
396
scenarios = make_scenarios(server1, server2, formats)
376
self.assertEqual(7, len(scenarios))
397
self.assertEqual(8, len(scenarios))
377
398
default_wt_format = workingtree.format_registry.get_default()
378
399
wt4_format = workingtree_4.WorkingTreeFormat4()
379
400
wt5_format = workingtree_4.WorkingTreeFormat5()
401
wt6_format = workingtree_4.WorkingTreeFormat6()
380
402
expected_scenarios = [
381
403
('WorkingTreeFormat4',
382
404
{'bzrdir_format': formats[0]._matchingbzrdir,
392
414
'workingtree_format': formats[1],
393
415
'_workingtree_to_test_tree': return_parameter,
417
('WorkingTreeFormat6,remote',
418
{'bzrdir_format': wt6_format._matchingbzrdir,
419
'repo_is_remote': True,
420
'transport_readonly_server': smart_readonly_server,
421
'transport_server': smart_server,
422
'vfs_transport_factory': mem_server,
423
'workingtree_format': wt6_format,
424
'_workingtree_to_test_tree': return_parameter,
396
427
{'_workingtree_to_test_tree': revision_tree_from_workingtree,
397
428
'bzrdir_format': default_wt_format._matchingbzrdir,
609
640
# Guard against regression into MemoryTransport leaking
610
641
# files to disk instead of keeping them in memory.
611
642
self.assertFalse(osutils.lexists('dir'))
612
dir_format = bzrdir.format_registry.make_bzrdir('knit')
643
dir_format = controldir.format_registry.make_bzrdir('knit')
613
644
self.assertEqual(dir_format.repository_format.__class__,
614
645
the_branch.repository._format.__class__)
615
646
self.assertEqual('Bazaar-NG Knit Repository Format 1',
678
709
builder = self.make_branch_builder('dir')
679
710
rev_id = builder.build_commit()
680
711
self.assertPathExists('dir')
681
a_dir = bzrdir.BzrDir.open('dir')
712
a_dir = controldir.ControlDir.open('dir')
682
713
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
683
714
a_branch = a_dir.open_branch()
684
715
builder_branch = builder.get_branch()
1477
1508
transport_server.start_server()
1478
1509
self.addCleanup(transport_server.stop_server)
1479
1510
t = transport.get_transport_from_url(transport_server.get_url())
1480
bzrdir.BzrDir.create(t.base)
1511
controldir.ControlDir.create(t.base)
1481
1512
self.assertRaises(errors.BzrError,
1482
bzrdir.BzrDir.open_from_transport, t)
1513
controldir.ControlDir.open_from_transport, t)
1483
1514
# But if we declare this as safe, we can open the bzrdir.
1484
1515
self.permit_url(t.base)
1485
1516
self._bzr_selftest_roots.append(t.base)
1486
bzrdir.BzrDir.open_from_transport(t)
1517
controldir.ControlDir.open_from_transport(t)
1488
1519
def test_requireFeature_available(self):
1489
1520
"""self.requireFeature(available) is a no-op."""
1623
1654
self.assertRaises(AssertionError,
1624
1655
self.assertListRaises, _TestException, success_generator)
1657
def _run_successful_test(self, test):
1658
result = testtools.TestResult()
1660
self.assertTrue(result.wasSuccessful())
1626
1663
def test_overrideAttr_without_value(self):
1627
1664
self.test_attr = 'original' # Define a test attribute
1628
1665
obj = self # Make 'obj' visible to the embedded test
1629
1666
class Test(tests.TestCase):
1631
1668
def setUp(self):
1632
tests.TestCase.setUp(self)
1669
super(Test, self).setUp()
1633
1670
self.orig = self.overrideAttr(obj, 'test_attr')
1635
1672
def test_value(self):
1638
1675
obj.test_attr = 'modified'
1639
1676
self.assertEqual('modified', obj.test_attr)
1641
test = Test('test_value')
1642
test.run(unittest.TestResult())
1678
self._run_successful_test(Test('test_value'))
1643
1679
self.assertEqual('original', obj.test_attr)
1645
1681
def test_overrideAttr_with_value(self):
1648
1684
class Test(tests.TestCase):
1650
1686
def setUp(self):
1651
tests.TestCase.setUp(self)
1687
super(Test, self).setUp()
1652
1688
self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
1654
1690
def test_value(self):
1655
1691
self.assertEqual('original', self.orig)
1656
1692
self.assertEqual('modified', obj.test_attr)
1658
test = Test('test_value')
1659
test.run(unittest.TestResult())
1694
self._run_successful_test(Test('test_value'))
1660
1695
self.assertEqual('original', obj.test_attr)
1697
def test_overrideAttr_with_no_existing_value_and_value(self):
1698
# Do not define the test_attribute
1699
obj = self # Make 'obj' visible to the embedded test
1700
class Test(tests.TestCase):
1703
tests.TestCase.setUp(self)
1704
self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
1706
def test_value(self):
1707
self.assertEqual(tests._unitialized_attr, self.orig)
1708
self.assertEqual('modified', obj.test_attr)
1710
self._run_successful_test(Test('test_value'))
1711
self.assertRaises(AttributeError, getattr, obj, 'test_attr')
1713
def test_overrideAttr_with_no_existing_value_and_no_value(self):
1714
# Do not define the test_attribute
1715
obj = self # Make 'obj' visible to the embedded test
1716
class Test(tests.TestCase):
1719
tests.TestCase.setUp(self)
1720
self.orig = self.overrideAttr(obj, 'test_attr')
1722
def test_value(self):
1723
self.assertEqual(tests._unitialized_attr, self.orig)
1724
self.assertRaises(AttributeError, getattr, obj, 'test_attr')
1726
self._run_successful_test(Test('test_value'))
1727
self.assertRaises(AttributeError, getattr, obj, 'test_attr')
1662
1729
def test_recordCalls(self):
1663
1730
from bzrlib.tests import test_selftest
1664
1731
calls = self.recordCalls(
1943
2010
def test_make_branch_and_tree_with_format(self):
1944
2011
# we should be able to supply a format to make_branch_and_tree
1945
2012
self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1())
1946
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format,
2013
self.assertIsInstance(bzrlib.controldir.ControlDir.open('a')._format,
1947
2014
bzrlib.bzrdir.BzrDirMetaFormat1)
1949
2016
def test_make_branch_and_memory_tree(self):
2381
2448
"""Base class for tests testing how we might run bzr."""
2383
2450
def setUp(self):
2384
tests.TestCaseWithTransport.setUp(self)
2451
super(TestWithFakedStartBzrSubprocess, self).setUp()
2385
2452
self.subprocess_calls = []
2387
2454
def start_bzr_subprocess(self, process_args, env_changes=None,
2601
2668
class TestSelftestFiltering(tests.TestCase):
2603
2670
def setUp(self):
2604
tests.TestCase.setUp(self)
2671
super(TestSelftestFiltering, self).setUp()
2605
2672
self.suite = TestUtil.TestSuite()
2606
2673
self.loader = TestUtil.TestLoader()
2607
2674
self.suite.addTest(self.loader.loadTestsFromModule(