~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-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

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
import bzrlib.msgeditor 
24
24
from bzrlib.tests import TestCaseWithTransport, TestSkipped
 
25
from bzrlib.trace import mutter
25
26
 
26
27
 
27
28
class MsgEditorTest(TestCaseWithTransport):
42
43
    def test_commit_template(self):
43
44
        """Test building a commit message template"""
44
45
        working_tree = self.make_uncommitted_tree()
45
 
        template = make_commit_message_template(working_tree, None)
 
46
        template = bzrlib.msgeditor.make_commit_message_template(working_tree, None)
46
47
        self.assertEqualDiff(template,
47
48
u"""\
48
49
added:
49
50
  hell\u00d8
50
51
""")
 
52
 
 
53
    def setUp(self):
 
54
        super(MsgEditorTest, self).setUp()
 
55
        self._bzr_editor = os.environ.get('BZR_EDITOR', None)
 
56
 
 
57
    def tearDown(self):
 
58
        if self._bzr_editor != None:
 
59
            os.environ['BZR_EDITOR'] = self._bzr_editor
 
60
        else:
 
61
            if os.environ.get('BZR_EDITOR', None) != None:
 
62
                del os.environ['BZR_EDITOR']
 
63
        super(MsgEditorTest, self).tearDown()
 
64
 
 
65
    def test_get_editor(self):
 
66
        os.environ['BZR_EDITOR'] = 'fed'
 
67
        editors = [i for i in bzrlib.msgeditor._get_editor()]
 
68
        self.assertNotEqual([], editors, 'No editor found')
 
69
        self.assertEqual('fed', editors[0])
 
70
 
 
71
    def test_run_editor(self):
 
72
        if sys.platform == "win32":
 
73
            f = file('fed.bat', 'w')
 
74
            f.write('@rem dummy fed')
 
75
            f.close()
 
76
            os.environ['BZR_EDITOR'] = 'fed.bat'
 
77
        else:
 
78
            f = file('fed.sh', 'wb')
 
79
            f.write('#!/bin/sh\n')
 
80
            f.close()
 
81
            os.chmod('fed.sh', 0755)
 
82
            os.environ['BZR_EDITOR'] = './fed.sh'
 
83
 
 
84
        self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
 
85
                         'Unable to run dummy fake editor')
 
86
 
 
87
    def test_edit_commit_message(self):
 
88
        working_tree = self.make_uncommitted_tree()
 
89
        # make fake editor
 
90
        f = file('fed.py', 'wb')
 
91
        f.write('#!%s\n' % sys.executable)
 
92
        f.write("""\
 
93
import sys
 
94
if len(sys.argv) == 2:
 
95
    fn = sys.argv[1]
 
96
    f = file(fn, 'rb')
 
97
    s = f.read()
 
98
    f.close()
 
99
    f = file(fn, 'wb')
 
100
    f.write('test message from fed\\n')
 
101
    f.write(s)
 
102
    f.close()
 
103
""")
 
104
        f.close()
 
105
        if sys.platform == "win32":
 
106
            # [win32] make batch file and set BZR_EDITOR
 
107
            f = file('fed.bat', 'w')
 
108
            f.write("""\
 
109
@echo off
 
110
%s fed.py %%1
 
111
""" % sys.executable)
 
112
            f.close()
 
113
            os.environ['BZR_EDITOR'] = 'fed.bat'
 
114
        else:
 
115
            # [non-win32] make python script executable and set BZR_EDITOR
 
116
            os.chmod('fed.py', 0755)
 
117
            os.environ['BZR_EDITOR'] = './fed.py'
 
118
 
 
119
        mutter('edit_commit_message without infotext')
 
120
        self.assertEqual('test message from fed\n',
 
121
                         bzrlib.msgeditor.edit_commit_message(''))
 
122
 
 
123
        mutter('edit_commit_message with unicode infotext')
 
124
        self.assertEqual('test message from fed\n',
 
125
                         bzrlib.msgeditor.edit_commit_message(u'\u1234'))
 
126
 
 
127
    def test_deleted_commit_message(self):
 
128
        working_tree = self.make_uncommitted_tree()
 
129
 
 
130
        if sys.platform == 'win32':
 
131
            os.environ['BZR_EDITOR'] = 'del'
 
132
        else:
 
133
            os.environ['BZR_EDITOR'] = 'rm'
 
134
 
 
135
        self.assertRaises(IOError, bzrlib.msgeditor.edit_commit_message, '')
 
136