~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
 
102
102
            raise NotImplementedError
103
103
        if self.email is not None:
104
104
            return StringIO(self.email)
105
 
        raise errors.NoSuchFile
 
105
        raise errors.NoSuchFile(filename)
106
106
 
107
107
 
108
108
class InstrumentedConfig(config.Config):
195
195
    def test_config_dir(self):
196
196
        if sys.platform == 'win32':
197
197
            self.assertEqual(config.config_dir(), 
198
 
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0')
 
198
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0')
199
199
        else:
200
200
            self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
201
201
 
202
202
    def test_config_filename(self):
203
203
        if sys.platform == 'win32':
204
204
            self.assertEqual(config.config_filename(), 
205
 
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\bazaar.conf')
 
205
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/bazaar.conf')
206
206
        else:
207
207
            self.assertEqual(config.config_filename(),
208
208
                             '/home/bogus/.bazaar/bazaar.conf')
210
210
    def test_branches_config_filename(self):
211
211
        if sys.platform == 'win32':
212
212
            self.assertEqual(config.branches_config_filename(), 
213
 
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\branches.conf')
 
213
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/branches.conf')
214
214
        else:
215
215
            self.assertEqual(config.branches_config_filename(),
216
216
                             '/home/bogus/.bazaar/branches.conf')
490
490
        
491
491
    def test_post_commit_default(self):
492
492
        self.get_location_config('/a/c')
493
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
493
        self.assertEqual('bzrlib.tests.test_config.post_commit',
494
494
                         self.my_config.post_commit())
495
495
 
496
496
 
507
507
        self.my_config._get_global_config()._get_parser(global_file)
508
508
 
509
509
    def test_set_user_setting_sets_and_saves(self):
510
 
        # TODO RBC 20051029 test hat mkdir ~/.bazaar is called ..
511
510
        self.get_location_config('/a/c')
512
511
        record = InstrumentedConfigObj("foo")
513
512
        self.my_config._parser = record
514
 
        return
515
 
        # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
516
 
        # broken: creates .bazaar in the top-level directory, not 
517
 
        # inside the test directory
518
 
        self.my_config.set_user_option('foo', 'bar')
 
513
 
 
514
        real_mkdir = os.mkdir
 
515
        self.created = False
 
516
        def checked_mkdir(path, mode=0777):
 
517
            self.log('making directory: %s', path)
 
518
            real_mkdir(path, mode)
 
519
            self.created = True
 
520
 
 
521
        os.mkdir = checked_mkdir
 
522
        try:
 
523
            self.my_config.set_user_option('foo', 'bar')
 
524
        finally:
 
525
            os.mkdir = real_mkdir
 
526
 
 
527
        self.failUnless(self.created, 'Failed to create ~/.bazaar')
519
528
        self.assertEqual([('__contains__', '/a/c'),
520
529
                          ('__contains__', '/a/c/'),
521
530
                          ('__setitem__', '/a/c', {}),
588
597
            _get_global_config()._get_parser(config_file))
589
598
        branch_file = StringIO(sample_branches_text)
590
599
        my_config._get_location_config()._get_parser(branch_file)
591
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
600
        self.assertEqual('bzrlib.tests.test_config.post_commit',
592
601
                         my_config.post_commit())
593
602
 
594
603