517
518
change_editor.command_template)
520
class TestConfigPath(tests.TestCase):
523
super(TestConfigPath, self).setUp()
524
self.overrideEnv('HOME', '/home/bogus')
525
self.overrideEnv('XDG_CACHE_HOME', '')
526
if sys.platform == 'win32':
529
r'C:\Documents and Settings\bogus\Application Data')
531
'C:/Documents and Settings/bogus/Application Data/breezy'
533
self.brz_home = '/home/bogus/.config/breezy'
535
def test_config_dir(self):
536
self.assertEqual(config.config_dir(), self.brz_home)
538
def test_config_dir_is_unicode(self):
539
self.assertIsInstance(config.config_dir(), text_type)
541
def test_config_filename(self):
542
self.assertEqual(config.config_filename(),
543
self.brz_home + '/breezy.conf')
545
def test_locations_config_filename(self):
546
self.assertEqual(config.locations_config_filename(),
547
self.brz_home + '/locations.conf')
549
def test_authentication_config_filename(self):
550
self.assertEqual(config.authentication_config_filename(),
551
self.brz_home + '/authentication.conf')
554
class TestConfigPathFallback(tests.TestCaseInTempDir):
557
super(TestConfigPathFallback, self).setUp()
558
self.overrideEnv('HOME', self.test_dir)
559
self.overrideEnv('XDG_CACHE_HOME', '')
560
self.bzr_home = os.path.join(self.test_dir, '.bazaar')
561
os.mkdir(self.bzr_home)
563
def test_config_dir(self):
564
self.assertEqual(config.config_dir(), self.bzr_home)
566
def test_config_dir_is_unicode(self):
567
self.assertIsInstance(config.config_dir(), text_type)
569
def test_config_filename(self):
570
self.assertEqual(config.config_filename(),
571
self.bzr_home + '/bazaar.conf')
573
def test_locations_config_filename(self):
574
self.assertEqual(config.locations_config_filename(),
575
self.bzr_home + '/locations.conf')
577
def test_authentication_config_filename(self):
578
self.assertEqual(config.authentication_config_filename(),
579
self.bzr_home + '/authentication.conf')
582
class TestXDGConfigDir(tests.TestCaseInTempDir):
583
# must be in temp dir because config tests for the existence of the bazaar
584
# subdirectory of $XDG_CONFIG_HOME
587
if sys.platform == 'win32':
588
raise tests.TestNotApplicable(
589
'XDG config dir not used on this platform')
590
super(TestXDGConfigDir, self).setUp()
591
self.overrideEnv('HOME', self.test_home_dir)
592
# BRZ_HOME overrides everything we want to test so unset it.
593
self.overrideEnv('BRZ_HOME', None)
595
def test_xdg_config_dir_exists(self):
596
"""When ~/.config/bazaar exists, use it as the config dir."""
597
newdir = osutils.pathjoin(self.test_home_dir, '.config', 'bazaar')
599
self.assertEqual(config.config_dir(), newdir)
601
def test_xdg_config_home(self):
602
"""When XDG_CONFIG_HOME is set, use it."""
603
xdgconfigdir = osutils.pathjoin(self.test_home_dir, 'xdgconfig')
604
self.overrideEnv('XDG_CONFIG_HOME', xdgconfigdir)
605
newdir = osutils.pathjoin(xdgconfigdir, 'bazaar')
607
self.assertEqual(config.config_dir(), newdir)
610
521
class TestIniConfig(tests.TestCaseInTempDir):
612
523
def make_config_parser(self, s):
4714
class TestAutoUserId(tests.TestCase):
4715
"""Test inferring an automatic user name."""
4717
def test_auto_user_id(self):
4718
"""Automatic inference of user name.
4720
This is a bit hard to test in an isolated way, because it depends on
4721
system functions that go direct to /etc or perhaps somewhere else.
4722
But it's reasonable to say that on Unix, with an /etc/mailname, we ought
4723
to be able to choose a user name with no configuration.
4725
if sys.platform == 'win32':
4726
raise tests.TestSkipped(
4727
"User name inference not implemented on win32")
4728
realname, address = config._auto_user_id()
4729
if os.path.exists('/etc/mailname'):
4730
self.assertIsNot(None, realname)
4731
self.assertIsNot(None, address)
4733
self.assertEqual((None, None), (realname, address))
4736
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4737
"""Test retrieving default domain from mailname file"""
4739
def test_default_mail_domain_simple(self):
4740
with open('simple', 'w') as f:
4741
f.write("domainname.com\n")
4742
r = config._get_default_mail_domain('simple')
4743
self.assertEqual('domainname.com', r)
4745
def test_default_mail_domain_no_eol(self):
4746
with open('no_eol', 'w') as f:
4747
f.write("domainname.com")
4748
r = config._get_default_mail_domain('no_eol')
4749
self.assertEqual('domainname.com', r)
4751
def test_default_mail_domain_multiple_lines(self):
4752
with open('multiple_lines', 'w') as f:
4753
f.write("domainname.com\nsome other text\n")
4754
r = config._get_default_mail_domain('multiple_lines')
4755
self.assertEqual('domainname.com', r)
4758
4625
class EmailOptionTests(tests.TestCase):
4760
4627
def test_default_email_uses_BRZ_EMAIL(self):