~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Andrew Bennetts
  • Date: 2011-02-07 04:14:29 UTC
  • mfrom: (5535.4.26 fetch-all-tags-309682)
  • mto: This revision was merged to the branch mainline in revision 5648.
  • Revision ID: andrew.bennetts@canonical.com-20110207041429-3kc1blj34rvvxod9
Merge fetch-all-tags-309682.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
33
    errors,
34
34
    osutils,
35
35
    mail_client,
 
36
    mergetools,
36
37
    ui,
37
38
    urlutils,
38
39
    tests,
70
71
gpg_signing_command=gnome-gpg
71
72
log_format=short
72
73
user_global_option=something
 
74
bzr.mergetool.sometool=sometool {base} {this} {other} -o {result}
 
75
bzr.mergetool.funkytool=funkytool "arg with spaces" {this_temp}
 
76
bzr.default_mergetool=sometool
73
77
[ALIASES]
74
78
h=help
75
79
ll=""" + sample_long_alias + "\n"
402
406
 
403
407
    def setUp(self):
404
408
        super(TestConfigPath, self).setUp()
405
 
        os.environ['HOME'] = '/home/bogus'
406
 
        os.environ['XDG_CACHE_DIR'] = ''
 
409
        self.overrideEnv('HOME', '/home/bogus')
 
410
        self.overrideEnv('XDG_CACHE_DIR', '')
407
411
        if sys.platform == 'win32':
408
 
            os.environ['BZR_HOME'] = \
409
 
                r'C:\Documents and Settings\bogus\Application Data'
 
412
            self.overrideEnv(
 
413
                'BZR_HOME', r'C:\Documents and Settings\bogus\Application Data')
410
414
            self.bzr_home = \
411
415
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0'
412
416
        else:
441
445
            raise tests.TestNotApplicable(
442
446
                'XDG config dir not used on this platform')
443
447
        super(TestXDGConfigDir, self).setUp()
444
 
        os.environ['HOME'] = self.test_home_dir
 
448
        self.overrideEnv('HOME', self.test_home_dir)
445
449
        # BZR_HOME overrides everything we want to test so unset it.
446
 
        del os.environ['BZR_HOME']
 
450
        self.overrideEnv('BZR_HOME', None)
447
451
 
448
452
    def test_xdg_config_dir_exists(self):
449
453
        """When ~/.config/bazaar exists, use it as the config dir."""
454
458
    def test_xdg_config_home(self):
455
459
        """When XDG_CONFIG_HOME is set, use it."""
456
460
        xdgconfigdir = osutils.pathjoin(self.test_home_dir, 'xdgconfig')
457
 
        os.environ['XDG_CONFIG_HOME'] = xdgconfigdir
 
461
        self.overrideEnv('XDG_CONFIG_HOME', xdgconfigdir)
458
462
        newdir = osutils.pathjoin(xdgconfigdir, 'bazaar')
459
463
        os.makedirs(newdir)
460
464
        self.assertEqual(config.config_dir(), newdir)
953
957
        change_editor = my_config.get_change_editor('old', 'new')
954
958
        self.assertIs(None, change_editor)
955
959
 
 
960
    def test_get_merge_tools(self):
 
961
        conf = self._get_sample_config()
 
962
        tools = conf.get_merge_tools()
 
963
        self.log(repr(tools))
 
964
        self.assertEqual(
 
965
            {u'funkytool' : u'funkytool "arg with spaces" {this_temp}',
 
966
            u'sometool' : u'sometool {base} {this} {other} -o {result}'},
 
967
            tools)
 
968
 
 
969
    def test_get_merge_tools_empty(self):
 
970
        conf = self._get_empty_config()
 
971
        tools = conf.get_merge_tools()
 
972
        self.assertEqual({}, tools)
 
973
 
 
974
    def test_find_merge_tool(self):
 
975
        conf = self._get_sample_config()
 
976
        cmdline = conf.find_merge_tool('sometool')
 
977
        self.assertEqual('sometool {base} {this} {other} -o {result}', cmdline)
 
978
 
 
979
    def test_find_merge_tool_not_found(self):
 
980
        conf = self._get_sample_config()
 
981
        cmdline = conf.find_merge_tool('DOES NOT EXIST')
 
982
        self.assertIs(cmdline, None)
 
983
 
 
984
    def test_find_merge_tool_known(self):
 
985
        conf = self._get_empty_config()
 
986
        cmdline = conf.find_merge_tool('kdiff3')
 
987
        self.assertEquals('kdiff3 {base} {this} {other} -o {result}', cmdline)
 
988
        
 
989
    def test_find_merge_tool_override_known(self):
 
990
        conf = self._get_empty_config()
 
991
        conf.set_user_option('bzr.mergetool.kdiff3', 'kdiff3 blah')
 
992
        cmdline = conf.find_merge_tool('kdiff3')
 
993
        self.assertEqual('kdiff3 blah', cmdline)
 
994
 
956
995
 
957
996
class TestGlobalConfigSavingOptions(tests.TestCaseInTempDir):
958
997
 
1308
1347
        self.assertEqual('bzr', my_config.get_bzr_remote_path())
1309
1348
        my_config.set_user_option('bzr_remote_path', '/path-bzr')
1310
1349
        self.assertEqual('/path-bzr', my_config.get_bzr_remote_path())
1311
 
        os.environ['BZR_REMOTE_PATH'] = '/environ-bzr'
 
1350
        self.overrideEnv('BZR_REMOTE_PATH', '/environ-bzr')
1312
1351
        self.assertEqual('/environ-bzr', my_config.get_bzr_remote_path())
1313
1352
 
1314
1353
 
1360
1399
        self.assertEqual("John", my_config._get_user_id())
1361
1400
 
1362
1401
    def test_BZR_EMAIL_OVERRIDES(self):
1363
 
        os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
 
1402
        self.overrideEnv('BZR_EMAIL', "Robert Collins <robertc@example.org>")
1364
1403
        branch = FakeBranch()
1365
1404
        my_config = config.BranchConfig(branch)
1366
1405
        self.assertEqual("Robert Collins <robertc@example.org>",