18
18
"""Tests for finding and reading the bzr config file[s]."""
19
19
# import system imports here
20
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError
20
from ConfigParser import ConfigParser
21
21
from cStringIO import StringIO
25
25
#import bzrlib specific imports here
32
from bzrlib.branch import Branch
33
from bzrlib.bzrdir import BzrDir
34
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
37
sample_long_alias="log -r-15..-1 --line"
38
sample_config_text = u"""
40
email=Erik B\u00e5gfors <erik@bagfors.nu>
42
gpg_signing_command=gnome-gpg
44
user_global_option=something
47
ll=""" + sample_long_alias + "\n"
50
sample_always_signatures = """
52
check_signatures=ignore
53
create_signatures=always
56
sample_ignore_signatures = """
58
check_signatures=require
59
create_signatures=never
62
sample_maybe_signatures = """
64
check_signatures=ignore
65
create_signatures=when-required
68
sample_branches_text = """
69
[http://www.example.com]
71
email=Robert Collins <robertc@example.org>
72
normal_option = normal
73
appendpath_option = append
74
appendpath_option:policy = appendpath
75
norecurse_option = norecurse
76
norecurse_option:policy = norecurse
77
[http://www.example.com/ignoreparent]
78
# different project: ignore parent dir config
80
[http://www.example.com/norecurse]
81
# configuration items that only apply to this dir
83
normal_option = norecurse
84
[http://www.example.com/dir]
85
appendpath_option = normal
87
check_signatures=require
88
# test trailing / matching with no children
90
check_signatures=check-available
91
gpg_signing_command=false
92
user_local_option=local
93
# test trailing / matching
95
#subdirs will match but not the parent
97
check_signatures=ignore
98
post_commit=bzrlib.tests.test_config.post_commit
99
#testing explicit beats globs
103
class InstrumentedConfigObj(object):
104
"""A config obj look-enough-alike to record calls made to it."""
106
def __contains__(self, thing):
107
self._calls.append(('__contains__', thing))
110
def __getitem__(self, key):
111
self._calls.append(('__getitem__', key))
114
def __init__(self, input, encoding=None):
115
self._calls = [('__init__', input, encoding)]
117
def __setitem__(self, key, value):
118
self._calls.append(('__setitem__', key, value))
120
def __delitem__(self, key):
121
self._calls.append(('__delitem__', key))
124
self._calls.append(('keys',))
127
def write(self, arg):
128
self._calls.append(('write',))
130
def as_bool(self, value):
131
self._calls.append(('as_bool', value))
134
def get_value(self, section, name):
135
self._calls.append(('get_value', section, name))
26
import bzrlib.config as config
27
import bzrlib.errors as errors
28
from bzrlib.selftest import TestCase, TestCaseInTempDir
31
sample_config_text = ("[DEFAULT]\n"
32
"email=Robert Collins <robertc@example.com>\n"
34
"gpg_signing_command=gnome-gpg\n"
35
"user_global_option=something\n")
38
sample_always_signatures = ("[DEFAULT]\n"
39
"check_signatures=require\n")
42
sample_ignore_signatures = ("[DEFAULT]\n"
43
"check_signatures=ignore\n")
46
sample_maybe_signatures = ("[DEFAULT]\n"
47
"check_signatures=check-available\n")
50
sample_branches_text = ("[http://www.example.com]\n"
51
"# Top level policy\n"
52
"email=Robert Collins <robertc@example.org>\n"
53
"[http://www.example.com/useglobal]\n"
54
"# different project, forces global lookup\n"
57
"check_signatures=require\n"
58
"# test trailing / matching with no children\n"
60
"check_signatures=check-available\n"
61
"gpg_signing_command=false\n"
62
"user_local_option=local\n"
63
"# test trailing / matching\n"
65
"#subdirs will match but not the parent\n"
68
"check_signatures=ignore\n"
69
"#testing explicit beats globs\n")
72
class InstrumentedConfigParser(object):
73
"""A config parser look-enough-alike to record calls made to it."""
78
def read(self, filenames):
79
self._calls.append(('read', filenames))
139
82
class FakeBranch(object):
141
def __init__(self, base=None, user_id=None):
143
self.base = "http://example.com/branches/demo"
146
self.control_files = FakeControlFiles(user_id=user_id)
148
def lock_write(self):
155
class FakeControlFiles(object):
157
def __init__(self, user_id=None):
161
def get_utf8(self, filename):
85
self.base = "http://example.com/branches/demo"
86
self.email = 'Robert Collins <robertc@example.net>\n'
88
def controlfile(self, filename, mode):
162
89
if filename != 'email':
163
90
raise NotImplementedError
164
91
if self.email is not None:
165
92
return StringIO(self.email)
166
raise errors.NoSuchFile(filename)
168
def get(self, filename):
170
return StringIO(self.files[filename])
172
raise errors.NoSuchFile(filename)
174
def put(self, filename, fileobj):
175
self.files[filename] = fileobj.read()
93
raise errors.NoSuchFile
178
96
class InstrumentedConfig(config.Config):
506
303
my_config = self._get_sample_config()
507
304
self.assertEqual("something",
508
305
my_config.get_user_option('user_global_option'))
510
def test_post_commit_default(self):
511
my_config = self._get_sample_config()
512
self.assertEqual(None, my_config.post_commit())
514
def test_configured_logformat(self):
515
my_config = self._get_sample_config()
516
self.assertEqual("short", my_config.log_format())
518
def test_get_alias(self):
519
my_config = self._get_sample_config()
520
self.assertEqual('help', my_config.get_alias('h'))
522
def test_get_no_alias(self):
523
my_config = self._get_sample_config()
524
self.assertEqual(None, my_config.get_alias('foo'))
526
def test_get_long_alias(self):
527
my_config = self._get_sample_config()
528
self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
531
class TestLocationConfig(TestCaseInTempDir):
308
class TestLocationConfig(TestCase):
533
310
def test_constructs(self):
534
311
my_config = config.LocationConfig('http://example.com')
535
312
self.assertRaises(TypeError, config.LocationConfig)
537
314
def test_branch_calls_read_filenames(self):
538
# This is testing the correct file names are provided.
539
# TODO: consolidate with the test for GlobalConfigs filename checks.
541
315
# replace the class that is constructured, to check its parameters
542
oldparserclass = config.ConfigObj
543
config.ConfigObj = InstrumentedConfigObj
545
my_config = config.LocationConfig('http://www.example.com')
546
parser = my_config._get_parser()
548
config.ConfigObj = oldparserclass
549
self.failUnless(isinstance(parser, InstrumentedConfigObj))
550
self.assertEqual(parser._calls,
551
[('__init__', config.locations_config_filename(),
553
config.ensure_config_dir_exists()
554
#os.mkdir(config.config_dir())
555
f = file(config.branches_config_filename(), 'wb')
558
oldparserclass = config.ConfigObj
559
config.ConfigObj = InstrumentedConfigObj
561
my_config = config.LocationConfig('http://www.example.com')
562
parser = my_config._get_parser()
564
config.ConfigObj = oldparserclass
316
oldparserclass = config.ConfigParser
317
config.ConfigParser = InstrumentedConfigParser
318
my_config = config.LocationConfig('http://www.example.com')
320
parser = my_config._get_parser()
322
config.ConfigParser = oldparserclass
323
self.failUnless(isinstance(parser, InstrumentedConfigParser))
324
self.assertEqual(parser._calls, [('read', [config.branches_config_filename()])])
566
326
def test_get_global_config(self):
567
my_config = config.BranchConfig(FakeBranch('http://example.com'))
327
my_config = config.LocationConfig('http://example.com')
568
328
global_config = my_config._get_global_config()
569
329
self.failUnless(isinstance(global_config, config.GlobalConfig))
570
330
self.failUnless(global_config is my_config._get_global_config())
572
def test__get_matching_sections_no_match(self):
573
self.get_branch_config('/')
574
self.assertEqual([], self.my_location_config._get_matching_sections())
332
def test__get_section_no_match(self):
333
self.get_location_config('/')
334
self.assertEqual(None, self.my_config._get_section())
576
def test__get_matching_sections_exact(self):
577
self.get_branch_config('http://www.example.com')
578
self.assertEqual([('http://www.example.com', '')],
579
self.my_location_config._get_matching_sections())
336
def test__get_section_exact(self):
337
self.get_location_config('http://www.example.com')
338
self.assertEqual('http://www.example.com',
339
self.my_config._get_section())
581
def test__get_matching_sections_suffix_does_not(self):
582
self.get_branch_config('http://www.example.com-com')
583
self.assertEqual([], self.my_location_config._get_matching_sections())
585
def test__get_matching_sections_subdir_recursive(self):
586
self.get_branch_config('http://www.example.com/com')
587
self.assertEqual([('http://www.example.com', 'com')],
588
self.my_location_config._get_matching_sections())
590
def test__get_matching_sections_ignoreparent(self):
591
self.get_branch_config('http://www.example.com/ignoreparent')
592
self.assertEqual([('http://www.example.com/ignoreparent', '')],
593
self.my_location_config._get_matching_sections())
595
def test__get_matching_sections_ignoreparent_subdir(self):
596
self.get_branch_config(
597
'http://www.example.com/ignoreparent/childbranch')
598
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
599
self.my_location_config._get_matching_sections())
601
def test__get_matching_sections_subdir_trailing_slash(self):
602
self.get_branch_config('/b')
603
self.assertEqual([('/b/', '')],
604
self.my_location_config._get_matching_sections())
606
def test__get_matching_sections_subdir_child(self):
607
self.get_branch_config('/a/foo')
608
self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
609
self.my_location_config._get_matching_sections())
611
def test__get_matching_sections_subdir_child_child(self):
612
self.get_branch_config('/a/foo/bar')
613
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
614
self.my_location_config._get_matching_sections())
616
def test__get_matching_sections_trailing_slash_with_children(self):
617
self.get_branch_config('/a/')
618
self.assertEqual([('/a/', '')],
619
self.my_location_config._get_matching_sections())
621
def test__get_matching_sections_explicit_over_glob(self):
622
# XXX: 2006-09-08 jamesh
623
# This test only passes because ord('c') > ord('*'). If there
624
# was a config section for '/a/?', it would get precedence
626
self.get_branch_config('/a/c')
627
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
628
self.my_location_config._get_matching_sections())
630
def test__get_option_policy_normal(self):
631
self.get_branch_config('http://www.example.com')
633
self.my_location_config._get_config_policy(
634
'http://www.example.com', 'normal_option'),
637
def test__get_option_policy_norecurse(self):
638
self.get_branch_config('http://www.example.com')
640
self.my_location_config._get_option_policy(
641
'http://www.example.com', 'norecurse_option'),
642
config.POLICY_NORECURSE)
643
# Test old recurse=False setting:
645
self.my_location_config._get_option_policy(
646
'http://www.example.com/norecurse', 'normal_option'),
647
config.POLICY_NORECURSE)
649
def test__get_option_policy_normal(self):
650
self.get_branch_config('http://www.example.com')
652
self.my_location_config._get_option_policy(
653
'http://www.example.com', 'appendpath_option'),
654
config.POLICY_APPENDPATH)
341
def test__get_section_suffix_does_not(self):
342
self.get_location_config('http://www.example.com-com')
343
self.assertEqual(None, self.my_config._get_section())
345
def test__get_section_subdir_recursive(self):
346
self.get_location_config('http://www.example.com/com')
347
self.assertEqual('http://www.example.com',
348
self.my_config._get_section())
350
def test__get_section_subdir_matches(self):
351
self.get_location_config('http://www.example.com/useglobal')
352
self.assertEqual('http://www.example.com/useglobal',
353
self.my_config._get_section())
355
def test__get_section_subdir_nonrecursive(self):
356
self.get_location_config(
357
'http://www.example.com/useglobal/childbranch')
358
self.assertEqual('http://www.example.com',
359
self.my_config._get_section())
361
def test__get_section_subdir_trailing_slash(self):
362
self.get_location_config('/b')
363
self.assertEqual('/b/', self.my_config._get_section())
365
def test__get_section_subdir_child(self):
366
self.get_location_config('/a/foo')
367
self.assertEqual('/a/*', self.my_config._get_section())
369
def test__get_section_subdir_child_child(self):
370
self.get_location_config('/a/foo/bar')
371
self.assertEqual('/a/', self.my_config._get_section())
373
def test__get_section_trailing_slash_with_children(self):
374
self.get_location_config('/a/')
375
self.assertEqual('/a/', self.my_config._get_section())
377
def test__get_section_explicit_over_glob(self):
378
self.get_location_config('/a/c')
379
self.assertEqual('/a/c', self.my_config._get_section())
381
def get_location_config(self, location, global_config=None):
382
if global_config is None:
383
global_file = StringIO(sample_config_text)
385
global_file = StringIO(global_config)
386
branches_file = StringIO(sample_branches_text)
387
self.my_config = config.LocationConfig(location)
388
self.my_config._get_parser(branches_file)
389
self.my_config._get_global_config()._get_parser(global_file)
656
391
def test_location_without_username(self):
657
self.get_branch_config('http://www.example.com/ignoreparent')
658
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
392
self.get_location_config('http://www.example.com/useglobal')
393
self.assertEqual('Robert Collins <robertc@example.com>',
659
394
self.my_config.username())
661
396
def test_location_not_listed(self):
662
"""Test that the global username is used when no location matches"""
663
self.get_branch_config('/home/robertc/sources')
664
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
397
self.get_location_config('/home/robertc/sources')
398
self.assertEqual('Robert Collins <robertc@example.com>',
665
399
self.my_config.username())
667
401
def test_overriding_location(self):
668
self.get_branch_config('http://www.example.com/foo')
402
self.get_location_config('http://www.example.com/foo')
669
403
self.assertEqual('Robert Collins <robertc@example.org>',
670
404
self.my_config.username())
672
406
def test_signatures_not_set(self):
673
self.get_branch_config('http://www.example.com',
407
self.get_location_config('http://www.example.com',
674
408
global_config=sample_ignore_signatures)
675
self.assertEqual(config.CHECK_ALWAYS,
409
self.assertEqual(config.CHECK_NEVER,
676
410
self.my_config.signature_checking())
677
self.assertEqual(config.SIGN_NEVER,
678
self.my_config.signing_policy())
680
412
def test_signatures_never(self):
681
self.get_branch_config('/a/c')
413
self.get_location_config('/a/c')
682
414
self.assertEqual(config.CHECK_NEVER,
683
415
self.my_config.signature_checking())
685
417
def test_signatures_when_available(self):
686
self.get_branch_config('/a/', global_config=sample_ignore_signatures)
418
self.get_location_config('/a/', global_config=sample_ignore_signatures)
687
419
self.assertEqual(config.CHECK_IF_POSSIBLE,
688
420
self.my_config.signature_checking())
690
422
def test_signatures_always(self):
691
self.get_branch_config('/b')
423
self.get_location_config('/b')
692
424
self.assertEqual(config.CHECK_ALWAYS,
693
425
self.my_config.signature_checking())
695
427
def test_gpg_signing_command(self):
696
self.get_branch_config('/b')
428
self.get_location_config('/b')
697
429
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
699
431
def test_gpg_signing_command_missing(self):
700
self.get_branch_config('/a')
432
self.get_location_config('/a')
701
433
self.assertEqual("false", self.my_config.gpg_signing_command())
703
435
def test_get_user_option_global(self):
704
self.get_branch_config('/a')
436
self.get_location_config('/a')
705
437
self.assertEqual('something',
706
438
self.my_config.get_user_option('user_global_option'))
708
440
def test_get_user_option_local(self):
709
self.get_branch_config('/a')
441
self.get_location_config('/a')
710
442
self.assertEqual('local',
711
443
self.my_config.get_user_option('user_local_option'))
713
def test_get_user_option_appendpath(self):
714
# returned as is for the base path:
715
self.get_branch_config('http://www.example.com')
716
self.assertEqual('append',
717
self.my_config.get_user_option('appendpath_option'))
718
# Extra path components get appended:
719
self.get_branch_config('http://www.example.com/a/b/c')
720
self.assertEqual('append/a/b/c',
721
self.my_config.get_user_option('appendpath_option'))
722
# Overriden for http://www.example.com/dir, where it is a
724
self.get_branch_config('http://www.example.com/dir/a/b/c')
725
self.assertEqual('normal',
726
self.my_config.get_user_option('appendpath_option'))
728
def test_get_user_option_norecurse(self):
729
self.get_branch_config('http://www.example.com')
730
self.assertEqual('norecurse',
731
self.my_config.get_user_option('norecurse_option'))
732
self.get_branch_config('http://www.example.com/dir')
733
self.assertEqual(None,
734
self.my_config.get_user_option('norecurse_option'))
735
# http://www.example.com/norecurse is a recurse=False section
736
# that redefines normal_option. Subdirectories do not pick up
738
self.get_branch_config('http://www.example.com/norecurse')
739
self.assertEqual('norecurse',
740
self.my_config.get_user_option('normal_option'))
741
self.get_branch_config('http://www.example.com/norecurse/subdir')
742
self.assertEqual('normal',
743
self.my_config.get_user_option('normal_option'))
745
def test_set_user_option_norecurse(self):
746
self.get_branch_config('http://www.example.com')
747
self.my_config.set_user_option('foo', 'bar',
748
store=config.STORE_LOCATION_NORECURSE)
750
self.my_location_config._get_option_policy(
751
'http://www.example.com', 'foo'),
752
config.POLICY_NORECURSE)
754
def test_set_user_option_appendpath(self):
755
self.get_branch_config('http://www.example.com')
756
self.my_config.set_user_option('foo', 'bar',
757
store=config.STORE_LOCATION_APPENDPATH)
759
self.my_location_config._get_option_policy(
760
'http://www.example.com', 'foo'),
761
config.POLICY_APPENDPATH)
763
def test_set_user_option_change_policy(self):
764
self.get_branch_config('http://www.example.com')
765
self.my_config.set_user_option('norecurse_option', 'normal',
766
store=config.STORE_LOCATION)
768
self.my_location_config._get_option_policy(
769
'http://www.example.com', 'norecurse_option'),
772
def test_set_user_option_recurse_false_section(self):
773
# The following section has recurse=False set. The test is to
774
# make sure that a normal option can be added to the section,
775
# converting recurse=False to the norecurse policy.
776
self.get_branch_config('http://www.example.com/norecurse')
777
self.callDeprecated(['The recurse option is deprecated as of 0.14. '
778
'The section "http://www.example.com/norecurse" '
779
'has been converted to use policies.'],
780
self.my_config.set_user_option,
781
'foo', 'bar', store=config.STORE_LOCATION)
783
self.my_location_config._get_option_policy(
784
'http://www.example.com/norecurse', 'foo'),
786
# The previously existing option is still norecurse:
788
self.my_location_config._get_option_policy(
789
'http://www.example.com/norecurse', 'normal_option'),
790
config.POLICY_NORECURSE)
793
def test_post_commit_default(self):
794
self.get_branch_config('/a/c')
795
self.assertEqual('bzrlib.tests.test_config.post_commit',
796
self.my_config.post_commit())
798
def get_branch_config(self, location, global_config=None):
799
if global_config is None:
800
global_file = StringIO(sample_config_text.encode('utf-8'))
802
global_file = StringIO(global_config.encode('utf-8'))
803
branches_file = StringIO(sample_branches_text.encode('utf-8'))
804
self.my_config = config.BranchConfig(FakeBranch(location))
805
# Force location config to use specified file
806
self.my_location_config = self.my_config._get_location_config()
807
self.my_location_config._get_parser(branches_file)
808
# Force global config to use specified file
809
self.my_config._get_global_config()._get_parser(global_file)
811
def test_set_user_setting_sets_and_saves(self):
812
self.get_branch_config('/a/c')
813
record = InstrumentedConfigObj("foo")
814
self.my_location_config._parser = record
816
real_mkdir = os.mkdir
818
def checked_mkdir(path, mode=0777):
819
self.log('making directory: %s', path)
820
real_mkdir(path, mode)
823
os.mkdir = checked_mkdir
825
self.callDeprecated(['The recurse option is deprecated as of '
826
'0.14. The section "/a/c" has been '
827
'converted to use policies.'],
828
self.my_config.set_user_option,
829
'foo', 'bar', store=config.STORE_LOCATION)
831
os.mkdir = real_mkdir
833
self.failUnless(self.created, 'Failed to create ~/.bazaar')
834
self.assertEqual([('__contains__', '/a/c'),
835
('__contains__', '/a/c/'),
836
('__setitem__', '/a/c', {}),
837
('__getitem__', '/a/c'),
838
('__setitem__', 'foo', 'bar'),
839
('__getitem__', '/a/c'),
840
('as_bool', 'recurse'),
841
('__getitem__', '/a/c'),
842
('__delitem__', 'recurse'),
843
('__getitem__', '/a/c'),
845
('__getitem__', '/a/c'),
846
('__contains__', 'foo:policy'),
850
def test_set_user_setting_sets_and_saves2(self):
851
self.get_branch_config('/a/c')
852
self.assertIs(self.my_config.get_user_option('foo'), None)
853
self.my_config.set_user_option('foo', 'bar')
855
self.my_config.branch.control_files.files['branch.conf'],
857
self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
858
self.my_config.set_user_option('foo', 'baz',
859
store=config.STORE_LOCATION)
860
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
861
self.my_config.set_user_option('foo', 'qux')
862
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
865
precedence_global = 'option = global'
866
precedence_branch = 'option = branch'
867
precedence_location = """
871
[http://example.com/specific]
876
class TestBranchConfigItems(TestCaseInTempDir):
878
def get_branch_config(self, global_config=None, location=None,
879
location_config=None, branch_data_config=None):
880
my_config = config.BranchConfig(FakeBranch(location))
881
if global_config is not None:
882
global_file = StringIO(global_config.encode('utf-8'))
883
my_config._get_global_config()._get_parser(global_file)
884
self.my_location_config = my_config._get_location_config()
885
if location_config is not None:
886
location_file = StringIO(location_config.encode('utf-8'))
887
self.my_location_config._get_parser(location_file)
888
if branch_data_config is not None:
889
my_config.branch.control_files.files['branch.conf'] = \
446
class TestBranchConfigItems(TestCase):
893
448
def test_user_id(self):
894
branch = FakeBranch(user_id='Robert Collins <robertc@example.net>')
449
branch = FakeBranch()
895
450
my_config = config.BranchConfig(branch)
896
451
self.assertEqual("Robert Collins <robertc@example.net>",
897
my_config.username())
898
branch.control_files.email = "John"
899
my_config.set_user_option('email',
900
"Robert Collins <robertc@example.org>")
901
self.assertEqual("John", my_config.username())
902
branch.control_files.email = None
903
self.assertEqual("Robert Collins <robertc@example.org>",
904
my_config.username())
452
my_config._get_user_id())
453
branch.email = "John"
454
self.assertEqual("John", my_config._get_user_id())
906
456
def test_not_set_in_branch(self):
907
my_config = self.get_branch_config(sample_config_text)
908
my_config.branch.control_files.email = None
909
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
457
branch = FakeBranch()
458
my_config = config.BranchConfig(branch)
460
config_file = StringIO(sample_config_text)
461
(my_config._get_location_config().
462
_get_global_config()._get_parser(config_file))
463
self.assertEqual("Robert Collins <robertc@example.com>",
910
464
my_config._get_user_id())
911
my_config.branch.control_files.email = "John"
465
branch.email = "John"
912
466
self.assertEqual("John", my_config._get_user_id())
914
def test_BZR_EMAIL_OVERRIDES(self):
915
os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
468
def test_BZREMAIL_OVERRIDES(self):
469
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>"
916
470
branch = FakeBranch()
917
471
my_config = config.BranchConfig(branch)
918
472
self.assertEqual("Robert Collins <robertc@example.org>",
919
473
my_config.username())
921
475
def test_signatures_forced(self):
922
my_config = self.get_branch_config(
923
global_config=sample_always_signatures)
924
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
925
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
926
self.assertTrue(my_config.signature_needed())
928
def test_signatures_forced_branch(self):
929
my_config = self.get_branch_config(
930
global_config=sample_ignore_signatures,
931
branch_data_config=sample_always_signatures)
932
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
933
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
934
self.assertTrue(my_config.signature_needed())
476
branch = FakeBranch()
477
my_config = config.BranchConfig(branch)
478
config_file = StringIO(sample_always_signatures)
479
(my_config._get_location_config().
480
_get_global_config()._get_parser(config_file))
481
self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking())
936
483
def test_gpg_signing_command(self):
937
my_config = self.get_branch_config(
938
# branch data cannot set gpg_signing_command
939
branch_data_config="gpg_signing_command=pgp")
940
config_file = StringIO(sample_config_text.encode('utf-8'))
941
my_config._get_global_config()._get_parser(config_file)
484
branch = FakeBranch()
485
my_config = config.BranchConfig(branch)
486
config_file = StringIO(sample_config_text)
487
(my_config._get_location_config().
488
_get_global_config()._get_parser(config_file))
942
489
self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
944
491
def test_get_user_option_global(self):
945
492
branch = FakeBranch()
946
493
my_config = config.BranchConfig(branch)
947
config_file = StringIO(sample_config_text.encode('utf-8'))
948
(my_config._get_global_config()._get_parser(config_file))
494
config_file = StringIO(sample_config_text)
495
(my_config._get_location_config().
496
_get_global_config()._get_parser(config_file))
949
497
self.assertEqual('something',
950
498
my_config.get_user_option('user_global_option'))
952
def test_post_commit_default(self):
953
branch = FakeBranch()
954
my_config = self.get_branch_config(sample_config_text, '/a/c',
955
sample_branches_text)
956
self.assertEqual(my_config.branch.base, '/a/c')
957
self.assertEqual('bzrlib.tests.test_config.post_commit',
958
my_config.post_commit())
959
my_config.set_user_option('post_commit', 'rmtree_root')
960
# post-commit is ignored when bresent in branch data
961
self.assertEqual('bzrlib.tests.test_config.post_commit',
962
my_config.post_commit())
963
my_config.set_user_option('post_commit', 'rmtree_root',
964
store=config.STORE_LOCATION)
965
self.assertEqual('rmtree_root', my_config.post_commit())
967
def test_config_precedence(self):
968
my_config = self.get_branch_config(global_config=precedence_global)
969
self.assertEqual(my_config.get_user_option('option'), 'global')
970
my_config = self.get_branch_config(global_config=precedence_global,
971
branch_data_config=precedence_branch)
972
self.assertEqual(my_config.get_user_option('option'), 'branch')
973
my_config = self.get_branch_config(global_config=precedence_global,
974
branch_data_config=precedence_branch,
975
location_config=precedence_location)
976
self.assertEqual(my_config.get_user_option('option'), 'recurse')
977
my_config = self.get_branch_config(global_config=precedence_global,
978
branch_data_config=precedence_branch,
979
location_config=precedence_location,
980
location='http://example.com/specific')
981
self.assertEqual(my_config.get_user_option('option'), 'exact')
984
class TestMailAddressExtraction(TestCase):
986
def test_extract_email_address(self):
987
self.assertEqual('jane@test.com',
988
config.extract_email_address('Jane <jane@test.com>'))
989
self.assertRaises(errors.NoEmailInUsername,
990
config.extract_email_address, 'Jane Tester')