38
37
sample_long_alias="log -r-15..-1 --line"
39
sample_config_text = u"""
41
email=Erik B\u00e5gfors <erik@bagfors.nu>
43
gpg_signing_command=gnome-gpg
45
user_global_option=something
48
ll=""" + sample_long_alias + "\n"
51
sample_always_signatures = """
53
check_signatures=ignore
54
create_signatures=always
57
sample_ignore_signatures = """
59
check_signatures=require
60
create_signatures=never
63
sample_maybe_signatures = """
65
check_signatures=ignore
66
create_signatures=when-required
69
sample_branches_text = """
70
[http://www.example.com]
72
email=Robert Collins <robertc@example.org>
73
normal_option = normal
74
appendpath_option = append
75
appendpath_option:policy = appendpath
76
norecurse_option = norecurse
77
norecurse_option:policy = norecurse
78
[http://www.example.com/ignoreparent]
79
# different project: ignore parent dir config
81
[http://www.example.com/norecurse]
82
# configuration items that only apply to this dir
84
normal_option = norecurse
85
[http://www.example.com/dir]
86
appendpath_option = normal
88
check_signatures=require
89
# test trailing / matching with no children
91
check_signatures=check-available
92
gpg_signing_command=false
93
user_local_option=local
94
# test trailing / matching
96
#subdirs will match but not the parent
98
check_signatures=ignore
99
post_commit=bzrlib.tests.test_config.post_commit
100
#testing explicit beats globs
38
sample_config_text = ("[DEFAULT]\n"
39
u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n"
41
"gpg_signing_command=gnome-gpg\n"
43
"user_global_option=something\n"
46
"ll=" + sample_long_alias + "\n")
49
sample_always_signatures = ("[DEFAULT]\n"
50
"check_signatures=ignore\n"
51
"create_signatures=always")
54
sample_ignore_signatures = ("[DEFAULT]\n"
55
"check_signatures=require\n"
56
"create_signatures=never")
59
sample_maybe_signatures = ("[DEFAULT]\n"
60
"check_signatures=ignore\n"
61
"create_signatures=when-required")
64
sample_branches_text = ("[http://www.example.com]\n"
65
"# Top level policy\n"
66
"email=Robert Collins <robertc@example.org>\n"
67
"[http://www.example.com/ignoreparent]\n"
68
"# different project: ignore parent dir config\n"
69
"ignore_parents=true\n"
70
"[http://www.example.com/norecurse]\n"
71
"# configuration items that only apply to this dir\n"
74
"check_signatures=require\n"
75
"# test trailing / matching with no children\n"
77
"check_signatures=check-available\n"
78
"gpg_signing_command=false\n"
79
"user_local_option=local\n"
80
"# test trailing / matching\n"
82
"#subdirs will match but not the parent\n"
84
"check_signatures=ignore\n"
85
"post_commit=bzrlib.tests.test_config.post_commit\n"
86
"#testing explicit beats globs\n")
104
90
class InstrumentedConfigObj(object):
118
104
def __setitem__(self, key, value):
119
105
self._calls.append(('__setitem__', key, value))
121
def __delitem__(self, key):
122
self._calls.append(('__delitem__', key))
125
self._calls.append(('keys',))
128
107
def write(self, arg):
129
108
self._calls.append(('write',))
131
def as_bool(self, value):
132
self._calls.append(('as_bool', value))
135
def get_value(self, section, name):
136
self._calls.append(('get_value', section, name))
140
111
class FakeBranch(object):
272
243
super(TestConfigPath, self).setUp()
244
self.old_home = os.environ.get('HOME', None)
245
self.old_appdata = os.environ.get('APPDATA', None)
273
246
os.environ['HOME'] = '/home/bogus'
274
if sys.platform == 'win32':
275
os.environ['BZR_HOME'] = \
276
r'C:\Documents and Settings\bogus\Application Data'
247
os.environ['APPDATA'] = \
248
r'C:\Documents and Settings\bogus\Application Data'
251
if self.old_home is None:
252
del os.environ['HOME']
254
os.environ['HOME'] = self.old_home
255
if self.old_appdata is None:
256
del os.environ['APPDATA']
258
os.environ['APPDATA'] = self.old_appdata
259
super(TestConfigPath, self).tearDown()
278
261
def test_config_dir(self):
279
262
if sys.platform == 'win32':
280
263
self.assertEqual(config.config_dir(),
403
386
def test_config_creates_local(self):
404
387
"""Creating a new entry in config uses a local path."""
405
branch = self.make_branch('branch', format='knit')
388
branch = self.make_branch('branch')
406
389
branch.set_push_location('http://foobar')
407
390
locations = config.locations_config_filename()
408
391
local_path = osutils.getcwd().encode('utf8')
409
392
# Surprisingly ConfigObj doesn't create a trailing newline
410
393
self.check_file_contents(locations,
411
'[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
413
def test_autonick_urlencoded(self):
414
b = self.make_branch('!repo')
415
self.assertEqual('!repo', b.get_config().get_nickname())
417
def test_warn_if_masked(self):
418
_warning = trace.warning
421
warnings.append(args[0] % args[1:])
423
def set_option(store, warn_masked=True):
425
conf.set_user_option('example_option', repr(store), store=store,
426
warn_masked=warn_masked)
427
def assertWarning(warning):
429
self.assertEqual(0, len(warnings))
431
self.assertEqual(1, len(warnings))
432
self.assertEqual(warning, warnings[0])
433
trace.warning = warning
435
branch = self.make_branch('.')
436
conf = branch.get_config()
437
set_option(config.STORE_GLOBAL)
439
set_option(config.STORE_BRANCH)
441
set_option(config.STORE_GLOBAL)
442
assertWarning('Value "4" is masked by "3" from branch.conf')
443
set_option(config.STORE_GLOBAL, warn_masked=False)
445
set_option(config.STORE_LOCATION)
447
set_option(config.STORE_BRANCH)
448
assertWarning('Value "3" is masked by "0" from locations.conf')
449
set_option(config.STORE_BRANCH, warn_masked=False)
452
trace.warning = _warning
394
'[%s/branch]\npush_location = http://foobar' % (local_path,))
455
397
class TestGlobalConfigItems(TestCase):
624
566
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
625
567
self.my_location_config._get_matching_sections())
569
def test__get_matching_sections_norecurse(self):
570
self.get_branch_config('http://www.example.com/norecurse')
571
self.assertEqual([('http://www.example.com/norecurse', ''),
572
('http://www.example.com', 'norecurse')],
573
self.my_location_config._get_matching_sections())
575
def test__get_matching_sections_norecurse_subdir(self):
576
self.get_branch_config(
577
'http://www.example.com/norecurse/childbranch')
578
self.assertEqual([('http://www.example.com', 'norecurse/childbranch')],
579
self.my_location_config._get_matching_sections())
627
581
def test__get_matching_sections_subdir_trailing_slash(self):
628
582
self.get_branch_config('/b')
629
583
self.assertEqual([('/b/', '')],
653
607
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
654
608
self.my_location_config._get_matching_sections())
656
def test__get_option_policy_normal(self):
657
self.get_branch_config('http://www.example.com')
659
self.my_location_config._get_config_policy(
660
'http://www.example.com', 'normal_option'),
663
def test__get_option_policy_norecurse(self):
664
self.get_branch_config('http://www.example.com')
666
self.my_location_config._get_option_policy(
667
'http://www.example.com', 'norecurse_option'),
668
config.POLICY_NORECURSE)
669
# Test old recurse=False setting:
671
self.my_location_config._get_option_policy(
672
'http://www.example.com/norecurse', 'normal_option'),
673
config.POLICY_NORECURSE)
675
def test__get_option_policy_normal(self):
676
self.get_branch_config('http://www.example.com')
678
self.my_location_config._get_option_policy(
679
'http://www.example.com', 'appendpath_option'),
680
config.POLICY_APPENDPATH)
682
610
def test_location_without_username(self):
683
611
self.get_branch_config('http://www.example.com/ignoreparent')
684
612
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
736
664
self.assertEqual('local',
737
665
self.my_config.get_user_option('user_local_option'))
739
def test_get_user_option_appendpath(self):
740
# returned as is for the base path:
741
self.get_branch_config('http://www.example.com')
742
self.assertEqual('append',
743
self.my_config.get_user_option('appendpath_option'))
744
# Extra path components get appended:
745
self.get_branch_config('http://www.example.com/a/b/c')
746
self.assertEqual('append/a/b/c',
747
self.my_config.get_user_option('appendpath_option'))
748
# Overriden for http://www.example.com/dir, where it is a
750
self.get_branch_config('http://www.example.com/dir/a/b/c')
751
self.assertEqual('normal',
752
self.my_config.get_user_option('appendpath_option'))
754
def test_get_user_option_norecurse(self):
755
self.get_branch_config('http://www.example.com')
756
self.assertEqual('norecurse',
757
self.my_config.get_user_option('norecurse_option'))
758
self.get_branch_config('http://www.example.com/dir')
759
self.assertEqual(None,
760
self.my_config.get_user_option('norecurse_option'))
761
# http://www.example.com/norecurse is a recurse=False section
762
# that redefines normal_option. Subdirectories do not pick up
764
self.get_branch_config('http://www.example.com/norecurse')
765
self.assertEqual('norecurse',
766
self.my_config.get_user_option('normal_option'))
767
self.get_branch_config('http://www.example.com/norecurse/subdir')
768
self.assertEqual('normal',
769
self.my_config.get_user_option('normal_option'))
771
def test_set_user_option_norecurse(self):
772
self.get_branch_config('http://www.example.com')
773
self.my_config.set_user_option('foo', 'bar',
774
store=config.STORE_LOCATION_NORECURSE)
776
self.my_location_config._get_option_policy(
777
'http://www.example.com', 'foo'),
778
config.POLICY_NORECURSE)
780
def test_set_user_option_appendpath(self):
781
self.get_branch_config('http://www.example.com')
782
self.my_config.set_user_option('foo', 'bar',
783
store=config.STORE_LOCATION_APPENDPATH)
785
self.my_location_config._get_option_policy(
786
'http://www.example.com', 'foo'),
787
config.POLICY_APPENDPATH)
789
def test_set_user_option_change_policy(self):
790
self.get_branch_config('http://www.example.com')
791
self.my_config.set_user_option('norecurse_option', 'normal',
792
store=config.STORE_LOCATION)
794
self.my_location_config._get_option_policy(
795
'http://www.example.com', 'norecurse_option'),
798
def test_set_user_option_recurse_false_section(self):
799
# The following section has recurse=False set. The test is to
800
# make sure that a normal option can be added to the section,
801
# converting recurse=False to the norecurse policy.
802
self.get_branch_config('http://www.example.com/norecurse')
803
self.callDeprecated(['The recurse option is deprecated as of 0.14. '
804
'The section "http://www.example.com/norecurse" '
805
'has been converted to use policies.'],
806
self.my_config.set_user_option,
807
'foo', 'bar', store=config.STORE_LOCATION)
809
self.my_location_config._get_option_policy(
810
'http://www.example.com/norecurse', 'foo'),
812
# The previously existing option is still norecurse:
814
self.my_location_config._get_option_policy(
815
'http://www.example.com/norecurse', 'normal_option'),
816
config.POLICY_NORECURSE)
818
667
def test_post_commit_default(self):
819
668
self.get_branch_config('/a/c')
820
669
self.assertEqual('bzrlib.tests.test_config.post_commit',
1013
848
config.extract_email_address('Jane <jane@test.com>'))
1014
849
self.assertRaises(errors.NoEmailInUsername,
1015
850
config.extract_email_address, 'Jane Tester')
1018
class TestTreeConfig(TestCaseWithTransport):
1020
def test_get_value(self):
1021
"""Test that retreiving a value from a section is possible"""
1022
branch = self.make_branch('.')
1023
tree_config = config.TreeConfig(branch)
1024
tree_config.set_option('value', 'key', 'SECTION')
1025
tree_config.set_option('value2', 'key2')
1026
tree_config.set_option('value3-top', 'key3')
1027
tree_config.set_option('value3-section', 'key3', 'SECTION')
1028
value = tree_config.get_option('key', 'SECTION')
1029
self.assertEqual(value, 'value')
1030
value = tree_config.get_option('key2')
1031
self.assertEqual(value, 'value2')
1032
self.assertEqual(tree_config.get_option('non-existant'), None)
1033
value = tree_config.get_option('non-existant', 'SECTION')
1034
self.assertEqual(value, None)
1035
value = tree_config.get_option('non-existant', default='default')
1036
self.assertEqual(value, 'default')
1037
self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
1038
value = tree_config.get_option('key2', 'NOSECTION', default='default')
1039
self.assertEqual(value, 'default')
1040
value = tree_config.get_option('key3')
1041
self.assertEqual(value, 'value3-top')
1042
value = tree_config.get_option('key3', 'SECTION')
1043
self.assertEqual(value, 'value3-section')