~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_msgeditor.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-29 15:40:15 UTC
  • mto: This revision was merged to the branch mainline in revision 1693.
  • Revision ID: john@arbash-meinel.com-20060429154015-2ed83b4e1041240e
Added a test for the new list of editors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
 
22
22
from bzrlib.branch import Branch
23
 
from bzrlib.msgeditor import make_commit_message_template
 
23
from bzrlib.config import ensure_config_dir_exists, config_filename
 
24
from bzrlib.msgeditor import make_commit_message_template, _get_editor
24
25
from bzrlib.tests import TestCaseWithTransport, TestSkipped
25
26
 
26
27
 
48
49
added:
49
50
  hell\u00d8
50
51
""")
 
52
 
 
53
    def test__get_editor(self):
 
54
        # Test that _get_editor can return a decent list of items
 
55
        bzr_editor = os.environ.get('BZR_EDITOR')
 
56
        editor = os.environ.get('EDITOR')
 
57
        try:
 
58
            os.environ['BZR_EDITOR'] = 'bzr_editor'
 
59
            os.environ['EDITOR'] = 'editor'
 
60
 
 
61
            ensure_config_dir_exists()
 
62
            f = open(config_filename(), 'wb')
 
63
            f.write('editor = config_editor\n')
 
64
            f.close()
 
65
 
 
66
            editors = list(_get_editor())
 
67
 
 
68
            self.assertEqual(['bzr_editor', 'config_editor', 'editor'],
 
69
                editors[:3])
 
70
 
 
71
            if sys.platform == 'win32':
 
72
                self.assertEqual(['wordpad.exe', 'notepad.exe'], editors[3:])
 
73
            else:
 
74
                self.assertEqual(['vi', 'pico', 'nano', 'joe'], editors[3:])
 
75
 
 
76
        finally:
 
77
            # Restore the environment
 
78
            if bzr_editor is None:
 
79
                del os.environ['BZR_EDITOR']
 
80
            else:
 
81
                os.environ['BZR_EDITOR'] = bzr_editor
 
82
            if editor is None:
 
83
                del os.environ['EDITOR']
 
84
            else:
 
85
                os.environ['EDITOR'] = editor
 
86