~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
64
64
sample_branches_text = ("[http://www.example.com]\n"
65
65
                        "# Top level policy\n"
66
66
                        "email=Robert Collins <robertc@example.org>\n"
67
 
                        "[http://www.example.com/useglobal]\n"
68
 
                        "# different project, forces global lookup\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"
69
72
                        "recurse=false\n"
70
73
                        "[/b/]\n"
71
74
                        "check_signatures=require\n"
77
80
                        "# test trailing / matching\n"
78
81
                        "[/a/*]\n"
79
82
                        "#subdirs will match but not the parent\n"
80
 
                        "recurse=False\n"
81
83
                        "[/a/c]\n"
82
84
                        "check_signatures=ignore\n"
83
85
                        "post_commit=bzrlib.tests.test_config.post_commit\n"
535
537
        self.failUnless(isinstance(global_config, config.GlobalConfig))
536
538
        self.failUnless(global_config is my_config._get_global_config())
537
539
 
538
 
    def test__get_section_no_match(self):
 
540
    def test__get_matching_sections_no_match(self):
539
541
        self.get_branch_config('/')
540
 
        self.assertEqual(None, self.my_location_config._get_section())
 
542
        self.assertEqual([], self.my_location_config._get_matching_sections())
541
543
        
542
 
    def test__get_section_exact(self):
 
544
    def test__get_matching_sections_exact(self):
543
545
        self.get_branch_config('http://www.example.com')
544
 
        self.assertEqual('http://www.example.com',
545
 
                         self.my_location_config._get_section())
 
546
        self.assertEqual([('http://www.example.com', '')],
 
547
                         self.my_location_config._get_matching_sections())
546
548
   
547
 
    def test__get_section_suffix_does_not(self):
 
549
    def test__get_matching_sections_suffix_does_not(self):
548
550
        self.get_branch_config('http://www.example.com-com')
549
 
        self.assertEqual(None, self.my_location_config._get_section())
 
551
        self.assertEqual([], self.my_location_config._get_matching_sections())
550
552
 
551
 
    def test__get_section_subdir_recursive(self):
 
553
    def test__get_matching_sections_subdir_recursive(self):
552
554
        self.get_branch_config('http://www.example.com/com')
553
 
        self.assertEqual('http://www.example.com',
554
 
                         self.my_location_config._get_section())
555
 
 
556
 
    def test__get_section_subdir_matches(self):
557
 
        self.get_branch_config('http://www.example.com/useglobal')
558
 
        self.assertEqual('http://www.example.com/useglobal',
559
 
                         self.my_location_config._get_section())
560
 
 
561
 
    def test__get_section_subdir_nonrecursive(self):
562
 
        self.get_branch_config(
563
 
            'http://www.example.com/useglobal/childbranch')
564
 
        self.assertEqual('http://www.example.com',
565
 
                         self.my_location_config._get_section())
566
 
 
567
 
    def test__get_section_subdir_trailing_slash(self):
 
555
        self.assertEqual([('http://www.example.com', 'com')],
 
556
                         self.my_location_config._get_matching_sections())
 
557
 
 
558
    def test__get_matching_sections_ignoreparent(self):
 
559
        self.get_branch_config('http://www.example.com/ignoreparent')
 
560
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
 
561
                         self.my_location_config._get_matching_sections())
 
562
 
 
563
    def test__get_matching_sections_ignoreparent_subdir(self):
 
564
        self.get_branch_config(
 
565
            'http://www.example.com/ignoreparent/childbranch')
 
566
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
 
567
                         self.my_location_config._get_matching_sections())
 
568
 
 
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())
 
574
 
 
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())
 
580
 
 
581
    def test__get_matching_sections_subdir_trailing_slash(self):
568
582
        self.get_branch_config('/b')
569
 
        self.assertEqual('/b/', self.my_location_config._get_section())
 
583
        self.assertEqual([('/b/', '')],
 
584
                         self.my_location_config._get_matching_sections())
570
585
 
571
 
    def test__get_section_subdir_child(self):
 
586
    def test__get_matching_sections_subdir_child(self):
572
587
        self.get_branch_config('/a/foo')
573
 
        self.assertEqual('/a/*', self.my_location_config._get_section())
 
588
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
 
589
                         self.my_location_config._get_matching_sections())
574
590
 
575
 
    def test__get_section_subdir_child_child(self):
 
591
    def test__get_matching_sections_subdir_child_child(self):
576
592
        self.get_branch_config('/a/foo/bar')
577
 
        self.assertEqual('/a/', self.my_location_config._get_section())
 
593
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
 
594
                         self.my_location_config._get_matching_sections())
578
595
 
579
 
    def test__get_section_trailing_slash_with_children(self):
 
596
    def test__get_matching_sections_trailing_slash_with_children(self):
580
597
        self.get_branch_config('/a/')
581
 
        self.assertEqual('/a/', self.my_location_config._get_section())
 
598
        self.assertEqual([('/a/', '')],
 
599
                         self.my_location_config._get_matching_sections())
582
600
 
583
 
    def test__get_section_explicit_over_glob(self):
 
601
    def test__get_matching_sections_explicit_over_glob(self):
 
602
        # XXX: 2006-09-08 jamesh
 
603
        # This test only passes because ord('c') > ord('*').  If there
 
604
        # was a config section for '/a/?', it would get precedence
 
605
        # over '/a/c'.
584
606
        self.get_branch_config('/a/c')
585
 
        self.assertEqual('/a/c', self.my_location_config._get_section())
586
 
 
 
607
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
 
608
                         self.my_location_config._get_matching_sections())
587
609
 
588
610
    def test_location_without_username(self):
589
 
        self.get_branch_config('http://www.example.com/useglobal')
 
611
        self.get_branch_config('http://www.example.com/ignoreparent')
590
612
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
591
613
                         self.my_config.username())
592
614
 
641
663
        self.get_branch_config('/a')
642
664
        self.assertEqual('local',
643
665
                         self.my_config.get_user_option('user_local_option'))
644
 
        
 
666
 
645
667
    def test_post_commit_default(self):
646
668
        self.get_branch_config('/a/c')
647
669
        self.assertEqual('bzrlib.tests.test_config.post_commit',
824
846
    def test_extract_email_address(self):
825
847
        self.assertEqual('jane@test.com',
826
848
                         config.extract_email_address('Jane <jane@test.com>'))
827
 
        self.assertRaises(errors.BzrError,
 
849
        self.assertRaises(errors.NoEmailInUsername,
828
850
                          config.extract_email_address, 'Jane Tester')