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
31
31
sample_config_text = ("[DEFAULT]\n"
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'
187
190
def tearDown(self):
188
os.environ['HOME'] = self.oldenv
191
if self.old_home is None:
192
del os.environ['HOME']
194
os.environ['HOME'] = self.old_home
195
if self.old_appdata is None:
196
del os.environ['APPDATA']
198
os.environ['APPDATA'] = self.old_appdata
189
199
super(TestConfigPath, self).tearDown()
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')
206
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
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')
213
self.assertEqual(config.config_filename(),
214
'/home/bogus/.bazaar/bazaar.conf')
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')
221
self.assertEqual(config.branches_config_filename(),
222
'/home/bogus/.bazaar/branches.conf')
202
224
class TestIniConfig(TestCase):
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())
503
class TestLocationConfig(TestCaseInTempDir):
505
def get_location_config(self, location, global_config=None):
506
if global_config is None:
507
global_file = StringIO(sample_config_text)
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)
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")
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())
600
class TestMailAddressExtraction(TestCase):
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')