513
512
change_editor = my_config.get_change_editor('old_tree', 'new_tree')
514
513
self.assertEqual(['_get_change_editor'], my_config._calls)
515
514
self.assertIs(diff.DiffFromTool, change_editor.__class__)
516
self.assertEqual(['vimdiff', '-fo', '@new_path', '@old_path'],
517
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')
553
def test_xdg_cache_dir(self):
554
self.assertEqual(config.xdg_cache_dir(),
555
'/home/bogus/.cache')
558
class TestConfigPathFallback(tests.TestCaseInTempDir):
561
super(TestConfigPathFallback, self).setUp()
562
self.overrideEnv('HOME', self.test_dir)
563
self.overrideEnv('XDG_CACHE_HOME', '')
564
self.bzr_home = os.path.join(self.test_dir, '.bazaar')
565
os.mkdir(self.bzr_home)
567
def test_config_dir(self):
568
self.assertEqual(config.config_dir(), self.bzr_home)
570
def test_config_dir_is_unicode(self):
571
self.assertIsInstance(config.config_dir(), text_type)
573
def test_config_filename(self):
574
self.assertEqual(config.config_filename(),
575
self.bzr_home + '/bazaar.conf')
577
def test_locations_config_filename(self):
578
self.assertEqual(config.locations_config_filename(),
579
self.bzr_home + '/locations.conf')
581
def test_authentication_config_filename(self):
582
self.assertEqual(config.authentication_config_filename(),
583
self.bzr_home + '/authentication.conf')
585
def test_xdg_cache_dir(self):
586
self.assertEqual(config.xdg_cache_dir(),
587
os.path.join(self.test_dir, '.cache'))
590
class TestXDGConfigDir(tests.TestCaseInTempDir):
591
# must be in temp dir because config tests for the existence of the bazaar
592
# subdirectory of $XDG_CONFIG_HOME
595
if sys.platform == 'win32':
596
raise tests.TestNotApplicable(
597
'XDG config dir not used on this platform')
598
super(TestXDGConfigDir, self).setUp()
599
self.overrideEnv('HOME', self.test_home_dir)
600
# BRZ_HOME overrides everything we want to test so unset it.
601
self.overrideEnv('BRZ_HOME', None)
603
def test_xdg_config_dir_exists(self):
604
"""When ~/.config/bazaar exists, use it as the config dir."""
605
newdir = osutils.pathjoin(self.test_home_dir, '.config', 'bazaar')
607
self.assertEqual(config.config_dir(), newdir)
609
def test_xdg_config_home(self):
610
"""When XDG_CONFIG_HOME is set, use it."""
611
xdgconfigdir = osutils.pathjoin(self.test_home_dir, 'xdgconfig')
612
self.overrideEnv('XDG_CONFIG_HOME', xdgconfigdir)
613
newdir = osutils.pathjoin(xdgconfigdir, 'bazaar')
615
self.assertEqual(config.config_dir(), newdir)
515
self.assertEqual(['vimdiff', '-fo', '{new_path}', '{old_path}'],
516
change_editor.command_template)
518
def test_get_change_editor_implicit_args(self):
519
# If there are no substitution variables, then assume the
520
# old and new path are the last arguments.
521
my_config = InstrumentedConfig()
522
my_config._change_editor = 'vimdiff -o'
523
change_editor = my_config.get_change_editor('old_tree', 'new_tree')
524
self.assertEqual(['_get_change_editor'], my_config._calls)
525
self.assertIs(diff.DiffFromTool, change_editor.__class__)
526
self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
527
change_editor.command_template)
529
def test_get_change_editor_old_style(self):
530
# Test the old style format for the change_editor setting.
531
my_config = InstrumentedConfig()
532
my_config._change_editor = 'vimdiff -o @old_path @new_path'
533
change_editor = my_config.get_change_editor('old_tree', 'new_tree')
534
self.assertEqual(['_get_change_editor'], my_config._calls)
535
self.assertIs(diff.DiffFromTool, change_editor.__class__)
536
self.assertEqual(['vimdiff', '-o', '{old_path}', '{new_path}'],
537
change_editor.command_template)
618
540
class TestIniConfig(tests.TestCaseInTempDir):
4722
class TestAutoUserId(tests.TestCase):
4723
"""Test inferring an automatic user name."""
4725
def test_auto_user_id(self):
4726
"""Automatic inference of user name.
4728
This is a bit hard to test in an isolated way, because it depends on
4729
system functions that go direct to /etc or perhaps somewhere else.
4730
But it's reasonable to say that on Unix, with an /etc/mailname, we ought
4731
to be able to choose a user name with no configuration.
4733
if sys.platform == 'win32':
4734
raise tests.TestSkipped(
4735
"User name inference not implemented on win32")
4736
realname, address = config._auto_user_id()
4737
if os.path.exists('/etc/mailname'):
4738
self.assertIsNot(None, realname)
4739
self.assertIsNot(None, address)
4741
self.assertEqual((None, None), (realname, address))
4744
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4745
"""Test retrieving default domain from mailname file"""
4747
def test_default_mail_domain_simple(self):
4748
with open('simple', 'w') as f:
4749
f.write("domainname.com\n")
4750
r = config._get_default_mail_domain('simple')
4751
self.assertEqual('domainname.com', r)
4753
def test_default_mail_domain_no_eol(self):
4754
with open('no_eol', 'w') as f:
4755
f.write("domainname.com")
4756
r = config._get_default_mail_domain('no_eol')
4757
self.assertEqual('domainname.com', r)
4759
def test_default_mail_domain_multiple_lines(self):
4760
with open('multiple_lines', 'w') as f:
4761
f.write("domainname.com\nsome other text\n")
4762
r = config._get_default_mail_domain('multiple_lines')
4763
self.assertEqual('domainname.com', r)
4766
4651
class EmailOptionTests(tests.TestCase):
4768
4653
def test_default_email_uses_BRZ_EMAIL(self):
4769
4654
conf = config.MemoryStack(b'email=jelmer@debian.org')
4770
# BRZ_EMAIL takes precedence over EMAIL
4655
# BRZ_EMAIL takes precedence over BZR_EMAIL and EMAIL
4771
4656
self.overrideEnv('BRZ_EMAIL', 'jelmer@samba.org')
4657
self.overrideEnv('BZR_EMAIL', 'jelmer@jelmer.uk')
4658
self.overrideEnv('EMAIL', 'jelmer@apache.org')
4659
self.assertEqual('jelmer@samba.org', conf.get('email'))
4661
def test_default_email_uses_BZR_EMAIL(self):
4662
conf = config.MemoryStack(b'email=jelmer@debian.org')
4663
# BZR_EMAIL takes precedence over EMAIL
4664
self.overrideEnv('BZR_EMAIL', 'jelmer@samba.org')
4772
4665
self.overrideEnv('EMAIL', 'jelmer@apache.org')
4773
4666
self.assertEqual('jelmer@samba.org', conf.get('email'))