1906
1909
self.assertIs(None, bzrdir_config.get_default_stack_on())
1912
class TestOldConfigHooks(tests.TestCaseWithTransport):
1915
super(TestOldConfigHooks, self).setUp()
1916
create_configs_with_file_option(self)
1918
def assertGetHook(self, conf, name, value):
1922
config.OldConfigHooks.install_named_hook('get', hook, None)
1924
config.OldConfigHooks.uninstall_named_hook, 'get', None)
1925
self.assertLength(0, calls)
1926
actual_value = conf.get_user_option(name)
1927
self.assertEquals(value, actual_value)
1928
self.assertLength(1, calls)
1929
self.assertEquals((conf, name, value), calls[0])
1931
def test_get_hook_bazaar(self):
1932
self.assertGetHook(self.bazaar_config, 'file', 'bazaar')
1934
def test_get_hook_locations(self):
1935
self.assertGetHook(self.locations_config, 'file', 'locations')
1937
def test_get_hook_branch(self):
1938
# Since locations masks branch, we define a different option
1939
self.branch_config.set_user_option('file2', 'branch')
1940
self.assertGetHook(self.branch_config, 'file2', 'branch')
1942
def assertSetHook(self, conf, name, value):
1946
config.OldConfigHooks.install_named_hook('set', hook, None)
1948
config.OldConfigHooks.uninstall_named_hook, 'set', None)
1949
self.assertLength(0, calls)
1950
conf.set_user_option(name, value)
1951
self.assertLength(1, calls)
1952
# We can't assert the conf object below as different configs use
1953
# different means to implement set_user_option and we care only about
1955
self.assertEquals((name, value), calls[0][1:])
1957
def test_set_hook_bazaar(self):
1958
self.assertSetHook(self.bazaar_config, 'foo', 'bazaar')
1960
def test_set_hook_locations(self):
1961
self.assertSetHook(self.locations_config, 'foo', 'locations')
1963
def test_set_hook_branch(self):
1964
self.assertSetHook(self.branch_config, 'foo', 'branch')
1966
def assertRemoveHook(self, conf, name, section_name=None):
1970
config.OldConfigHooks.install_named_hook('remove', hook, None)
1972
config.OldConfigHooks.uninstall_named_hook, 'remove', None)
1973
self.assertLength(0, calls)
1974
conf.remove_user_option(name, section_name)
1975
self.assertLength(1, calls)
1976
# We can't assert the conf object below as different configs use
1977
# different means to implement remove_user_option and we care only about
1979
self.assertEquals((name,), calls[0][1:])
1981
def test_remove_hook_bazaar(self):
1982
self.assertRemoveHook(self.bazaar_config, 'file')
1984
def test_remove_hook_locations(self):
1985
self.assertRemoveHook(self.locations_config, 'file',
1986
self.locations_config.location)
1988
def test_remove_hook_branch(self):
1989
self.assertRemoveHook(self.branch_config, 'file')
1991
def assertLoadHook(self, name, conf_class, *conf_args):
1995
config.OldConfigHooks.install_named_hook('load', hook, None)
1997
config.OldConfigHooks.uninstall_named_hook, 'load', None)
1998
self.assertLength(0, calls)
2000
conf = conf_class(*conf_args)
2001
# Access an option to trigger a load
2002
conf.get_user_option(name)
2003
self.assertLength(1, calls)
2004
# Since we can't assert about conf, we just use the number of calls ;-/
2006
def test_load_hook_bazaar(self):
2007
self.assertLoadHook('file', config.GlobalConfig)
2009
def test_load_hook_locations(self):
2010
self.assertLoadHook('file', config.LocationConfig, self.tree.basedir)
2012
def test_load_hook_branch(self):
2013
self.assertLoadHook('file', config.BranchConfig, self.tree.branch)
2015
def assertSaveHook(self, conf):
2019
config.OldConfigHooks.install_named_hook('save', hook, None)
2021
config.OldConfigHooks.uninstall_named_hook, 'save', None)
2022
self.assertLength(0, calls)
2023
# Setting an option triggers a save
2024
conf.set_user_option('foo', 'bar')
2025
self.assertLength(1, calls)
2026
# Since we can't assert about conf, we just use the number of calls ;-/
2028
def test_save_hook_bazaar(self):
2029
self.assertSaveHook(self.bazaar_config)
2031
def test_save_hook_locations(self):
2032
self.assertSaveHook(self.locations_config)
2034
def test_save_hook_branch(self):
2035
self.assertSaveHook(self.branch_config)
2038
class TestOldConfigHooksForRemote(tests.TestCaseWithTransport):
2039
"""Tests config hooks for remote configs.
2041
No tests for the remove hook as this is not implemented there.
2045
super(TestOldConfigHooksForRemote, self).setUp()
2046
self.transport_server = test_server.SmartTCPServer_for_testing
2047
create_configs_with_file_option(self)
2049
def assertGetHook(self, conf, name, value):
2053
config.OldConfigHooks.install_named_hook('get', hook, None)
2055
config.OldConfigHooks.uninstall_named_hook, 'get', None)
2056
self.assertLength(0, calls)
2057
actual_value = conf.get_option(name)
2058
self.assertEquals(value, actual_value)
2059
self.assertLength(1, calls)
2060
self.assertEquals((conf, name, value), calls[0])
2062
def test_get_hook_remote_branch(self):
2063
remote_branch = branch.Branch.open(self.get_url('tree'))
2064
self.assertGetHook(remote_branch._get_config(), 'file', 'branch')
2066
def test_get_hook_remote_bzrdir(self):
2067
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2068
conf = remote_bzrdir._get_config()
2069
conf.set_option('remotedir', 'file')
2070
self.assertGetHook(conf, 'file', 'remotedir')
2072
def assertSetHook(self, conf, name, value):
2076
config.OldConfigHooks.install_named_hook('set', hook, None)
2078
config.OldConfigHooks.uninstall_named_hook, 'set', None)
2079
self.assertLength(0, calls)
2080
conf.set_option(value, name)
2081
self.assertLength(1, calls)
2082
# We can't assert the conf object below as different configs use
2083
# different means to implement set_user_option and we care only about
2085
self.assertEquals((name, value), calls[0][1:])
2087
def test_set_hook_remote_branch(self):
2088
remote_branch = branch.Branch.open(self.get_url('tree'))
2089
self.addCleanup(remote_branch.lock_write().unlock)
2090
self.assertSetHook(remote_branch._get_config(), 'file', 'remote')
2092
def test_set_hook_remote_bzrdir(self):
2093
remote_branch = branch.Branch.open(self.get_url('tree'))
2094
self.addCleanup(remote_branch.lock_write().unlock)
2095
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2096
self.assertSetHook(remote_bzrdir._get_config(), 'file', 'remotedir')
2098
def assertLoadHook(self, expected_nb_calls, name, conf_class, *conf_args):
2102
config.OldConfigHooks.install_named_hook('load', hook, None)
2104
config.OldConfigHooks.uninstall_named_hook, 'load', None)
2105
self.assertLength(0, calls)
2107
conf = conf_class(*conf_args)
2108
# Access an option to trigger a load
2109
conf.get_option(name)
2110
self.assertLength(expected_nb_calls, calls)
2111
# Since we can't assert about conf, we just use the number of calls ;-/
2113
def test_load_hook_remote_branch(self):
2114
remote_branch = branch.Branch.open(self.get_url('tree'))
2115
self.assertLoadHook(1, 'file', remote.RemoteBranchConfig, remote_branch)
2117
def test_load_hook_remote_bzrdir(self):
2118
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2119
# The config file doesn't exist, set an option to force its creation
2120
conf = remote_bzrdir._get_config()
2121
conf.set_option('remotedir', 'file')
2122
# We get one call for the server and one call for the client, this is
2123
# caused by the differences in implementations betwen
2124
# SmartServerBzrDirRequestConfigFile (in smart/bzrdir.py) and
2125
# SmartServerBranchGetConfigFile (in smart/branch.py)
2126
self.assertLoadHook(2 ,'file', remote.RemoteBzrDirConfig, remote_bzrdir)
2128
def assertSaveHook(self, conf):
2132
config.OldConfigHooks.install_named_hook('save', hook, None)
2134
config.OldConfigHooks.uninstall_named_hook, 'save', None)
2135
self.assertLength(0, calls)
2136
# Setting an option triggers a save
2137
conf.set_option('foo', 'bar')
2138
self.assertLength(1, calls)
2139
# Since we can't assert about conf, we just use the number of calls ;-/
2141
def test_save_hook_remote_branch(self):
2142
remote_branch = branch.Branch.open(self.get_url('tree'))
2143
self.addCleanup(remote_branch.lock_write().unlock)
2144
self.assertSaveHook(remote_branch._get_config())
2146
def test_save_hook_remote_bzrdir(self):
2147
remote_branch = branch.Branch.open(self.get_url('tree'))
2148
self.addCleanup(remote_branch.lock_write().unlock)
2149
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
2150
self.assertSaveHook(remote_bzrdir._get_config())
1909
2153
class TestOption(tests.TestCase):
1911
2155
def test_default_value(self):