~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

Merge updated set_parents api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
from cStringIO import StringIO
19
19
import errno
 
20
import subprocess
20
21
from tempfile import TemporaryFile
21
22
 
22
23
from bzrlib.diff import internal_diff, external_diff, show_diff_trees
109
110
                                     use_stringio=True)
110
111
        self.check_patch(lines)
111
112
 
112
 
    def test_external_diff_binary(self):
113
 
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
114
 
        self.assertEqual(['Binary files old and new differ\n', '\n'], lines)
 
113
    def test_external_diff_binary_lang_c(self):
 
114
        orig_lang = os.environ.get('LANG')
 
115
        try:
 
116
            os.environ['LANG'] = 'C'
 
117
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
 
118
            self.assertEqual(['Binary files old and new differ\n', '\n'], lines)
 
119
        finally:
 
120
            if orig_lang is None:
 
121
                del os.environ['LANG']
 
122
            else:
 
123
                os.environ['LANG'] = orig_lang
115
124
 
116
125
    def test_no_external_diff(self):
117
126
        """Check that NoDiff is raised when diff is not available"""
182
191
            'internal_diff should return bytestrings')
183
192
 
184
193
 
 
194
class TestDiffFiles(TestCaseInTempDir):
 
195
 
 
196
    def test_external_diff_binary(self):
 
197
        """The output when using external diff should use diff's i18n error"""
 
198
        # Make sure external_diff doesn't fail in the current LANG
 
199
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
 
200
 
 
201
        cmd = ['diff', '-u', 'old', 'new']
 
202
        open('old', 'wb').write('\x00foobar\n')
 
203
        open('new', 'wb').write('foo\x00bar\n')
 
204
        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
 
205
                                     stdin=subprocess.PIPE)
 
206
        out, err = pipe.communicate()
 
207
        # Diff returns '2' on Binary files.
 
208
        self.assertEqual(2, pipe.returncode)
 
209
        # We should output whatever diff tells us, plus a trailing newline
 
210
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
 
211
 
 
212
 
185
213
class TestDiffDates(TestCaseWithTransport):
186
214
 
187
215
    def setUp(self):