477
248
config_file = StringIO(sample_always_signatures)
478
249
my_config = config.GlobalConfig()
479
250
my_config._parser = my_config._get_parser(file=config_file)
480
self.assertEqual(config.CHECK_NEVER,
251
self.assertEqual(config.CHECK_ALWAYS,
481
252
my_config.signature_checking())
482
self.assertEqual(config.SIGN_ALWAYS,
483
my_config.signing_policy())
484
253
self.assertEqual(True, my_config.signature_needed())
486
255
def test_signatures_if_possible(self):
487
256
config_file = StringIO(sample_maybe_signatures)
488
257
my_config = config.GlobalConfig()
489
258
my_config._parser = my_config._get_parser(file=config_file)
490
self.assertEqual(config.CHECK_NEVER,
259
self.assertEqual(config.CHECK_IF_POSSIBLE,
491
260
my_config.signature_checking())
492
self.assertEqual(config.SIGN_WHEN_REQUIRED,
493
my_config.signing_policy())
494
261
self.assertEqual(False, my_config.signature_needed())
496
263
def test_signatures_ignore(self):
497
264
config_file = StringIO(sample_ignore_signatures)
498
265
my_config = config.GlobalConfig()
499
266
my_config._parser = my_config._get_parser(file=config_file)
500
self.assertEqual(config.CHECK_ALWAYS,
267
self.assertEqual(config.CHECK_NEVER,
501
268
my_config.signature_checking())
502
self.assertEqual(config.SIGN_NEVER,
503
my_config.signing_policy())
504
269
self.assertEqual(False, my_config.signature_needed())
506
def _get_sample_config(self):
507
config_file = StringIO(sample_config_text.encode('utf-8'))
508
my_config = config.GlobalConfig()
509
my_config._parser = my_config._get_parser(file=config_file)
512
271
def test_gpg_signing_command(self):
513
my_config = self._get_sample_config()
272
config_file = StringIO(sample_config_text)
273
my_config = config.GlobalConfig()
274
my_config._parser = my_config._get_parser(file=config_file)
514
275
self.assertEqual("gnome-gpg", my_config.gpg_signing_command())
515
276
self.assertEqual(False, my_config.signature_needed())
517
def _get_empty_config(self):
518
config_file = StringIO("")
519
my_config = config.GlobalConfig()
520
my_config._parser = my_config._get_parser(file=config_file)
523
278
def test_gpg_signing_command_unset(self):
524
my_config = self._get_empty_config()
279
config_file = StringIO("")
280
my_config = config.GlobalConfig()
281
my_config._parser = my_config._get_parser(file=config_file)
525
282
self.assertEqual("gpg", my_config.gpg_signing_command())
527
def test_get_user_option_default(self):
528
my_config = self._get_empty_config()
529
self.assertEqual(None, my_config.get_user_option('no_option'))
531
def test_get_user_option_global(self):
532
my_config = self._get_sample_config()
533
self.assertEqual("something",
534
my_config.get_user_option('user_global_option'))
536
def test_post_commit_default(self):
537
my_config = self._get_sample_config()
538
self.assertEqual(None, my_config.post_commit())
540
def test_configured_logformat(self):
541
my_config = self._get_sample_config()
542
self.assertEqual("short", my_config.log_format())
544
def test_get_alias(self):
545
my_config = self._get_sample_config()
546
self.assertEqual('help', my_config.get_alias('h'))
548
def test_get_no_alias(self):
549
my_config = self._get_sample_config()
550
self.assertEqual(None, my_config.get_alias('foo'))
552
def test_get_long_alias(self):
553
my_config = self._get_sample_config()
554
self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
557
class TestLocationConfig(TestCaseInTempDir):
285
class TestLocationConfig(TestCase):
559
287
def test_constructs(self):
560
288
my_config = config.LocationConfig('http://example.com')
561
289
self.assertRaises(TypeError, config.LocationConfig)
563
291
def test_branch_calls_read_filenames(self):
564
# This is testing the correct file names are provided.
565
# TODO: consolidate with the test for GlobalConfigs filename checks.
567
292
# replace the class that is constructured, to check its parameters
568
oldparserclass = config.ConfigObj
569
config.ConfigObj = InstrumentedConfigObj
571
my_config = config.LocationConfig('http://www.example.com')
572
parser = my_config._get_parser()
574
config.ConfigObj = oldparserclass
575
self.failUnless(isinstance(parser, InstrumentedConfigObj))
576
self.assertEqual(parser._calls,
577
[('__init__', config.locations_config_filename(),
579
config.ensure_config_dir_exists()
580
#os.mkdir(config.config_dir())
581
f = file(config.branches_config_filename(), 'wb')
584
oldparserclass = config.ConfigObj
585
config.ConfigObj = InstrumentedConfigObj
587
my_config = config.LocationConfig('http://www.example.com')
588
parser = my_config._get_parser()
590
config.ConfigObj = oldparserclass
293
oldparserclass = config.ConfigParser
294
config.ConfigParser = InstrumentedConfigParser
295
my_config = config.LocationConfig('http://www.example.com')
297
parser = my_config._get_parser()
299
config.ConfigParser = oldparserclass
300
self.failUnless(isinstance(parser, InstrumentedConfigParser))
301
self.assertEqual(parser._calls, [('read', [config.branches_config_filename()])])
592
303
def test_get_global_config(self):
593
my_config = config.BranchConfig(FakeBranch('http://example.com'))
304
my_config = config.LocationConfig('http://example.com')
594
305
global_config = my_config._get_global_config()
595
306
self.failUnless(isinstance(global_config, config.GlobalConfig))
596
307
self.failUnless(global_config is my_config._get_global_config())
598
def test__get_matching_sections_no_match(self):
599
self.get_branch_config('/')
600
self.assertEqual([], self.my_location_config._get_matching_sections())
309
def test__get_section_no_match(self):
310
self.get_location_config('/')
311
self.assertEqual(None, self.my_config._get_section())
602
def test__get_matching_sections_exact(self):
603
self.get_branch_config('http://www.example.com')
604
self.assertEqual([('http://www.example.com', '')],
605
self.my_location_config._get_matching_sections())
313
def test__get_section_exact(self):
314
self.get_location_config('http://www.example.com')
315
self.assertEqual('http://www.example.com',
316
self.my_config._get_section())
607
def test__get_matching_sections_suffix_does_not(self):
608
self.get_branch_config('http://www.example.com-com')
609
self.assertEqual([], self.my_location_config._get_matching_sections())
611
def test__get_matching_sections_subdir_recursive(self):
612
self.get_branch_config('http://www.example.com/com')
613
self.assertEqual([('http://www.example.com', 'com')],
614
self.my_location_config._get_matching_sections())
616
def test__get_matching_sections_ignoreparent(self):
617
self.get_branch_config('http://www.example.com/ignoreparent')
618
self.assertEqual([('http://www.example.com/ignoreparent', '')],
619
self.my_location_config._get_matching_sections())
621
def test__get_matching_sections_ignoreparent_subdir(self):
622
self.get_branch_config(
623
'http://www.example.com/ignoreparent/childbranch')
624
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
625
self.my_location_config._get_matching_sections())
627
def test__get_matching_sections_subdir_trailing_slash(self):
628
self.get_branch_config('/b')
629
self.assertEqual([('/b/', '')],
630
self.my_location_config._get_matching_sections())
632
def test__get_matching_sections_subdir_child(self):
633
self.get_branch_config('/a/foo')
634
self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
635
self.my_location_config._get_matching_sections())
637
def test__get_matching_sections_subdir_child_child(self):
638
self.get_branch_config('/a/foo/bar')
639
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
640
self.my_location_config._get_matching_sections())
642
def test__get_matching_sections_trailing_slash_with_children(self):
643
self.get_branch_config('/a/')
644
self.assertEqual([('/a/', '')],
645
self.my_location_config._get_matching_sections())
647
def test__get_matching_sections_explicit_over_glob(self):
648
# XXX: 2006-09-08 jamesh
649
# This test only passes because ord('c') > ord('*'). If there
650
# was a config section for '/a/?', it would get precedence
652
self.get_branch_config('/a/c')
653
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
654
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)
318
def test__get_section_suffix_does_not(self):
319
self.get_location_config('http://www.example.com-com')
320
self.assertEqual(None, self.my_config._get_section())
322
def test__get_section_subdir_recursive(self):
323
self.get_location_config('http://www.example.com/com')
324
self.assertEqual('http://www.example.com',
325
self.my_config._get_section())
327
def test__get_section_subdir_matches(self):
328
self.get_location_config('http://www.example.com/useglobal')
329
self.assertEqual('http://www.example.com/useglobal',
330
self.my_config._get_section())
332
def test__get_section_subdir_nonrecursive(self):
333
self.get_location_config(
334
'http://www.example.com/useglobal/childbranch')
335
self.assertEqual('http://www.example.com',
336
self.my_config._get_section())
338
def test__get_section_subdir_trailing_slash(self):
339
self.get_location_config('/b')
340
self.assertEqual('/b/', self.my_config._get_section())
342
def test__get_section_subdir_child(self):
343
self.get_location_config('/a/foo')
344
self.assertEqual('/a/*', self.my_config._get_section())
346
def test__get_section_subdir_child_child(self):
347
self.get_location_config('/a/foo/bar')
348
self.assertEqual('/a/', self.my_config._get_section())
350
def test__get_section_trailing_slash_with_children(self):
351
self.get_location_config('/a/')
352
self.assertEqual('/a/', self.my_config._get_section())
354
def test__get_section_explicit_over_glob(self):
355
self.get_location_config('/a/c')
356
self.assertEqual('/a/c', self.my_config._get_section())
358
def get_location_config(self, location, global_config=None):
359
if global_config is None:
360
global_file = StringIO(sample_config_text)
362
global_file = StringIO(global_config)
363
branches_file = StringIO(sample_branches_text)
364
self.my_config = config.LocationConfig(location)
365
self.my_config._get_parser(branches_file)
366
self.my_config._get_global_config()._get_parser(global_file)
682
368
def test_location_without_username(self):
683
self.get_branch_config('http://www.example.com/ignoreparent')
684
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
369
self.get_location_config('http://www.example.com/useglobal')
370
self.assertEqual('Robert Collins <robertc@example.com>',
685
371
self.my_config.username())
687
373
def test_location_not_listed(self):
688
"""Test that the global username is used when no location matches"""
689
self.get_branch_config('/home/robertc/sources')
690
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
374
self.get_location_config('/home/robertc/sources')
375
self.assertEqual('Robert Collins <robertc@example.com>',
691
376
self.my_config.username())
693
378
def test_overriding_location(self):
694
self.get_branch_config('http://www.example.com/foo')
379
self.get_location_config('http://www.example.com/foo')
695
380
self.assertEqual('Robert Collins <robertc@example.org>',
696
381
self.my_config.username())
698
383
def test_signatures_not_set(self):
699
self.get_branch_config('http://www.example.com',
384
self.get_location_config('http://www.example.com',
700
385
global_config=sample_ignore_signatures)
701
self.assertEqual(config.CHECK_ALWAYS,
386
self.assertEqual(config.CHECK_NEVER,
702
387
self.my_config.signature_checking())
703
self.assertEqual(config.SIGN_NEVER,
704
self.my_config.signing_policy())
706
389
def test_signatures_never(self):
707
self.get_branch_config('/a/c')
390
self.get_location_config('/a/c')
708
391
self.assertEqual(config.CHECK_NEVER,
709
392
self.my_config.signature_checking())
711
394
def test_signatures_when_available(self):
712
self.get_branch_config('/a/', global_config=sample_ignore_signatures)
395
self.get_location_config('/a/', global_config=sample_ignore_signatures)
713
396
self.assertEqual(config.CHECK_IF_POSSIBLE,
714
397
self.my_config.signature_checking())
716
399
def test_signatures_always(self):
717
self.get_branch_config('/b')
400
self.get_location_config('/b')
718
401
self.assertEqual(config.CHECK_ALWAYS,
719
402
self.my_config.signature_checking())
721
404
def test_gpg_signing_command(self):
722
self.get_branch_config('/b')
405
self.get_location_config('/b')
723
406
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
725
408
def test_gpg_signing_command_missing(self):
726
self.get_branch_config('/a')
409
self.get_location_config('/a')
727
410
self.assertEqual("false", self.my_config.gpg_signing_command())
729
def test_get_user_option_global(self):
730
self.get_branch_config('/a')
731
self.assertEqual('something',
732
self.my_config.get_user_option('user_global_option'))
734
def test_get_user_option_local(self):
735
self.get_branch_config('/a')
736
self.assertEqual('local',
737
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
def test_post_commit_default(self):
819
self.get_branch_config('/a/c')
820
self.assertEqual('bzrlib.tests.test_config.post_commit',
821
self.my_config.post_commit())
823
def get_branch_config(self, location, global_config=None):
824
if global_config is None:
825
global_file = StringIO(sample_config_text.encode('utf-8'))
827
global_file = StringIO(global_config.encode('utf-8'))
828
branches_file = StringIO(sample_branches_text.encode('utf-8'))
829
self.my_config = config.BranchConfig(FakeBranch(location))
830
# Force location config to use specified file
831
self.my_location_config = self.my_config._get_location_config()
832
self.my_location_config._get_parser(branches_file)
833
# Force global config to use specified file
834
self.my_config._get_global_config()._get_parser(global_file)
836
def test_set_user_setting_sets_and_saves(self):
837
self.get_branch_config('/a/c')
838
record = InstrumentedConfigObj("foo")
839
self.my_location_config._parser = record
841
real_mkdir = os.mkdir
843
def checked_mkdir(path, mode=0777):
844
self.log('making directory: %s', path)
845
real_mkdir(path, mode)
848
os.mkdir = checked_mkdir
850
self.callDeprecated(['The recurse option is deprecated as of '
851
'0.14. The section "/a/c" has been '
852
'converted to use policies.'],
853
self.my_config.set_user_option,
854
'foo', 'bar', store=config.STORE_LOCATION)
856
os.mkdir = real_mkdir
858
self.failUnless(self.created, 'Failed to create ~/.bazaar')
859
self.assertEqual([('__contains__', '/a/c'),
860
('__contains__', '/a/c/'),
861
('__setitem__', '/a/c', {}),
862
('__getitem__', '/a/c'),
863
('__setitem__', 'foo', 'bar'),
864
('__getitem__', '/a/c'),
865
('as_bool', 'recurse'),
866
('__getitem__', '/a/c'),
867
('__delitem__', 'recurse'),
868
('__getitem__', '/a/c'),
870
('__getitem__', '/a/c'),
871
('__contains__', 'foo:policy'),
875
def test_set_user_setting_sets_and_saves2(self):
876
self.get_branch_config('/a/c')
877
self.assertIs(self.my_config.get_user_option('foo'), None)
878
self.my_config.set_user_option('foo', 'bar')
880
self.my_config.branch.control_files.files['branch.conf'],
882
self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
883
self.my_config.set_user_option('foo', 'baz',
884
store=config.STORE_LOCATION)
885
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
886
self.my_config.set_user_option('foo', 'qux')
887
self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
890
precedence_global = 'option = global'
891
precedence_branch = 'option = branch'
892
precedence_location = """
896
[http://example.com/specific]
901
class TestBranchConfigItems(TestCaseInTempDir):
903
def get_branch_config(self, global_config=None, location=None,
904
location_config=None, branch_data_config=None):
905
my_config = config.BranchConfig(FakeBranch(location))
906
if global_config is not None:
907
global_file = StringIO(global_config.encode('utf-8'))
908
my_config._get_global_config()._get_parser(global_file)
909
self.my_location_config = my_config._get_location_config()
910
if location_config is not None:
911
location_file = StringIO(location_config.encode('utf-8'))
912
self.my_location_config._get_parser(location_file)
913
if branch_data_config is not None:
914
my_config.branch.control_files.files['branch.conf'] = \
413
class TestBranchConfigItems(TestCase):
918
415
def test_user_id(self):
919
branch = FakeBranch(user_id='Robert Collins <robertc@example.net>')
416
branch = FakeBranch()
920
417
my_config = config.BranchConfig(branch)
921
418
self.assertEqual("Robert Collins <robertc@example.net>",
922
my_config.username())
923
branch.control_files.email = "John"
924
my_config.set_user_option('email',
925
"Robert Collins <robertc@example.org>")
926
self.assertEqual("John", my_config.username())
927
branch.control_files.email = None
928
self.assertEqual("Robert Collins <robertc@example.org>",
929
my_config.username())
419
my_config._get_user_id())
420
branch.email = "John"
421
self.assertEqual("John", my_config._get_user_id())
931
423
def test_not_set_in_branch(self):
932
my_config = self.get_branch_config(sample_config_text)
933
my_config.branch.control_files.email = None
934
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
424
branch = FakeBranch()
425
my_config = config.BranchConfig(branch)
427
config_file = StringIO(sample_config_text)
428
(my_config._get_location_config().
429
_get_global_config()._get_parser(config_file))
430
self.assertEqual("Robert Collins <robertc@example.com>",
935
431
my_config._get_user_id())
936
my_config.branch.control_files.email = "John"
432
branch.email = "John"
937
433
self.assertEqual("John", my_config._get_user_id())
939
def test_BZR_EMAIL_OVERRIDES(self):
940
os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
435
def test_BZREMAIL_OVERRIDES(self):
436
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>"
941
437
branch = FakeBranch()
942
438
my_config = config.BranchConfig(branch)
943
439
self.assertEqual("Robert Collins <robertc@example.org>",
944
440
my_config.username())
946
442
def test_signatures_forced(self):
947
my_config = self.get_branch_config(
948
global_config=sample_always_signatures)
949
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
950
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
951
self.assertTrue(my_config.signature_needed())
953
def test_signatures_forced_branch(self):
954
my_config = self.get_branch_config(
955
global_config=sample_ignore_signatures,
956
branch_data_config=sample_always_signatures)
957
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
958
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
959
self.assertTrue(my_config.signature_needed())
443
branch = FakeBranch()
444
my_config = config.BranchConfig(branch)
445
config_file = StringIO(sample_always_signatures)
446
(my_config._get_location_config().
447
_get_global_config()._get_parser(config_file))
448
self.assertEqual(config.CHECK_ALWAYS, my_config.signature_checking())
961
450
def test_gpg_signing_command(self):
962
my_config = self.get_branch_config(
963
# branch data cannot set gpg_signing_command
964
branch_data_config="gpg_signing_command=pgp")
965
config_file = StringIO(sample_config_text.encode('utf-8'))
966
my_config._get_global_config()._get_parser(config_file)
451
branch = FakeBranch()
452
my_config = config.BranchConfig(branch)
453
config_file = StringIO(sample_config_text)
454
(my_config._get_location_config().
455
_get_global_config()._get_parser(config_file))
967
456
self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
969
def test_get_user_option_global(self):
970
branch = FakeBranch()
971
my_config = config.BranchConfig(branch)
972
config_file = StringIO(sample_config_text.encode('utf-8'))
973
(my_config._get_global_config()._get_parser(config_file))
974
self.assertEqual('something',
975
my_config.get_user_option('user_global_option'))
977
def test_post_commit_default(self):
978
branch = FakeBranch()
979
my_config = self.get_branch_config(sample_config_text, '/a/c',
980
sample_branches_text)
981
self.assertEqual(my_config.branch.base, '/a/c')
982
self.assertEqual('bzrlib.tests.test_config.post_commit',
983
my_config.post_commit())
984
my_config.set_user_option('post_commit', 'rmtree_root')
985
# post-commit is ignored when bresent in branch data
986
self.assertEqual('bzrlib.tests.test_config.post_commit',
987
my_config.post_commit())
988
my_config.set_user_option('post_commit', 'rmtree_root',
989
store=config.STORE_LOCATION)
990
self.assertEqual('rmtree_root', my_config.post_commit())
992
def test_config_precedence(self):
993
my_config = self.get_branch_config(global_config=precedence_global)
994
self.assertEqual(my_config.get_user_option('option'), 'global')
995
my_config = self.get_branch_config(global_config=precedence_global,
996
branch_data_config=precedence_branch)
997
self.assertEqual(my_config.get_user_option('option'), 'branch')
998
my_config = self.get_branch_config(global_config=precedence_global,
999
branch_data_config=precedence_branch,
1000
location_config=precedence_location)
1001
self.assertEqual(my_config.get_user_option('option'), 'recurse')
1002
my_config = self.get_branch_config(global_config=precedence_global,
1003
branch_data_config=precedence_branch,
1004
location_config=precedence_location,
1005
location='http://example.com/specific')
1006
self.assertEqual(my_config.get_user_option('option'), 'exact')
1009
class TestMailAddressExtraction(TestCase):
1011
def test_extract_email_address(self):
1012
self.assertEqual('jane@test.com',
1013
config.extract_email_address('Jane <jane@test.com>'))
1014
self.assertRaises(errors.NoEmailInUsername,
1015
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')