~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

[merge] up-to-date against bzr.dev

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
 
175
175
 
176
176
    def setUp(self):
177
177
        super(TestConfigPath, self).setUp()
178
 
        self.oldenv = os.environ.get('HOME', None)
 
178
        self.old_home = os.environ.get('HOME', None)
 
179
        self.old_appdata = os.environ.get('APPDATA', None)
179
180
        os.environ['HOME'] = '/home/bogus'
 
181
        os.environ['APPDATA'] = \
 
182
            r'C:\Documents and Settings\bogus\Application Data'
180
183
 
181
184
    def tearDown(self):
182
 
        os.environ['HOME'] = self.oldenv
 
185
        if self.old_home is None:
 
186
            del os.environ['HOME']
 
187
        else:
 
188
            os.environ['HOME'] = self.old_home
 
189
        if self.old_appdata is None:
 
190
            del os.environ['APPDATA']
 
191
        else:
 
192
            os.environ['APPDATA'] = self.old_appdata
183
193
        super(TestConfigPath, self).tearDown()
184
194
    
185
195
    def test_config_dir(self):
186
 
        self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
 
196
        if sys.platform == 'win32':
 
197
            self.assertEqual(config.config_dir(), 
 
198
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0')
 
199
        else:
 
200
            self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
187
201
 
188
202
    def test_config_filename(self):
189
 
        self.assertEqual(config.config_filename(),
190
 
                         '/home/bogus/.bazaar/bazaar.conf')
 
203
        if sys.platform == 'win32':
 
204
            self.assertEqual(config.config_filename(), 
 
205
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\bazaar.conf')
 
206
        else:
 
207
            self.assertEqual(config.config_filename(),
 
208
                             '/home/bogus/.bazaar/bazaar.conf')
191
209
 
192
210
    def test_branches_config_filename(self):
193
 
        self.assertEqual(config.branches_config_filename(),
194
 
                         '/home/bogus/.bazaar/branches.conf')
 
211
        if sys.platform == 'win32':
 
212
            self.assertEqual(config.branches_config_filename(), 
 
213
                r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\branches.conf')
 
214
        else:
 
215
            self.assertEqual(config.branches_config_filename(),
 
216
                             '/home/bogus/.bazaar/branches.conf')
195
217
 
196
218
class TestIniConfig(TestCase):
197
219
 
468
490
        
469
491
    def test_post_commit_default(self):
470
492
        self.get_location_config('/a/c')
471
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
493
        self.assertEqual('bzrlib.tests.test_config.post_commit',
472
494
                         self.my_config.post_commit())
473
495
 
474
496
 
566
588
            _get_global_config()._get_parser(config_file))
567
589
        branch_file = StringIO(sample_branches_text)
568
590
        my_config._get_location_config()._get_parser(branch_file)
569
 
        self.assertEqual('bzrlib.selftest.testconfig.post_commit',
 
591
        self.assertEqual('bzrlib.tests.test_config.post_commit',
570
592
                         my_config.post_commit())
 
593
 
 
594
 
 
595
class TestMailAddressExtraction(TestCase):
 
596
 
 
597
    def test_extract_email_address(self):
 
598
        self.assertEqual('jane@test.com',
 
599
                         config.extract_email_address('Jane <jane@test.com>'))
 
600
        self.assertRaises(errors.BzrError,
 
601
                          config.extract_email_address, 'Jane Tester')