203
203
nonactive = False
205
207
class TestConfigObj(tests.TestCase):
206
208
def test_get_bool(self):
207
from bzrlib.config import ConfigObj
208
co = ConfigObj(StringIO(bool_config))
209
co = config.ConfigObj(StringIO(bool_config))
209
210
self.assertIs(co.get_bool('DEFAULT', 'active'), True)
210
211
self.assertIs(co.get_bool('DEFAULT', 'inactive'), False)
211
212
self.assertIs(co.get_bool('UPPERCASE', 'active'), True)
217
218
[section] # line 3
218
219
whocares=notme # line 4
220
223
class TestConfigObjErrors(tests.TestCase):
222
225
def test_duplicate_section_name_error_line(self):
224
co = ConfigObj(StringIO(erroneous_config), raise_errors=True)
227
co = configobj.ConfigObj(StringIO(erroneous_config),
225
229
except config.configobj.DuplicateError, e:
226
230
self.assertEqual(3, e.line_number)
228
232
self.fail('Error in config file not detected')
230
235
class TestConfig(tests.TestCase):
232
237
def test_constructs(self):
235
240
def test_no_default_editor(self):
236
241
self.assertRaises(NotImplementedError, config.Config().get_editor)
291
296
if sys.platform == 'win32':
292
297
os.environ['BZR_HOME'] = \
293
298
r'C:\Documents and Settings\bogus\Application Data'
300
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0'
302
self.bzr_home = '/home/bogus/.bazaar'
295
304
def test_config_dir(self):
296
if sys.platform == 'win32':
297
self.assertEqual(config.config_dir(),
298
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0')
300
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
305
self.assertEqual(config.config_dir(), self.bzr_home)
302
307
def test_config_filename(self):
303
if sys.platform == 'win32':
304
self.assertEqual(config.config_filename(),
305
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/bazaar.conf')
307
self.assertEqual(config.config_filename(),
308
'/home/bogus/.bazaar/bazaar.conf')
308
self.assertEqual(config.config_filename(),
309
self.bzr_home + '/bazaar.conf')
310
311
def test_branches_config_filename(self):
311
if sys.platform == 'win32':
312
self.assertEqual(config.branches_config_filename(),
313
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/branches.conf')
315
self.assertEqual(config.branches_config_filename(),
316
'/home/bogus/.bazaar/branches.conf')
312
self.assertEqual(config.branches_config_filename(),
313
self.bzr_home + '/branches.conf')
318
315
def test_locations_config_filename(self):
319
if sys.platform == 'win32':
320
self.assertEqual(config.locations_config_filename(),
321
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf')
323
self.assertEqual(config.locations_config_filename(),
324
'/home/bogus/.bazaar/locations.conf')
316
self.assertEqual(config.locations_config_filename(),
317
self.bzr_home + '/locations.conf')
326
319
def test_authentication_config_filename(self):
327
if sys.platform == 'win32':
328
self.assertEqual(config.authentication_config_filename(),
329
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/authentication.conf')
331
self.assertEqual(config.authentication_config_filename(),
332
'/home/bogus/.bazaar/authentication.conf')
320
self.assertEqual(config.authentication_config_filename(),
321
self.bzr_home + '/authentication.conf')
334
324
class TestIniConfig(tests.TestCase):
356
346
my_config = config.GlobalConfig()
358
348
def test_calls_read_filenames(self):
359
# replace the class that is constructured, to check its parameters
349
# replace the class that is constructed, to check its parameters
360
350
oldparserclass = config.ConfigObj
361
351
config.ConfigObj = InstrumentedConfigObj
362
352
my_config = config.GlobalConfig()
433
423
local_path = osutils.getcwd().encode('utf8')
434
424
# Surprisingly ConfigObj doesn't create a trailing newline
435
425
self.check_file_contents(locations,
436
'[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
427
'push_location = http://foobar\n'
428
'push_location:policy = norecurse'
438
431
def test_autonick_urlencoded(self):
439
432
b = self.make_branch('!repo')
589
582
# This is testing the correct file names are provided.
590
583
# TODO: consolidate with the test for GlobalConfigs filename checks.
592
# replace the class that is constructured, to check its parameters
585
# replace the class that is constructed, to check its parameters
593
586
oldparserclass = config.ConfigObj
594
587
config.ConfigObj = InstrumentedConfigObj
623
616
def test__get_matching_sections_no_match(self):
624
617
self.get_branch_config('/')
625
618
self.assertEqual([], self.my_location_config._get_matching_sections())
627
620
def test__get_matching_sections_exact(self):
628
621
self.get_branch_config('http://www.example.com')
629
622
self.assertEqual([('http://www.example.com', '')],
630
623
self.my_location_config._get_matching_sections())
632
625
def test__get_matching_sections_suffix_does_not(self):
633
626
self.get_branch_config('http://www.example.com-com')
634
627
self.assertEqual([], self.my_location_config._get_matching_sections())
646
639
def test__get_matching_sections_ignoreparent_subdir(self):
647
640
self.get_branch_config(
648
641
'http://www.example.com/ignoreparent/childbranch')
649
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
642
self.assertEqual([('http://www.example.com/ignoreparent',
650
644
self.my_location_config._get_matching_sections())
652
646
def test__get_matching_sections_subdir_trailing_slash(self):
732
726
self.get_branch_config('/a/c')
733
727
self.assertEqual(config.CHECK_NEVER,
734
728
self.my_config.signature_checking())
736
730
def test_signatures_when_available(self):
737
731
self.get_branch_config('/a/', global_config=sample_ignore_signatures)
738
732
self.assertEqual(config.CHECK_IF_POSSIBLE,
739
733
self.my_config.signature_checking())
741
735
def test_signatures_always(self):
742
736
self.get_branch_config('/b')
743
737
self.assertEqual(config.CHECK_ALWAYS,
744
738
self.my_config.signature_checking())
746
740
def test_gpg_signing_command(self):
747
741
self.get_branch_config('/b')
748
742
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
902
896
self.assertIs(self.my_config.get_user_option('foo'), None)
903
897
self.my_config.set_user_option('foo', 'bar')
904
898
self.assertEqual(
905
self.my_config.branch.control_files.files['branch.conf'],
899
self.my_config.branch.control_files.files['branch.conf'],
907
901
self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
908
902
self.my_config.set_user_option('foo', 'baz',
910
904
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
911
905
self.my_config.set_user_option('foo', 'qux')
912
906
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
914
908
def test_get_bzr_remote_path(self):
915
909
my_config = config.LocationConfig('/a/c')
916
910
self.assertEqual('bzr', my_config.get_bzr_remote_path())
934
928
class TestBranchConfigItems(tests.TestCaseInTempDir):
936
def get_branch_config(self, global_config=None, location=None,
930
def get_branch_config(self, global_config=None, location=None,
937
931
location_config=None, branch_data_config=None):
938
932
my_config = config.BranchConfig(FakeBranch(location))
939
933
if global_config is not None:
954
948
self.assertEqual("Robert Collins <robertc@example.net>",
955
949
my_config.username())
956
950
branch.control_files.email = "John"
957
my_config.set_user_option('email',
951
my_config.set_user_option('email',
958
952
"Robert Collins <robertc@example.org>")
959
953
self.assertEqual("John", my_config.username())
960
954
branch.control_files.email = None
1025
1019
def test_config_precedence(self):
1026
1020
my_config = self.get_branch_config(global_config=precedence_global)
1027
1021
self.assertEqual(my_config.get_user_option('option'), 'global')
1028
my_config = self.get_branch_config(global_config=precedence_global,
1022
my_config = self.get_branch_config(global_config=precedence_global,
1029
1023
branch_data_config=precedence_branch)
1030
1024
self.assertEqual(my_config.get_user_option('option'), 'branch')
1031
my_config = self.get_branch_config(global_config=precedence_global,
1025
my_config = self.get_branch_config(global_config=precedence_global,
1032
1026
branch_data_config=precedence_branch,
1033
1027
location_config=precedence_location)
1034
1028
self.assertEqual(my_config.get_user_option('option'), 'recurse')
1035
my_config = self.get_branch_config(global_config=precedence_global,
1029
my_config = self.get_branch_config(global_config=precedence_global,
1036
1030
branch_data_config=precedence_branch,
1037
1031
location_config=precedence_location,
1038
1032
location='http://example.com/specific')