~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Martin Pool
  • Date: 2006-06-20 05:32:16 UTC
  • mfrom: (1797 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620053216-817857d7ca3e9d1f
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import os
18
18
from cStringIO import StringIO
 
19
import errno
 
20
from tempfile import TemporaryFile
19
21
 
20
 
from bzrlib.diff import internal_diff, show_diff_trees
21
 
from bzrlib.errors import BinaryFile
 
22
from bzrlib.diff import internal_diff, external_diff, show_diff_trees
 
23
from bzrlib.errors import BinaryFile, NoDiff
22
24
import bzrlib.patiencediff
23
 
from bzrlib.tests import TestCase, TestCaseWithTransport, TestCaseInTempDir
 
25
from bzrlib.tests import (TestCase, TestCaseWithTransport,
 
26
                          TestCaseInTempDir, TestSkipped)
24
27
 
25
28
 
26
29
def udiff_lines(old, new, allow_binary=False):
30
33
    return output.readlines()
31
34
 
32
35
 
 
36
def external_udiff_lines(old, new, use_stringio=False):
 
37
    if use_stringio:
 
38
        # StringIO has no fileno, so it tests a different codepath
 
39
        output = StringIO()
 
40
    else:
 
41
        output = TemporaryFile()
 
42
    try:
 
43
        external_diff('old', old, 'new', new, output, diff_opts=['-u'])
 
44
    except NoDiff:
 
45
        raise TestSkipped('external "diff" not present to test')
 
46
    output.seek(0, 0)
 
47
    lines = output.readlines()
 
48
    output.close()
 
49
    return lines
 
50
 
 
51
 
33
52
class TestDiff(TestCase):
34
53
 
35
54
    def test_add_nl(self):
77
96
        udiff_lines([1023 * 'a' + '\x00'], [], allow_binary=True)
78
97
        udiff_lines([], [1023 * 'a' + '\x00'], allow_binary=True)
79
98
 
 
99
    def test_external_diff(self):
 
100
        lines = external_udiff_lines(['boo\n'], ['goo\n'])
 
101
        self.check_patch(lines)
 
102
 
 
103
    def test_external_diff_no_fileno(self):
 
104
        # Make sure that we can handle not having a fileno, even
 
105
        # if the diff is large
 
106
        lines = external_udiff_lines(['boo\n']*10000,
 
107
                                     ['goo\n']*10000,
 
108
                                     use_stringio=True)
 
109
        self.check_patch(lines)
 
110
        
80
111
    def test_internal_diff_default(self):
81
112
        # Default internal diff encoding is utf8
82
113
        output = StringIO()