~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2010-11-24 16:01:57 UTC
  • mfrom: (4597.13.7 cleanup)
  • mto: This revision was merged to the branch mainline in revision 5558.
  • Revision ID: v.ladeuil+lp@free.fr-20101124160157-kieuslo7wj9abdmb
Merge cleanup into 638451-malformed

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import sys
22
22
import threading
23
23
 
 
24
 
 
25
from testtools import matchers
 
26
 
24
27
#import bzrlib specific imports here
25
28
from bzrlib import (
26
29
    branch,
125
128
"""
126
129
 
127
130
 
 
131
def create_configs(test):
 
132
    """Create configuration files for a given test.
 
133
 
 
134
    This requires creating a tree (and populate the ``test.tree`` attribute)
 
135
    and its associated branch and will populate the following attributes:
 
136
 
 
137
    - branch_config: A BranchConfig for the associated branch.
 
138
 
 
139
    - locations_config : A LocationConfig for the associated branch
 
140
 
 
141
    - bazaar_config: A GlobalConfig.
 
142
 
 
143
    The tree and branch are created in a 'tree' subdirectory so the tests can
 
144
    still use the test directory to stay outside of the branch.
 
145
    """
 
146
    tree = test.make_branch_and_tree('tree')
 
147
    test.tree = tree
 
148
    test.branch_config = config.BranchConfig(tree.branch)
 
149
    test.locations_config = config.LocationConfig(tree.basedir)
 
150
    test.bazaar_config = config.GlobalConfig()
 
151
 
 
152
 
 
153
def create_configs_with_file_option(test):
 
154
    """Create configuration files with a ``file`` option set in each.
 
155
 
 
156
    This builds on ``create_configs`` and add one ``file`` option in each
 
157
    configuration with a value which allows identifying the configuration file.
 
158
    """
 
159
    create_configs(test)
 
160
    test.bazaar_config.set_user_option('file', 'bazaar')
 
161
    test.locations_config.set_user_option('file', 'locations')
 
162
    test.branch_config.set_user_option('file', 'branch')
 
163
 
 
164
 
 
165
class TestOptionsMixin:
 
166
 
 
167
    def assertOptions(self, expected, conf):
 
168
        # We don't care about the parser (as it will make tests hard to write
 
169
        # and error-prone anyway)
 
170
        self.assertThat([opt[:4] for opt in conf._get_options()],
 
171
                        matchers.Equals(expected))
 
172
 
 
173
 
128
174
class InstrumentedConfigObj(object):
129
175
    """A config obj look-enough-alike to record calls made to it."""
130
176
 
902
948
        self.assertIs(None, new_config.get_alias('commit'))
903
949
 
904
950
 
905
 
class TestLocationConfig(tests.TestCaseInTempDir):
 
951
class TestLocationConfig(tests.TestCaseInTempDir, TestOptionsMixin):
906
952
 
907
953
    def test_constructs(self):
908
954
        my_config = config.LocationConfig('http://example.com')
1016
1062
            'http://www.example.com', 'appendpath_option'),
1017
1063
            config.POLICY_APPENDPATH)
1018
1064
 
 
1065
    def test__get_options_with_policy(self):
 
1066
        self.get_branch_config('/dir/subdir',
 
1067
                               location_config="""\
 
1068
[/dir]
 
1069
other_url = /other-dir
 
1070
other_url:policy = appendpath
 
1071
[/dir/subdir]
 
1072
other_url = /other-subdir
 
1073
""")
 
1074
        self.assertOptions(
 
1075
            [(u'other_url', u'/other-subdir', u'/dir/subdir', 'locations'),
 
1076
             (u'other_url', u'/other-dir', u'/dir', 'locations'),
 
1077
             (u'other_url:policy', u'appendpath', u'/dir', 'locations')],
 
1078
            self.my_location_config)
 
1079
 
1019
1080
    def test_location_without_username(self):
1020
1081
        self.get_branch_config('http://www.example.com/ignoreparent')
1021
1082
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
1157
1218
        self.assertEqual('bzrlib.tests.test_config.post_commit',
1158
1219
                         self.my_config.post_commit())
1159
1220
 
1160
 
    def get_branch_config(self, location, global_config=None):
 
1221
    def get_branch_config(self, location, global_config=None,
 
1222
                          location_config=None):
1161
1223
        my_branch = FakeBranch(location)
1162
1224
        if global_config is None:
1163
1225
            global_config = sample_config_text
 
1226
        if location_config is None:
 
1227
            location_config = sample_branches_text
1164
1228
 
1165
1229
        my_global_config = config.GlobalConfig.from_string(global_config,
1166
1230
                                                           save=True)
1167
1231
        my_location_config = config.LocationConfig.from_string(
1168
 
            sample_branches_text, my_branch.base, save=True)
 
1232
            location_config, my_branch.base, save=True)
1169
1233
        my_config = config.BranchConfig(my_branch)
1170
1234
        self.my_config = my_config
1171
1235
        self.my_location_config = my_config._get_location_config()
1467
1531
        self.assertIs(None, bzrdir_config.get_default_stack_on())
1468
1532
 
1469
1533
 
1470
 
def create_configs(test):
1471
 
    """Create configuration files for a given test.
1472
 
 
1473
 
    This requires creating a tree (and populate the ``test.tree`` attribute)
1474
 
    and its associated branch and will populate the following attributes:
1475
 
 
1476
 
    - branch_config: A BranchConfig for the associated branch.
1477
 
 
1478
 
    - locations_config : A LocationConfig for the associated branch
1479
 
 
1480
 
    - bazaar_config: A GlobalConfig.
1481
 
 
1482
 
    The tree and branch are created in a 'tree' subdirectory so the tests can
1483
 
    still use the test directory to stay outside of the branch.
1484
 
    """
1485
 
    tree = test.make_branch_and_tree('tree')
1486
 
    test.tree = tree
1487
 
    test.branch_config = config.BranchConfig(tree.branch)
1488
 
    test.locations_config = config.LocationConfig(tree.basedir)
1489
 
    test.bazaar_config = config.GlobalConfig()
1490
 
 
1491
 
 
1492
 
def create_configs_with_file_option(test):
1493
 
    """Create configuration files with a ``file`` option set in each.
1494
 
 
1495
 
    This builds on ``create_configs`` and add one ``file`` option in each
1496
 
    configuration with a value which allows identifying the configuration file.
1497
 
    """
1498
 
    create_configs(test)
1499
 
    test.bazaar_config.set_user_option('file', 'bazaar')
1500
 
    test.locations_config.set_user_option('file', 'locations')
1501
 
    test.branch_config.set_user_option('file', 'branch')
1502
 
 
1503
 
 
1504
 
class TestConfigGetOptions(tests.TestCaseWithTransport):
 
1534
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
1505
1535
 
1506
1536
    def setUp(self):
1507
1537
        super(TestConfigGetOptions, self).setUp()
1508
1538
        create_configs(self)
1509
1539
 
1510
 
    def assertOptions(self, expected, conf):
1511
 
        actual = list(conf._get_options())
1512
 
        self.assertEqual(expected, actual)
1513
 
 
1514
1540
    # One variable in none of the above
1515
1541
    def test_no_variable(self):
1516
1542
        # Using branch should query branch, locations and bazaar
1559
1585
            self.branch_config)
1560
1586
 
1561
1587
 
1562
 
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
1588
class TestConfigRemoveOption(tests.TestCaseWithTransport, TestOptionsMixin):
1563
1589
 
1564
1590
    def setUp(self):
1565
1591
        super(TestConfigRemoveOption, self).setUp()
1566
1592
        create_configs_with_file_option(self)
1567
1593
 
1568
 
    def assertOptions(self, expected, conf):
1569
 
        actual = list(conf._get_options())
1570
 
        self.assertEqual(expected, actual)
1571
 
 
1572
1594
    def test_remove_in_locations(self):
1573
1595
        self.locations_config.remove_user_option('file', self.tree.basedir)
1574
1596
        self.assertOptions(