~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#import bzrlib specific imports here
26
26
import bzrlib.config as config
27
27
import bzrlib.errors as errors
28
 
from bzrlib.selftest import TestCase, TestCaseInTempDir
 
28
from bzrlib.tests import TestCase, TestCaseInTempDir
29
29
 
30
30
 
31
31
sample_config_text = ("[DEFAULT]\n"
66
66
                        "recurse=False\n"
67
67
                        "[/a/c]\n"
68
68
                        "check_signatures=ignore\n"
69
 
                        "post_commit=bzrlib.selftest.testconfig.post_commit\n"
 
69
                        "post_commit=bzrlib.tests.test_config.post_commit\n"
70
70
                        "#testing explicit beats globs\n")
71
71
 
72
72
 
181
181
 
182
182
    def setUp(self):
183
183
        super(TestConfigPath, self).setUp()
184
 
        self.oldenv = os.environ.get('HOME', None)
 
184
        self.old_home = os.environ.get('HOME', None)
 
185
        self.old_appdata = os.environ.get('APPDATA', None)
185
186
        os.environ['HOME'] = '/home/bogus'
 
187
        os.environ['APPDATA'] = \
 
188
            r'C:\Documents and Settings\bogus\Application Data'
186
189
 
187
190
    def tearDown(self):
188
 
        os.environ['HOME'] = self.oldenv
 
191
        if self.old_home is None:
 
192
            del os.environ['HOME']
 
193
        else:
 
194
            os.environ['HOME'] = self.old_home
 
195
        if self.old_appdata is None:
 
196
            del os.environ['APPDATA']
 
197
        else:
 
198
            os.environ['APPDATA'] = self.old_appdata
189
199
        super(TestConfigPath, self).tearDown()
190
200
    
191
201
    def test_config_dir(self):
192
 
        self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
 
202
        if sys.platform == 'win32':
 
203
            self.assertEqual(config.config_dir(), 
 
204
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0')
 
205
        else:
 
206
            self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
193
207
 
194
208
    def test_config_filename(self):
195
 
        self.assertEqual(config.config_filename(),
196
 
                         '/home/bogus/.bazaar/bazaar.conf')
 
209
        if sys.platform == 'win32':
 
210
            self.assertEqual(config.config_filename(), 
 
211
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\bazaar.conf')
 
212
        else:
 
213
            self.assertEqual(config.config_filename(),
 
214
                             '/home/bogus/.bazaar/bazaar.conf')
197
215
 
198
216
    def test_branches_config_filename(self):
199
 
        self.assertEqual(config.branches_config_filename(),
200
 
                         '/home/bogus/.bazaar/branches.conf')
 
217
        if sys.platform == 'win32':
 
218
            self.assertEqual(config.branches_config_filename(), 
 
219
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\branches.conf')
 
220
        else:
 
221
            self.assertEqual(config.branches_config_filename(),
 
222
                             '/home/bogus/.bazaar/branches.conf')
201
223
 
202
224
class TestIniConfig(TestCase):
203
225
 
331
353
        self.assertEqual(None, my_config.post_commit())
332
354
 
333
355
 
334
 
 
335
356
class TestLocationConfig(TestCase):
336
357
 
337
358
    def test_constructs(self):
475
496
        
476
497
    def test_post_commit_default(self):
477
498
        self.get_location_config('/a/c')
478
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
499
        self.assertEqual('bzrlib.tests.test_config.post_commit',
479
500
                         self.my_config.post_commit())
480
501
 
 
502
 
 
503
class TestLocationConfig(TestCaseInTempDir):
 
504
 
 
505
    def get_location_config(self, location, global_config=None):
 
506
        if global_config is None:
 
507
            global_file = StringIO(sample_config_text)
 
508
        else:
 
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)
 
513
        self.my_config._get_global_config()._get_parser(global_file)
 
514
 
481
515
    def test_set_user_setting_sets_and_saves(self):
482
516
        # TODO RBC 20051029 test hat mkdir ~/.bazaar is called ..
483
517
        self.get_location_config('/a/c')
484
518
        record = InstrumentedConfigObj("foo")
485
519
        self.my_config._parser = record
 
520
        print ("test_set_user_setting_sets_and_saves broken: creates .bazaar "
 
521
               "in the top-level directory, not inside the test directory")
 
522
        return
486
523
        self.my_config.set_user_option('foo', 'bar')
487
524
        self.assertEqual([('__contains__', '/a/c'),
488
525
                          ('__contains__', '/a/c/'),
556
593
            _get_global_config()._get_parser(config_file))
557
594
        branch_file = StringIO(sample_branches_text)
558
595
        my_config._get_location_config()._get_parser(branch_file)
559
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
596
        self.assertEqual('bzrlib.tests.test_config.post_commit',
560
597
                         my_config.post_commit())
 
598
 
 
599
 
 
600
class TestMailAddressExtraction(TestCase):
 
601
 
 
602
    def test_extract_email_address(self):
 
603
        self.assertEqual('jane@test.com',
 
604
                         config.extract_email_address('Jane <jane@test.com>'))
 
605
        self.assertRaises(errors.BzrError,
 
606
                          config.extract_email_address, 'Jane Tester')