1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26
from bzrlib.tests.features import backslashdir_feature
29
class TestFilenameSubstitution(tests.TestCaseInTempDir):
31
def test_simple_filename(self):
32
cmd_list = ['kdiff3', '{base}', '{this}', '{other}', '-o', '{result}']
33
args, tmpfile = mergetools._subst_filename(cmd_list, 'test.txt')
43
def test_spaces(self):
44
cmd_list = ['kdiff3', '{base}', '{this}', '{other}', '-o', '{result}']
45
args, tmpfile = mergetools._subst_filename(cmd_list,
46
'file with space.txt')
49
'file with space.txt.BASE',
50
'file with space.txt.THIS',
51
'file with space.txt.OTHER',
53
'file with space.txt'],
56
def test_spaces_and_quotes(self):
57
cmd_list = ['kdiff3', '{base}', '{this}', '{other}', '-o', '{result}']
58
args, tmpfile = mergetools._subst_filename(cmd_list,
59
'file with "space and quotes".txt')
62
'file with "space and quotes".txt.BASE',
63
'file with "space and quotes".txt.THIS',
64
'file with "space and quotes".txt.OTHER',
66
'file with "space and quotes".txt'],
69
def test_tempfile(self):
70
self.build_tree(('test.txt', 'test.txt.BASE', 'test.txt.THIS',
72
cmd_list = ['some_tool', '{this_temp}']
73
args, tmpfile = mergetools._subst_filename(cmd_list, 'test.txt')
74
self.assertPathExists(tmpfile)
78
class TestCheckAvailability(tests.TestCaseInTempDir):
80
def test_full_path(self):
81
self.assertTrue(mergetools.check_availability(sys.executable))
83
def test_exe_on_path(self):
84
self.assertTrue(mergetools.check_availability(
85
os.path.basename(sys.executable)))
87
def test_nonexistent(self):
88
self.assertFalse(mergetools.check_availability('DOES NOT EXIST'))
90
def test_non_executable(self):
91
f, name = tempfile.mkstemp()
93
self.log('temp filename: %s', name)
94
self.assertFalse(mergetools.check_availability(name))
100
class TestInvoke(tests.TestCaseInTempDir):
102
super(tests.TestCaseInTempDir, self).setUp()
105
self.build_tree_contents((
106
('test.txt', 'stuff'),
107
('test.txt.BASE', 'base stuff'),
108
('test.txt.THIS', 'this stuff'),
109
('test.txt.OTHER', 'other stuff'),
112
def test_success(self):
113
def dummy_invoker(exe, args, cleanup):
118
retcode = mergetools.invoke('tool {result}', 'test.txt', dummy_invoker)
119
self.assertEqual(0, retcode)
120
self.assertEqual('tool', self._exe)
121
self.assertEqual(['test.txt'], self._args)
123
def test_failure(self):
124
def dummy_invoker(exe, args, cleanup):
129
retcode = mergetools.invoke('tool {result}', 'test.txt', dummy_invoker)
130
self.assertEqual(1, retcode)
131
self.assertEqual('tool', self._exe)
132
self.assertEqual(['test.txt'], self._args)
134
def test_success_tempfile(self):
135
def dummy_invoker(exe, args, cleanup):
138
self.assertPathExists(args[0])
139
f = open(args[0], 'wt')
140
f.write('temp stuff')
144
retcode = mergetools.invoke('tool {this_temp}', 'test.txt',
146
self.assertEqual(0, retcode)
147
self.assertEqual('tool', self._exe)
148
self.assertPathDoesNotExist(self._args[0])
149
self.assertFileEqual('temp stuff', 'test.txt')
151
def test_failure_tempfile(self):
152
def dummy_invoker(exe, args, cleanup):
155
self.assertPathExists(args[0])
157
f = open(args[0], 'wt')
159
f.write('temp stuff')
163
retcode = mergetools.invoke('tool {this_temp}', 'test.txt',
165
self.assertEqual(1, retcode)
166
self.assertEqual('tool', self._exe)
167
self.assertFileEqual('stuff', 'test.txt')