116
116
def build_control_store(test):
117
117
build_backing_branch(test, 'branch')
118
b = bzrdir.BzrDir.open('branch')
118
b = controldir.ControlDir.open('branch')
119
119
return config.ControlStore(b)
120
120
config.test_store_builder_registry.register('control', build_control_store)
1086
1086
def test_get_config(self):
1087
1087
"""The Branch.get_config method works properly"""
1088
b = bzrdir.BzrDir.create_standalone_workingtree('.').branch
1088
b = controldir.ControlDir.create_standalone_workingtree('.').branch
1089
1089
my_config = b.get_config()
1090
1090
self.assertIs(my_config.get_user_option('wacky'), None)
1091
1091
my_config.set_user_option('wacky', 'unlikely')
1140
1140
b = self.make_branch('!repo')
1141
1141
self.assertEqual('!repo', b.get_config().get_nickname())
1143
def test_autonick_uses_branch_name(self):
1144
b = self.make_branch('foo', name='bar')
1145
self.assertEqual('bar', b.get_config().get_nickname())
1143
1147
def test_warn_if_masked(self):
1145
1149
def warning(*args):
2142
2146
self.assertGetHook(remote_branch._get_config(), 'file', 'branch')
2144
2148
def test_get_hook_remote_bzrdir(self):
2145
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2149
remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2146
2150
conf = remote_bzrdir._get_config()
2147
2151
conf.set_option('remotedir', 'file')
2148
2152
self.assertGetHook(conf, 'file', 'remotedir')
2170
2174
def test_set_hook_remote_bzrdir(self):
2171
2175
remote_branch = branch.Branch.open(self.get_url('tree'))
2172
2176
self.addCleanup(remote_branch.lock_write().unlock)
2173
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2177
remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2174
2178
self.assertSetHook(remote_bzrdir._get_config(), 'file', 'remotedir')
2176
2180
def assertLoadHook(self, expected_nb_calls, name, conf_class, *conf_args):
2193
2197
self.assertLoadHook(1, 'file', remote.RemoteBranchConfig, remote_branch)
2195
2199
def test_load_hook_remote_bzrdir(self):
2196
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2200
remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2197
2201
# The config file doesn't exist, set an option to force its creation
2198
2202
conf = remote_bzrdir._get_config()
2199
2203
conf.set_option('remotedir', 'file')
2224
2228
def test_save_hook_remote_bzrdir(self):
2225
2229
remote_branch = branch.Branch.open(self.get_url('tree'))
2226
2230
self.addCleanup(remote_branch.lock_write().unlock)
2227
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2231
remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2228
2232
self.assertSaveHook(remote_bzrdir._get_config())
2267
2271
opt = config.Option('foo', default=bar_not_unicode)
2268
2272
self.assertRaises(AssertionError, opt.get_default)
2274
def test_get_help_topic(self):
2275
opt = config.Option('foo')
2276
self.assertEquals('foo', opt.get_help_topic())
2271
2279
class TestOptionConverterMixin(object):
3613
3621
self.assertEquals('bar', conf.get('foo'))
3624
class TestStackIterSections(tests.TestCase):
3626
def test_empty_stack(self):
3627
conf = config.Stack([])
3628
sections = list(conf.iter_sections())
3629
self.assertLength(0, sections)
3631
def test_empty_store(self):
3632
store = config.IniFileStore()
3633
store._load_from_string('')
3634
conf = config.Stack([store.get_sections])
3635
sections = list(conf.iter_sections())
3636
self.assertLength(0, sections)
3638
def test_simple_store(self):
3639
store = config.IniFileStore()
3640
store._load_from_string('foo=bar')
3641
conf = config.Stack([store.get_sections])
3642
tuples = list(conf.iter_sections())
3643
self.assertLength(1, tuples)
3644
(found_store, found_section) = tuples[0]
3645
self.assertIs(store, found_store)
3647
def test_two_stores(self):
3648
store1 = config.IniFileStore()
3649
store1._load_from_string('foo=bar')
3650
store2 = config.IniFileStore()
3651
store2._load_from_string('bar=qux')
3652
conf = config.Stack([store1.get_sections, store2.get_sections])
3653
tuples = list(conf.iter_sections())
3654
self.assertLength(2, tuples)
3655
self.assertIs(store1, tuples[0][0])
3656
self.assertIs(store2, tuples[1][0])
3616
3659
class TestStackWithTransport(tests.TestCaseWithTransport):
3618
3661
scenarios = [(key, {'get_stack': builder}) for key, builder
3901
self.registry.register(
3902
config.ListOption('list'))
3944
self.registry.register(config.ListOption('list'))
3945
# Register an intermediate option as a list to ensure no conversion
3946
# happen while expanding. Conversion should only occur for the original
3947
# option ('list' here).
3948
self.registry.register(config.ListOption('baz'))
3903
3949
self.assertEquals(['start', 'middle', 'end'],
3904
3950
self.conf.get('list', expand=True))