131
def create_configs(test):
132
"""Create configuration files for a given test.
134
This requires creating a tree (and populate the ``test.tree`` attribute)
135
and its associated branch and will populate the following attributes:
137
- branch_config: A BranchConfig for the associated branch.
139
- locations_config : A LocationConfig for the associated branch
141
- bazaar_config: A GlobalConfig.
143
The tree and branch are created in a 'tree' subdirectory so the tests can
144
still use the test directory to stay outside of the branch.
146
tree = test.make_branch_and_tree('tree')
148
test.branch_config = config.BranchConfig(tree.branch)
149
test.locations_config = config.LocationConfig(tree.basedir)
150
test.bazaar_config = config.GlobalConfig()
153
def create_configs_with_file_option(test):
154
"""Create configuration files with a ``file`` option set in each.
156
This builds on ``create_configs`` and add one ``file`` option in each
157
configuration with a value which allows identifying the configuration file.
160
test.bazaar_config.set_user_option('file', 'bazaar')
161
test.locations_config.set_user_option('file', 'locations')
162
test.branch_config.set_user_option('file', 'branch')
165
class TestOptionsMixin:
167
def assertOptions(self, expected, conf):
168
# We don't care about the parser (as it will make tests hard to write
169
# and error-prone anyway)
170
self.assertThat([opt[:4] for opt in conf._get_options()],
171
matchers.Equals(expected))
128
174
class InstrumentedConfigObj(object):
129
175
"""A config obj look-enough-alike to record calls made to it."""
902
948
self.assertIs(None, new_config.get_alias('commit'))
905
class TestLocationConfig(tests.TestCaseInTempDir):
951
class TestLocationConfig(tests.TestCaseInTempDir, TestOptionsMixin):
907
953
def test_constructs(self):
908
954
my_config = config.LocationConfig('http://example.com')
1016
1062
'http://www.example.com', 'appendpath_option'),
1017
1063
config.POLICY_APPENDPATH)
1065
def test__get_options_with_policy(self):
1066
self.get_branch_config('/dir/subdir',
1067
location_config="""\
1069
other_url = /other-dir
1070
other_url:policy = appendpath
1072
other_url = /other-subdir
1075
[(u'other_url', u'/other-subdir', u'/dir/subdir', 'locations'),
1076
(u'other_url', u'/other-dir', u'/dir', 'locations'),
1077
(u'other_url:policy', u'appendpath', u'/dir', 'locations')],
1078
self.my_location_config)
1019
1080
def test_location_without_username(self):
1020
1081
self.get_branch_config('http://www.example.com/ignoreparent')
1021
1082
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
1157
1218
self.assertEqual('bzrlib.tests.test_config.post_commit',
1158
1219
self.my_config.post_commit())
1160
def get_branch_config(self, location, global_config=None):
1221
def get_branch_config(self, location, global_config=None,
1222
location_config=None):
1161
1223
my_branch = FakeBranch(location)
1162
1224
if global_config is None:
1163
1225
global_config = sample_config_text
1226
if location_config is None:
1227
location_config = sample_branches_text
1165
1229
my_global_config = config.GlobalConfig.from_string(global_config,
1167
1231
my_location_config = config.LocationConfig.from_string(
1168
sample_branches_text, my_branch.base, save=True)
1232
location_config, my_branch.base, save=True)
1169
1233
my_config = config.BranchConfig(my_branch)
1170
1234
self.my_config = my_config
1171
1235
self.my_location_config = my_config._get_location_config()
1467
1531
self.assertIs(None, bzrdir_config.get_default_stack_on())
1470
def create_configs(test):
1471
"""Create configuration files for a given test.
1473
This requires creating a tree (and populate the ``test.tree`` attribute)
1474
and its associated branch and will populate the following attributes:
1476
- branch_config: A BranchConfig for the associated branch.
1478
- locations_config : A LocationConfig for the associated branch
1480
- bazaar_config: A GlobalConfig.
1482
The tree and branch are created in a 'tree' subdirectory so the tests can
1483
still use the test directory to stay outside of the branch.
1485
tree = test.make_branch_and_tree('tree')
1487
test.branch_config = config.BranchConfig(tree.branch)
1488
test.locations_config = config.LocationConfig(tree.basedir)
1489
test.bazaar_config = config.GlobalConfig()
1492
def create_configs_with_file_option(test):
1493
"""Create configuration files with a ``file`` option set in each.
1495
This builds on ``create_configs`` and add one ``file`` option in each
1496
configuration with a value which allows identifying the configuration file.
1498
create_configs(test)
1499
test.bazaar_config.set_user_option('file', 'bazaar')
1500
test.locations_config.set_user_option('file', 'locations')
1501
test.branch_config.set_user_option('file', 'branch')
1504
class TestConfigGetOptions(tests.TestCaseWithTransport):
1534
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
1506
1536
def setUp(self):
1507
1537
super(TestConfigGetOptions, self).setUp()
1508
1538
create_configs(self)
1510
def assertOptions(self, expected, conf):
1511
actual = list(conf._get_options())
1512
self.assertEqual(expected, actual)
1514
1540
# One variable in none of the above
1515
1541
def test_no_variable(self):
1516
1542
# Using branch should query branch, locations and bazaar
1559
1585
self.branch_config)
1562
class TestConfigRemoveOption(tests.TestCaseWithTransport):
1588
class TestConfigRemoveOption(tests.TestCaseWithTransport, TestOptionsMixin):
1564
1590
def setUp(self):
1565
1591
super(TestConfigRemoveOption, self).setUp()
1566
1592
create_configs_with_file_option(self)
1568
def assertOptions(self, expected, conf):
1569
actual = list(conf._get_options())
1570
self.assertEqual(expected, actual)
1572
1594
def test_remove_in_locations(self):
1573
1595
self.locations_config.remove_user_option('file', self.tree.basedir)
1574
1596
self.assertOptions(