~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-17 02:18:48 UTC
  • mfrom: (1711.2.58 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060617021848-38906188fc2a0300
(jamesh, jam) fix external_diff to support any file-like object (#4047, #48914)

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
24
 
from bzrlib.tests import TestCase, TestCaseInTempDir
 
25
from bzrlib.tests import (TestCase, TestCaseWithTransport,
 
26
                          TestCaseInTempDir, TestSkipped)
25
27
 
26
28
 
27
29
def udiff_lines(old, new, allow_binary=False):
31
33
    return output.readlines()
32
34
 
33
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
 
34
52
class TestDiff(TestCase):
35
53
 
36
54
    def test_add_nl(self):
78
96
        udiff_lines([1023 * 'a' + '\x00'], [], allow_binary=True)
79
97
        udiff_lines([], [1023 * 'a' + '\x00'], allow_binary=True)
80
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
        
81
111
    def test_internal_diff_default(self):
82
112
        # Default internal diff encoding is utf8
83
113
        output = StringIO()