272
359
self.assertEqual(branch.base, location_config.location)
273
360
self.failUnless(location_config is my_config._get_location_config())
362
def test_get_config(self):
363
"""The Branch.get_config method works properly"""
364
b = BzrDir.create_standalone_workingtree('.').branch
365
my_config = b.get_config()
366
self.assertIs(my_config.get_user_option('wacky'), None)
367
my_config.set_user_option('wacky', 'unlikely')
368
self.assertEqual(my_config.get_user_option('wacky'), 'unlikely')
370
# Ensure we get the same thing if we start again
371
b2 = Branch.open('.')
372
my_config2 = b2.get_config()
373
self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely')
375
def test_has_explicit_nickname(self):
376
b = self.make_branch('.')
377
self.assertFalse(b.get_config().has_explicit_nickname())
379
self.assertTrue(b.get_config().has_explicit_nickname())
381
def test_config_url(self):
382
"""The Branch.get_config will use section that uses a local url"""
383
branch = self.make_branch('branch')
384
self.assertEqual('branch', branch.nick)
386
locations = config.locations_config_filename()
387
config.ensure_config_dir_exists()
388
local_url = urlutils.local_path_to_url('branch')
389
open(locations, 'wb').write('[%s]\nnickname = foobar'
391
self.assertEqual('foobar', branch.nick)
393
def test_config_local_path(self):
394
"""The Branch.get_config will use a local system path"""
395
branch = self.make_branch('branch')
396
self.assertEqual('branch', branch.nick)
398
locations = config.locations_config_filename()
399
config.ensure_config_dir_exists()
400
open(locations, 'wb').write('[%s/branch]\nnickname = barry'
401
% (osutils.getcwd().encode('utf8'),))
402
self.assertEqual('barry', branch.nick)
404
def test_config_creates_local(self):
405
"""Creating a new entry in config uses a local path."""
406
branch = self.make_branch('branch', format='knit')
407
branch.set_push_location('http://foobar')
408
locations = config.locations_config_filename()
409
local_path = osutils.getcwd().encode('utf8')
410
# Surprisingly ConfigObj doesn't create a trailing newline
411
self.check_file_contents(locations,
412
'[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
414
def test_autonick_urlencoded(self):
415
b = self.make_branch('!repo')
416
self.assertEqual('!repo', b.get_config().get_nickname())
418
def test_warn_if_masked(self):
419
_warning = trace.warning
422
warnings.append(args[0] % args[1:])
424
def set_option(store, warn_masked=True):
426
conf.set_user_option('example_option', repr(store), store=store,
427
warn_masked=warn_masked)
428
def assertWarning(warning):
430
self.assertEqual(0, len(warnings))
432
self.assertEqual(1, len(warnings))
433
self.assertEqual(warning, warnings[0])
434
trace.warning = warning
436
branch = self.make_branch('.')
437
conf = branch.get_config()
438
set_option(config.STORE_GLOBAL)
440
set_option(config.STORE_BRANCH)
442
set_option(config.STORE_GLOBAL)
443
assertWarning('Value "4" is masked by "3" from branch.conf')
444
set_option(config.STORE_GLOBAL, warn_masked=False)
446
set_option(config.STORE_LOCATION)
448
set_option(config.STORE_BRANCH)
449
assertWarning('Value "3" is masked by "0" from locations.conf')
450
set_option(config.STORE_BRANCH, warn_masked=False)
453
trace.warning = _warning
276
456
class TestGlobalConfigItems(TestCase):
278
458
def test_user_id(self):
279
config_file = StringIO(sample_config_text)
459
config_file = StringIO(sample_config_text.encode('utf-8'))
280
460
my_config = config.GlobalConfig()
281
461
my_config._parser = my_config._get_parser(file=config_file)
282
self.assertEqual("Robert Collins <robertc@example.com>",
462
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
283
463
my_config._get_user_id())
285
465
def test_absent_user_id(self):
366
568
# replace the class that is constructured, to check its parameters
367
569
oldparserclass = config.ConfigObj
368
570
config.ConfigObj = InstrumentedConfigObj
369
my_config = config.LocationConfig('http://www.example.com')
572
my_config = config.LocationConfig('http://www.example.com')
371
573
parser = my_config._get_parser()
373
575
config.ConfigObj = oldparserclass
374
576
self.failUnless(isinstance(parser, InstrumentedConfigObj))
375
577
self.assertEqual(parser._calls,
376
[('__init__', config.branches_config_filename())])
578
[('__init__', config.locations_config_filename(),
580
config.ensure_config_dir_exists()
581
#os.mkdir(config.config_dir())
582
f = file(config.branches_config_filename(), 'wb')
585
oldparserclass = config.ConfigObj
586
config.ConfigObj = InstrumentedConfigObj
588
my_config = config.LocationConfig('http://www.example.com')
589
parser = my_config._get_parser()
591
config.ConfigObj = oldparserclass
378
593
def test_get_global_config(self):
379
my_config = config.LocationConfig('http://example.com')
594
my_config = config.BranchConfig(FakeBranch('http://example.com'))
380
595
global_config = my_config._get_global_config()
381
596
self.failUnless(isinstance(global_config, config.GlobalConfig))
382
597
self.failUnless(global_config is my_config._get_global_config())
384
def test__get_section_no_match(self):
385
self.get_location_config('/')
386
self.assertEqual(None, self.my_config._get_section())
599
def test__get_matching_sections_no_match(self):
600
self.get_branch_config('/')
601
self.assertEqual([], self.my_location_config._get_matching_sections())
388
def test__get_section_exact(self):
389
self.get_location_config('http://www.example.com')
390
self.assertEqual('http://www.example.com',
391
self.my_config._get_section())
603
def test__get_matching_sections_exact(self):
604
self.get_branch_config('http://www.example.com')
605
self.assertEqual([('http://www.example.com', '')],
606
self.my_location_config._get_matching_sections())
393
def test__get_section_suffix_does_not(self):
394
self.get_location_config('http://www.example.com-com')
395
self.assertEqual(None, self.my_config._get_section())
397
def test__get_section_subdir_recursive(self):
398
self.get_location_config('http://www.example.com/com')
399
self.assertEqual('http://www.example.com',
400
self.my_config._get_section())
402
def test__get_section_subdir_matches(self):
403
self.get_location_config('http://www.example.com/useglobal')
404
self.assertEqual('http://www.example.com/useglobal',
405
self.my_config._get_section())
407
def test__get_section_subdir_nonrecursive(self):
408
self.get_location_config(
409
'http://www.example.com/useglobal/childbranch')
410
self.assertEqual('http://www.example.com',
411
self.my_config._get_section())
413
def test__get_section_subdir_trailing_slash(self):
414
self.get_location_config('/b')
415
self.assertEqual('/b/', self.my_config._get_section())
417
def test__get_section_subdir_child(self):
418
self.get_location_config('/a/foo')
419
self.assertEqual('/a/*', self.my_config._get_section())
421
def test__get_section_subdir_child_child(self):
422
self.get_location_config('/a/foo/bar')
423
self.assertEqual('/a/', self.my_config._get_section())
425
def test__get_section_trailing_slash_with_children(self):
426
self.get_location_config('/a/')
427
self.assertEqual('/a/', self.my_config._get_section())
429
def test__get_section_explicit_over_glob(self):
430
self.get_location_config('/a/c')
431
self.assertEqual('/a/c', self.my_config._get_section())
433
def get_location_config(self, location, global_config=None):
434
if global_config is None:
435
global_file = StringIO(sample_config_text)
437
global_file = StringIO(global_config)
438
branches_file = StringIO(sample_branches_text)
439
self.my_config = config.LocationConfig(location)
440
self.my_config._get_parser(branches_file)
441
self.my_config._get_global_config()._get_parser(global_file)
608
def test__get_matching_sections_suffix_does_not(self):
609
self.get_branch_config('http://www.example.com-com')
610
self.assertEqual([], self.my_location_config._get_matching_sections())
612
def test__get_matching_sections_subdir_recursive(self):
613
self.get_branch_config('http://www.example.com/com')
614
self.assertEqual([('http://www.example.com', 'com')],
615
self.my_location_config._get_matching_sections())
617
def test__get_matching_sections_ignoreparent(self):
618
self.get_branch_config('http://www.example.com/ignoreparent')
619
self.assertEqual([('http://www.example.com/ignoreparent', '')],
620
self.my_location_config._get_matching_sections())
622
def test__get_matching_sections_ignoreparent_subdir(self):
623
self.get_branch_config(
624
'http://www.example.com/ignoreparent/childbranch')
625
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
626
self.my_location_config._get_matching_sections())
628
def test__get_matching_sections_subdir_trailing_slash(self):
629
self.get_branch_config('/b')
630
self.assertEqual([('/b/', '')],
631
self.my_location_config._get_matching_sections())
633
def test__get_matching_sections_subdir_child(self):
634
self.get_branch_config('/a/foo')
635
self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
636
self.my_location_config._get_matching_sections())
638
def test__get_matching_sections_subdir_child_child(self):
639
self.get_branch_config('/a/foo/bar')
640
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
641
self.my_location_config._get_matching_sections())
643
def test__get_matching_sections_trailing_slash_with_children(self):
644
self.get_branch_config('/a/')
645
self.assertEqual([('/a/', '')],
646
self.my_location_config._get_matching_sections())
648
def test__get_matching_sections_explicit_over_glob(self):
649
# XXX: 2006-09-08 jamesh
650
# This test only passes because ord('c') > ord('*'). If there
651
# was a config section for '/a/?', it would get precedence
653
self.get_branch_config('/a/c')
654
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
655
self.my_location_config._get_matching_sections())
657
def test__get_option_policy_normal(self):
658
self.get_branch_config('http://www.example.com')
660
self.my_location_config._get_config_policy(
661
'http://www.example.com', 'normal_option'),
664
def test__get_option_policy_norecurse(self):
665
self.get_branch_config('http://www.example.com')
667
self.my_location_config._get_option_policy(
668
'http://www.example.com', 'norecurse_option'),
669
config.POLICY_NORECURSE)
670
# Test old recurse=False setting:
672
self.my_location_config._get_option_policy(
673
'http://www.example.com/norecurse', 'normal_option'),
674
config.POLICY_NORECURSE)
676
def test__get_option_policy_normal(self):
677
self.get_branch_config('http://www.example.com')
679
self.my_location_config._get_option_policy(
680
'http://www.example.com', 'appendpath_option'),
681
config.POLICY_APPENDPATH)
443
683
def test_location_without_username(self):
444
self.get_location_config('http://www.example.com/useglobal')
445
self.assertEqual('Robert Collins <robertc@example.com>',
684
self.get_branch_config('http://www.example.com/ignoreparent')
685
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
446
686
self.my_config.username())
448
688
def test_location_not_listed(self):
449
self.get_location_config('/home/robertc/sources')
450
self.assertEqual('Robert Collins <robertc@example.com>',
689
"""Test that the global username is used when no location matches"""
690
self.get_branch_config('/home/robertc/sources')
691
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
451
692
self.my_config.username())
453
694
def test_overriding_location(self):
454
self.get_location_config('http://www.example.com/foo')
695
self.get_branch_config('http://www.example.com/foo')
455
696
self.assertEqual('Robert Collins <robertc@example.org>',
456
697
self.my_config.username())
458
699
def test_signatures_not_set(self):
459
self.get_location_config('http://www.example.com',
700
self.get_branch_config('http://www.example.com',
460
701
global_config=sample_ignore_signatures)
461
self.assertEqual(config.CHECK_NEVER,
702
self.assertEqual(config.CHECK_ALWAYS,
462
703
self.my_config.signature_checking())
704
self.assertEqual(config.SIGN_NEVER,
705
self.my_config.signing_policy())
464
707
def test_signatures_never(self):
465
self.get_location_config('/a/c')
708
self.get_branch_config('/a/c')
466
709
self.assertEqual(config.CHECK_NEVER,
467
710
self.my_config.signature_checking())
469
712
def test_signatures_when_available(self):
470
self.get_location_config('/a/', global_config=sample_ignore_signatures)
713
self.get_branch_config('/a/', global_config=sample_ignore_signatures)
471
714
self.assertEqual(config.CHECK_IF_POSSIBLE,
472
715
self.my_config.signature_checking())
474
717
def test_signatures_always(self):
475
self.get_location_config('/b')
718
self.get_branch_config('/b')
476
719
self.assertEqual(config.CHECK_ALWAYS,
477
720
self.my_config.signature_checking())
479
722
def test_gpg_signing_command(self):
480
self.get_location_config('/b')
723
self.get_branch_config('/b')
481
724
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
483
726
def test_gpg_signing_command_missing(self):
484
self.get_location_config('/a')
727
self.get_branch_config('/a')
485
728
self.assertEqual("false", self.my_config.gpg_signing_command())
487
730
def test_get_user_option_global(self):
488
self.get_location_config('/a')
731
self.get_branch_config('/a')
489
732
self.assertEqual('something',
490
733
self.my_config.get_user_option('user_global_option'))
492
735
def test_get_user_option_local(self):
493
self.get_location_config('/a')
736
self.get_branch_config('/a')
494
737
self.assertEqual('local',
495
738
self.my_config.get_user_option('user_local_option'))
740
def test_get_user_option_appendpath(self):
741
# returned as is for the base path:
742
self.get_branch_config('http://www.example.com')
743
self.assertEqual('append',
744
self.my_config.get_user_option('appendpath_option'))
745
# Extra path components get appended:
746
self.get_branch_config('http://www.example.com/a/b/c')
747
self.assertEqual('append/a/b/c',
748
self.my_config.get_user_option('appendpath_option'))
749
# Overriden for http://www.example.com/dir, where it is a
751
self.get_branch_config('http://www.example.com/dir/a/b/c')
752
self.assertEqual('normal',
753
self.my_config.get_user_option('appendpath_option'))
755
def test_get_user_option_norecurse(self):
756
self.get_branch_config('http://www.example.com')
757
self.assertEqual('norecurse',
758
self.my_config.get_user_option('norecurse_option'))
759
self.get_branch_config('http://www.example.com/dir')
760
self.assertEqual(None,
761
self.my_config.get_user_option('norecurse_option'))
762
# http://www.example.com/norecurse is a recurse=False section
763
# that redefines normal_option. Subdirectories do not pick up
765
self.get_branch_config('http://www.example.com/norecurse')
766
self.assertEqual('norecurse',
767
self.my_config.get_user_option('normal_option'))
768
self.get_branch_config('http://www.example.com/norecurse/subdir')
769
self.assertEqual('normal',
770
self.my_config.get_user_option('normal_option'))
772
def test_set_user_option_norecurse(self):
773
self.get_branch_config('http://www.example.com')
774
self.my_config.set_user_option('foo', 'bar',
775
store=config.STORE_LOCATION_NORECURSE)
777
self.my_location_config._get_option_policy(
778
'http://www.example.com', 'foo'),
779
config.POLICY_NORECURSE)
781
def test_set_user_option_appendpath(self):
782
self.get_branch_config('http://www.example.com')
783
self.my_config.set_user_option('foo', 'bar',
784
store=config.STORE_LOCATION_APPENDPATH)
786
self.my_location_config._get_option_policy(
787
'http://www.example.com', 'foo'),
788
config.POLICY_APPENDPATH)
790
def test_set_user_option_change_policy(self):
791
self.get_branch_config('http://www.example.com')
792
self.my_config.set_user_option('norecurse_option', 'normal',
793
store=config.STORE_LOCATION)
795
self.my_location_config._get_option_policy(
796
'http://www.example.com', 'norecurse_option'),
799
def test_set_user_option_recurse_false_section(self):
800
# The following section has recurse=False set. The test is to
801
# make sure that a normal option can be added to the section,
802
# converting recurse=False to the norecurse policy.
803
self.get_branch_config('http://www.example.com/norecurse')
804
self.callDeprecated(['The recurse option is deprecated as of 0.14. '
805
'The section "http://www.example.com/norecurse" '
806
'has been converted to use policies.'],
807
self.my_config.set_user_option,
808
'foo', 'bar', store=config.STORE_LOCATION)
810
self.my_location_config._get_option_policy(
811
'http://www.example.com/norecurse', 'foo'),
813
# The previously existing option is still norecurse:
815
self.my_location_config._get_option_policy(
816
'http://www.example.com/norecurse', 'normal_option'),
817
config.POLICY_NORECURSE)
497
819
def test_post_commit_default(self):
498
self.get_location_config('/a/c')
820
self.get_branch_config('/a/c')
499
821
self.assertEqual('bzrlib.tests.test_config.post_commit',
500
822
self.my_config.post_commit())
503
class TestLocationConfig(TestCaseInTempDir):
505
def get_location_config(self, location, global_config=None):
824
def get_branch_config(self, location, global_config=None):
506
825
if global_config is None:
507
global_file = StringIO(sample_config_text)
826
global_file = StringIO(sample_config_text.encode('utf-8'))
509
global_file = StringIO(global_config)
510
branches_file = StringIO(sample_branches_text)
511
self.my_config = config.LocationConfig(location)
512
self.my_config._get_parser(branches_file)
828
global_file = StringIO(global_config.encode('utf-8'))
829
branches_file = StringIO(sample_branches_text.encode('utf-8'))
830
self.my_config = config.BranchConfig(FakeBranch(location))
831
# Force location config to use specified file
832
self.my_location_config = self.my_config._get_location_config()
833
self.my_location_config._get_parser(branches_file)
834
# Force global config to use specified file
513
835
self.my_config._get_global_config()._get_parser(global_file)
515
837
def test_set_user_setting_sets_and_saves(self):
516
self.get_location_config('/a/c')
838
self.get_branch_config('/a/c')
517
839
record = InstrumentedConfigObj("foo")
518
self.my_config._parser = record
840
self.my_location_config._parser = record
520
842
real_mkdir = os.mkdir
521
843
self.created = False
536
862
('__setitem__', '/a/c', {}),
537
863
('__getitem__', '/a/c'),
538
864
('__setitem__', 'foo', 'bar'),
865
('__getitem__', '/a/c'),
866
('as_bool', 'recurse'),
867
('__getitem__', '/a/c'),
868
('__delitem__', 'recurse'),
869
('__getitem__', '/a/c'),
871
('__getitem__', '/a/c'),
872
('__contains__', 'foo:policy'),
540
874
record._calls[1:])
543
class TestBranchConfigItems(TestCase):
876
def test_set_user_setting_sets_and_saves2(self):
877
self.get_branch_config('/a/c')
878
self.assertIs(self.my_config.get_user_option('foo'), None)
879
self.my_config.set_user_option('foo', 'bar')
881
self.my_config.branch.control_files.files['branch.conf'],
883
self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
884
self.my_config.set_user_option('foo', 'baz',
885
store=config.STORE_LOCATION)
886
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
887
self.my_config.set_user_option('foo', 'qux')
888
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
891
precedence_global = 'option = global'
892
precedence_branch = 'option = branch'
893
precedence_location = """
897
[http://example.com/specific]
902
class TestBranchConfigItems(TestCaseInTempDir):
904
def get_branch_config(self, global_config=None, location=None,
905
location_config=None, branch_data_config=None):
906
my_config = config.BranchConfig(FakeBranch(location))
907
if global_config is not None:
908
global_file = StringIO(global_config.encode('utf-8'))
909
my_config._get_global_config()._get_parser(global_file)
910
self.my_location_config = my_config._get_location_config()
911
if location_config is not None:
912
location_file = StringIO(location_config.encode('utf-8'))
913
self.my_location_config._get_parser(location_file)
914
if branch_data_config is not None:
915
my_config.branch.control_files.files['branch.conf'] = \
545
919
def test_user_id(self):
546
branch = FakeBranch()
920
branch = FakeBranch(user_id='Robert Collins <robertc@example.net>')
547
921
my_config = config.BranchConfig(branch)
548
922
self.assertEqual("Robert Collins <robertc@example.net>",
549
my_config._get_user_id())
923
my_config.username())
550
924
branch.control_files.email = "John"
551
self.assertEqual("John", my_config._get_user_id())
925
my_config.set_user_option('email',
926
"Robert Collins <robertc@example.org>")
927
self.assertEqual("John", my_config.username())
928
branch.control_files.email = None
929
self.assertEqual("Robert Collins <robertc@example.org>",
930
my_config.username())
553
932
def test_not_set_in_branch(self):
554
branch = FakeBranch()
555
my_config = config.BranchConfig(branch)
556
branch.control_files.email = None
557
config_file = StringIO(sample_config_text)
558
(my_config._get_location_config().
559
_get_global_config()._get_parser(config_file))
560
self.assertEqual("Robert Collins <robertc@example.com>",
933
my_config = self.get_branch_config(sample_config_text)
934
my_config.branch.control_files.email = None
935
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
561
936
my_config._get_user_id())
562
branch.control_files.email = "John"
937
my_config.branch.control_files.email = "John"
563
938
self.assertEqual("John", my_config._get_user_id())
565
def test_BZREMAIL_OVERRIDES(self):
566
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>"
940
def test_BZR_EMAIL_OVERRIDES(self):
941
os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
567
942
branch = FakeBranch()
568
943
my_config = config.BranchConfig(branch)
569
944
self.assertEqual("Robert Collins <robertc@example.org>",
570
945
my_config.username())
572
947
def test_signatures_forced(self):
573
branch = FakeBranch()
574
my_config = config.BranchConfig(branch)
575
config_file = StringIO(sample_always_signatures)
576
(my_config._get_location_config().
577
_get_global_config()._get_parser(config_file))
578
self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking())
948
my_config = self.get_branch_config(
949
global_config=sample_always_signatures)
950
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
951
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
952
self.assertTrue(my_config.signature_needed())
954
def test_signatures_forced_branch(self):
955
my_config = self.get_branch_config(
956
global_config=sample_ignore_signatures,
957
branch_data_config=sample_always_signatures)
958
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
959
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
960
self.assertTrue(my_config.signature_needed())
580
962
def test_gpg_signing_command(self):
581
branch = FakeBranch()
582
my_config = config.BranchConfig(branch)
583
config_file = StringIO(sample_config_text)
584
(my_config._get_location_config().
585
_get_global_config()._get_parser(config_file))
963
my_config = self.get_branch_config(
964
# branch data cannot set gpg_signing_command
965
branch_data_config="gpg_signing_command=pgp")
966
config_file = StringIO(sample_config_text.encode('utf-8'))
967
my_config._get_global_config()._get_parser(config_file)
586
968
self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
588
970
def test_get_user_option_global(self):
589
971
branch = FakeBranch()
590
972
my_config = config.BranchConfig(branch)
591
config_file = StringIO(sample_config_text)
592
(my_config._get_location_config().
593
_get_global_config()._get_parser(config_file))
973
config_file = StringIO(sample_config_text.encode('utf-8'))
974
(my_config._get_global_config()._get_parser(config_file))
594
975
self.assertEqual('something',
595
976
my_config.get_user_option('user_global_option'))
597
978
def test_post_commit_default(self):
598
979
branch = FakeBranch()
600
my_config = config.BranchConfig(branch)
601
config_file = StringIO(sample_config_text)
602
(my_config._get_location_config().
603
_get_global_config()._get_parser(config_file))
604
branch_file = StringIO(sample_branches_text)
605
my_config._get_location_config()._get_parser(branch_file)
606
self.assertEqual('bzrlib.tests.test_config.post_commit',
607
my_config.post_commit())
980
my_config = self.get_branch_config(sample_config_text, '/a/c',
981
sample_branches_text)
982
self.assertEqual(my_config.branch.base, '/a/c')
983
self.assertEqual('bzrlib.tests.test_config.post_commit',
984
my_config.post_commit())
985
my_config.set_user_option('post_commit', 'rmtree_root')
986
# post-commit is ignored when bresent in branch data
987
self.assertEqual('bzrlib.tests.test_config.post_commit',
988
my_config.post_commit())
989
my_config.set_user_option('post_commit', 'rmtree_root',
990
store=config.STORE_LOCATION)
991
self.assertEqual('rmtree_root', my_config.post_commit())
993
def test_config_precedence(self):
994
my_config = self.get_branch_config(global_config=precedence_global)
995
self.assertEqual(my_config.get_user_option('option'), 'global')
996
my_config = self.get_branch_config(global_config=precedence_global,
997
branch_data_config=precedence_branch)
998
self.assertEqual(my_config.get_user_option('option'), 'branch')
999
my_config = self.get_branch_config(global_config=precedence_global,
1000
branch_data_config=precedence_branch,
1001
location_config=precedence_location)
1002
self.assertEqual(my_config.get_user_option('option'), 'recurse')
1003
my_config = self.get_branch_config(global_config=precedence_global,
1004
branch_data_config=precedence_branch,
1005
location_config=precedence_location,
1006
location='http://example.com/specific')
1007
self.assertEqual(my_config.get_user_option('option'), 'exact')
1009
def test_get_mail_client(self):
1010
config = self.get_branch_config()
1011
client = config.get_mail_client()
1012
self.assertIsInstance(client, mail_client.DefaultMail)
1014
config.set_user_option('mail_client', 'default')
1015
client = config.get_mail_client()
1016
self.assertIsInstance(client, mail_client.DefaultMail)
1018
config.set_user_option('mail_client', 'editor')
1019
client = config.get_mail_client()
1020
self.assertIsInstance(client, mail_client.Editor)
1022
config.set_user_option('mail_client', 'thunderbird')
1023
client = config.get_mail_client()
1024
self.assertIsInstance(client, mail_client.Thunderbird)
1026
config.set_user_option('mail_client', 'evolution')
1027
client = config.get_mail_client()
1028
self.assertIsInstance(client, mail_client.Evolution)
1030
config.set_user_option('mail_client', 'kmail')
1031
client = config.get_mail_client()
1032
self.assertIsInstance(client, mail_client.KMail)
1034
config.set_user_option('mail_client', 'xdg-email')
1035
client = config.get_mail_client()
1036
self.assertIsInstance(client, mail_client.XDGEmail)
1038
config.set_user_option('mail_client', 'mapi')
1039
client = config.get_mail_client()
1040
self.assertIsInstance(client, mail_client.MAPIClient)
1042
config.set_user_option('mail_client', 'firebird')
1043
self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
610
1046
class TestMailAddressExtraction(TestCase):