25
25
#import bzrlib specific imports here
26
import bzrlib.config as config
27
32
from bzrlib.branch import Branch
28
33
from bzrlib.bzrdir import BzrDir
29
import bzrlib.errors as errors
30
34
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
355
359
self.assertTrue(b.get_config().has_explicit_nickname())
361
def test_config_url(self):
362
"""The Branch.get_config will use section that uses a local url"""
363
branch = self.make_branch('branch')
364
self.assertEqual('branch', branch.nick)
366
locations = config.locations_config_filename()
367
config.ensure_config_dir_exists()
368
local_url = urlutils.local_path_to_url('branch')
369
open(locations, 'wb').write('[%s]\nnickname = foobar'
371
self.assertEqual('foobar', branch.nick)
373
def test_config_local_path(self):
374
"""The Branch.get_config will use a local system path"""
375
branch = self.make_branch('branch')
376
self.assertEqual('branch', branch.nick)
378
locations = config.locations_config_filename()
379
config.ensure_config_dir_exists()
380
open(locations, 'wb').write('[%s/branch]\nnickname = barry'
381
% (osutils.getcwd().encode('utf8'),))
382
self.assertEqual('barry', branch.nick)
384
def test_config_creates_local(self):
385
"""Creating a new entry in config uses a local path."""
386
branch = self.make_branch('branch')
387
branch.set_push_location('http://foobar')
388
locations = config.locations_config_filename()
389
local_path = osutils.getcwd().encode('utf8')
390
# Surprisingly ConfigObj doesn't create a trailing newline
391
self.check_file_contents(locations,
392
'[%s/branch]\npush_location = http://foobar' % (local_path,))
358
395
class TestGlobalConfigItems(TestCase):
713
750
my_config.branch.control_files.email = "John"
714
751
self.assertEqual("John", my_config._get_user_id())
716
def test_BZREMAIL_OVERRIDES(self):
717
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>"
753
def test_BZR_EMAIL_OVERRIDES(self):
754
os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
718
755
branch = FakeBranch()
719
756
my_config = config.BranchConfig(branch)
720
757
self.assertEqual("Robert Collins <robertc@example.org>",
787
824
def test_extract_email_address(self):
788
825
self.assertEqual('jane@test.com',
789
826
config.extract_email_address('Jane <jane@test.com>'))
790
self.assertRaises(errors.BzrError,
827
self.assertRaises(errors.NoEmailInUsername,
791
828
config.extract_email_address, 'Jane Tester')