/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for finding and reading the bzr config file[s]."""
18
18
 
19
19
from textwrap import dedent
 
20
from io import BytesIO
20
21
import os
21
22
import sys
22
23
import threading
27
28
from .. import (
28
29
    branch,
29
30
    config,
 
31
    bedding,
30
32
    controldir,
31
33
    diff,
32
34
    errors,
42
44
from ..bzr import (
43
45
    remote,
44
46
    )
45
 
from ..sixish import (
46
 
    BytesIO,
47
 
    text_type,
48
 
    )
49
47
from ..transport import remote as transport_remote
50
48
from . import (
51
49
    features,
190
188
[DEFAULT]
191
189
email=Erik B\u00e5gfors <erik@bagfors.nu>
192
190
editor=vim
193
 
change_editor=vimdiff -of @new_path @old_path
 
191
change_editor=vimdiff -of {new_path} {old_path}
194
192
gpg_signing_key=DD4D5088
195
193
log_format=short
196
194
validate_signatures_in_log=true
394
392
        super(InstrumentedConfig, self).__init__()
395
393
        self._calls = []
396
394
        self._signatures = config.CHECK_NEVER
 
395
        self._change_editor = 'vimdiff -fo {new_path} {old_path}'
397
396
 
398
397
    def _get_user_id(self):
399
398
        self._calls.append('_get_user_id')
405
404
 
406
405
    def _get_change_editor(self):
407
406
        self._calls.append('_get_change_editor')
408
 
        return 'vimdiff -fo @new_path @old_path'
 
407
        return self._change_editor
409
408
 
410
409
 
411
410
bool_config = b"""[DEFAULT]
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)
518
 
 
519
 
 
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)
 
515
        self.assertEqual(['vimdiff', '-fo', '{new_path}', '{old_path}'],
 
516
                         change_editor.command_template)
 
517
 
 
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)
 
528
 
 
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)
616
538
 
617
539
 
618
540
class TestIniConfig(tests.TestCaseInTempDir):
1022
944
        finally:
1023
945
            config.ConfigObj = oldparserclass
1024
946
        self.assertIsInstance(parser, InstrumentedConfigObj)
1025
 
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
 
947
        self.assertEqual(parser._calls, [('__init__', bedding.config_path(),
1026
948
                                          'utf-8')])
1027
949
 
1028
950
 
1092
1014
        branch.set_push_location('http://foobar')
1093
1015
        local_path = osutils.getcwd().encode('utf8')
1094
1016
        # Surprisingly ConfigObj doesn't create a trailing newline
1095
 
        self.check_file_contents(config.locations_config_filename(),
 
1017
        self.check_file_contents(bedding.locations_config_path(),
1096
1018
                                 b'[%s/branch]\n'
1097
1019
                                 b'push_location = http://foobar\n'
1098
1020
                                 b'push_location:policy = norecurse\n'
1198
1120
        my_config = self._get_sample_config()
1199
1121
        change_editor = my_config.get_change_editor('old', 'new')
1200
1122
        self.assertIs(diff.DiffFromTool, change_editor.__class__)
1201
 
        self.assertEqual('vimdiff -of @new_path @old_path',
 
1123
        self.assertEqual('vimdiff -of {new_path} {old_path}',
1202
1124
                         ' '.join(change_editor.command_template))
1203
1125
 
1204
1126
    def test_get_no_change_editor(self):
1287
1209
            config.ConfigObj = oldparserclass
1288
1210
        self.assertIsInstance(parser, InstrumentedConfigObj)
1289
1211
        self.assertEqual(parser._calls,
1290
 
                         [('__init__', config.locations_config_filename(),
 
1212
                         [('__init__', bedding.locations_config_path(),
1291
1213
                           'utf-8')])
1292
1214
 
1293
1215
    def test_get_global_config(self):
1559
1481
        self.assertEqual("Robert Collins <robertc@example.org>",
1560
1482
                         my_config.username())
1561
1483
 
 
1484
    def test_BRZ_EMAIL_OVERRIDES(self):
 
1485
        self.overrideEnv('BZR_EMAIL', "Robert Collins <robertc@example.org>")
 
1486
        branch = FakeBranch()
 
1487
        my_config = config.BranchConfig(branch)
 
1488
        self.assertEqual("Robert Collins <robertc@example.org>",
 
1489
                         my_config.username())
 
1490
 
1562
1491
    def test_get_user_option_global(self):
1563
1492
        my_config = self.get_branch_config(global_config=sample_config_text)
1564
1493
        self.assertEqual('something',
2419
2348
        self.assertEqual('y', section.get('x'))
2420
2349
 
2421
2350
    def test_wrong_syntax(self):
2422
 
        self.assertRaises(errors.BzrCommandError,
 
2351
        self.assertRaises(errors.CommandError,
2423
2352
                          self.store._from_cmdline, ['a=b', 'c'])
2424
2353
 
2425
2354
 
4204
4133
user=joe
4205
4134
port=port # Error: Not an int
4206
4135
""")
4207
 
        self.overrideAttr(config, 'authentication_config_filename',
 
4136
        self.overrideAttr(bedding, 'authentication_config_path',
4208
4137
                          lambda: self.path)
4209
4138
        osutils.chmod_if_possible(self.path, 0o755)
4210
4139
 
4719
4648
    pass
4720
4649
 
4721
4650
 
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
4651
class EmailOptionTests(tests.TestCase):
4767
4652
 
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'))
 
4660
 
 
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'))
4774
4667