~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: James Henstridge
  • Date: 2006-05-03 15:33:52 UTC
  • mto: (1711.2.53 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1786.
  • Revision ID: james.henstridge@canonical.com-20060503153352-8eb15d278c909d52
add a test for sending external diff output to a file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from cStringIO import StringIO
2
2
 
3
 
from bzrlib.diff import internal_diff
 
3
from bzrlib.diff import internal_diff, external_diff
4
4
from bzrlib.errors import BinaryFile
5
 
from bzrlib.tests import TestCase
 
5
from bzrlib.tests import TestCase, TestCaseInTempDir
 
6
from tempfile import TemporaryFile
6
7
 
7
8
 
8
9
def udiff_lines(old, new, allow_binary=False):
11
12
    output.seek(0, 0)
12
13
    return output.readlines()
13
14
 
 
15
def external_udiff_lines(old, new):
 
16
    output = TemporaryFile()
 
17
    external_diff('old', old, 'new', new, output, diff_opts=['-u'])
 
18
    output.seek(0, 0)
 
19
    lines = output.readlines()
 
20
    output.close()
 
21
    return lines
 
22
 
 
23
 
14
24
class TestDiff(TestCase):
15
25
    def test_add_nl(self):
16
26
        """diff generates a valid diff for patches that add a newline"""
56
66
        self.assertRaises(BinaryFile, udiff_lines, [], [1023 * 'a' + '\x00'])
57
67
        udiff_lines([1023 * 'a' + '\x00'], [], allow_binary=True)
58
68
        udiff_lines([], [1023 * 'a' + '\x00'], allow_binary=True)
 
69
 
 
70
    def test_external_diff(self):
 
71
        lines = external_udiff_lines(['boo\n'], ['goo\n'])
 
72
        self.check_patch(lines)
 
73