/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-16 02:23:42 UTC
  • mfrom: (7340 work)
  • mto: This revision was merged to the branch mainline in revision 7350.
  • Revision ID: jelmer@jelmer.uk-20190616022342-ihxzayq04x5culzd
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from .. import (
28
28
    branch,
29
29
    config,
 
30
    bedding,
30
31
    controldir,
31
32
    diff,
32
33
    errors,
517
518
                         change_editor.command_template)
518
519
 
519
520
 
520
 
class TestConfigPath(tests.TestCase):
521
 
 
522
 
    def setUp(self):
523
 
        super(TestConfigPath, self).setUp()
524
 
        self.overrideEnv('HOME', '/home/bogus')
525
 
        self.overrideEnv('XDG_CACHE_HOME', '')
526
 
        if sys.platform == 'win32':
527
 
            self.overrideEnv(
528
 
                'BRZ_HOME',
529
 
                r'C:\Documents and Settings\bogus\Application Data')
530
 
            self.brz_home = \
531
 
                'C:/Documents and Settings/bogus/Application Data/breezy'
532
 
        else:
533
 
            self.brz_home = '/home/bogus/.config/breezy'
534
 
 
535
 
    def test_config_dir(self):
536
 
        self.assertEqual(config.config_dir(), self.brz_home)
537
 
 
538
 
    def test_config_dir_is_unicode(self):
539
 
        self.assertIsInstance(config.config_dir(), text_type)
540
 
 
541
 
    def test_config_filename(self):
542
 
        self.assertEqual(config.config_filename(),
543
 
                         self.brz_home + '/breezy.conf')
544
 
 
545
 
    def test_locations_config_filename(self):
546
 
        self.assertEqual(config.locations_config_filename(),
547
 
                         self.brz_home + '/locations.conf')
548
 
 
549
 
    def test_authentication_config_filename(self):
550
 
        self.assertEqual(config.authentication_config_filename(),
551
 
                         self.brz_home + '/authentication.conf')
552
 
 
553
 
    def test_xdg_cache_dir(self):
554
 
        self.assertEqual(config.xdg_cache_dir(),
555
 
                         '/home/bogus/.cache')
556
 
 
557
 
 
558
 
class TestConfigPathFallback(tests.TestCaseInTempDir):
559
 
 
560
 
    def setUp(self):
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)
566
 
 
567
 
    def test_config_dir(self):
568
 
        self.assertEqual(config.config_dir(), self.bzr_home)
569
 
 
570
 
    def test_config_dir_is_unicode(self):
571
 
        self.assertIsInstance(config.config_dir(), text_type)
572
 
 
573
 
    def test_config_filename(self):
574
 
        self.assertEqual(config.config_filename(),
575
 
                         self.bzr_home + '/bazaar.conf')
576
 
 
577
 
    def test_locations_config_filename(self):
578
 
        self.assertEqual(config.locations_config_filename(),
579
 
                         self.bzr_home + '/locations.conf')
580
 
 
581
 
    def test_authentication_config_filename(self):
582
 
        self.assertEqual(config.authentication_config_filename(),
583
 
                         self.bzr_home + '/authentication.conf')
584
 
 
585
 
    def test_xdg_cache_dir(self):
586
 
        self.assertEqual(config.xdg_cache_dir(),
587
 
                         os.path.join(self.test_dir, '.cache'))
588
 
 
589
 
 
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
593
 
 
594
 
    def setUp(self):
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)
602
 
 
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')
606
 
        os.makedirs(newdir)
607
 
        self.assertEqual(config.config_dir(), newdir)
608
 
 
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')
614
 
        os.makedirs(newdir)
615
 
        self.assertEqual(config.config_dir(), newdir)
616
 
 
617
 
 
618
521
class TestIniConfig(tests.TestCaseInTempDir):
619
522
 
620
523
    def make_config_parser(self, s):
1022
925
        finally:
1023
926
            config.ConfigObj = oldparserclass
1024
927
        self.assertIsInstance(parser, InstrumentedConfigObj)
1025
 
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
 
928
        self.assertEqual(parser._calls, [('__init__', bedding.config_path(),
1026
929
                                          'utf-8')])
1027
930
 
1028
931
 
1092
995
        branch.set_push_location('http://foobar')
1093
996
        local_path = osutils.getcwd().encode('utf8')
1094
997
        # Surprisingly ConfigObj doesn't create a trailing newline
1095
 
        self.check_file_contents(config.locations_config_filename(),
 
998
        self.check_file_contents(bedding.locations_config_path(),
1096
999
                                 b'[%s/branch]\n'
1097
1000
                                 b'push_location = http://foobar\n'
1098
1001
                                 b'push_location:policy = norecurse\n'
1287
1190
            config.ConfigObj = oldparserclass
1288
1191
        self.assertIsInstance(parser, InstrumentedConfigObj)
1289
1192
        self.assertEqual(parser._calls,
1290
 
                         [('__init__', config.locations_config_filename(),
 
1193
                         [('__init__', bedding.locations_config_path(),
1291
1194
                           'utf-8')])
1292
1195
 
1293
1196
    def test_get_global_config(self):
4204
4107
user=joe
4205
4108
port=port # Error: Not an int
4206
4109
""")
4207
 
        self.overrideAttr(config, 'authentication_config_filename',
 
4110
        self.overrideAttr(bedding, 'authentication_config_path',
4208
4111
                          lambda: self.path)
4209
4112
        osutils.chmod_if_possible(self.path, 0o755)
4210
4113
 
4719
4622
    pass
4720
4623
 
4721
4624
 
4722
 
class TestAutoUserId(tests.TestCase):
4723
 
    """Test inferring an automatic user name."""
4724
 
 
4725
 
    def test_auto_user_id(self):
4726
 
        """Automatic inference of user name.
4727
 
 
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.
4732
 
        """
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)
4740
 
        else:
4741
 
            self.assertEqual((None, None), (realname, address))
4742
 
 
4743
 
 
4744
 
class TestDefaultMailDomain(tests.TestCaseInTempDir):
4745
 
    """Test retrieving default domain from mailname file"""
4746
 
 
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)
4752
 
 
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)
4758
 
 
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)
4764
 
 
4765
 
 
4766
4625
class EmailOptionTests(tests.TestCase):
4767
4626
 
4768
4627
    def test_default_email_uses_BRZ_EMAIL(self):