~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: 2007-10-24 12:49:17 UTC
  • mfrom: (2935.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071024124917-xb75eckyxx6vkrlg
Makefile fixes - hooks.html generation & allow python to be overridden (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Development Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
22
 
23
23
from bzrlib.diff import internal_diff, external_diff, show_diff_trees
24
24
from bzrlib.errors import BinaryFile, NoDiff
 
25
import bzrlib.osutils as osutils
25
26
import bzrlib.patiencediff
26
 
from bzrlib.tests import (TestCase, TestCaseWithTransport,
 
27
import bzrlib._patiencediff_py
 
28
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
27
29
                          TestCaseInTempDir, TestSkipped)
28
30
 
29
31
 
 
32
class _CompiledPatienceDiffFeature(Feature):
 
33
 
 
34
    def _probe(self):
 
35
        try:
 
36
            import bzrlib._patiencediff_c
 
37
        except ImportError:
 
38
            return False
 
39
        return True
 
40
 
 
41
    def feature_name(self):
 
42
        return 'bzrlib._patiencediff_c'
 
43
 
 
44
CompiledPatienceDiffFeature = _CompiledPatienceDiffFeature()
 
45
 
 
46
 
 
47
class _UnicodeFilename(Feature):
 
48
    """Does the filesystem support Unicode filenames?"""
 
49
 
 
50
    def _probe(self):
 
51
        try:
 
52
            os.stat(u'\u03b1')
 
53
        except UnicodeEncodeError:
 
54
            return False
 
55
        except (IOError, OSError):
 
56
            # The filesystem allows the Unicode filename but the file doesn't
 
57
            # exist.
 
58
            return True
 
59
        else:
 
60
            # The filesystem allows the Unicode filename and the file exists,
 
61
            # for some reason.
 
62
            return True
 
63
 
 
64
UnicodeFilename = _UnicodeFilename()
 
65
 
 
66
 
 
67
class TestUnicodeFilename(TestCase):
 
68
 
 
69
    def test_probe_passes(self):
 
70
        """UnicodeFilename._probe passes."""
 
71
        # We can't test much more than that because the behaviour depends
 
72
        # on the platform.
 
73
        UnicodeFilename._probe()
 
74
        
 
75
 
30
76
def udiff_lines(old, new, allow_binary=False):
31
77
    output = StringIO()
32
78
    internal_diff('old', old, 'new', new, output, allow_binary)
111
157
        self.check_patch(lines)
112
158
 
113
159
    def test_external_diff_binary_lang_c(self):
114
 
        orig_lang = os.environ.get('LANG')
 
160
        old_env = {}
 
161
        for lang in ('LANG', 'LC_ALL', 'LANGUAGE'):
 
162
            old_env[lang] = osutils.set_or_unset_env(lang, 'C')
115
163
        try:
116
 
            os.environ['LANG'] = 'C'
117
164
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
118
 
            self.assertEqual(['Binary files old and new differ\n', '\n'], lines)
 
165
            # Older versions of diffutils say "Binary files", newer
 
166
            # versions just say "Files".
 
167
            self.assertContainsRe(lines[0],
 
168
                                  '(Binary f|F)iles old and new differ\n')
 
169
            self.assertEquals(lines[1:], ['\n'])
119
170
        finally:
120
 
            if orig_lang is None:
121
 
                del os.environ['LANG']
122
 
            else:
123
 
                os.environ['LANG'] = orig_lang
 
171
            for lang, old_val in old_env.iteritems():
 
172
                osutils.set_or_unset_env(lang, old_val)
124
173
 
125
174
    def test_no_external_diff(self):
126
175
        """Check that NoDiff is raised when diff is not available"""
198
247
        # Make sure external_diff doesn't fail in the current LANG
199
248
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
200
249
 
201
 
        cmd = ['diff', '-u', 'old', 'new']
 
250
        cmd = ['diff', '-u', '--binary', 'old', 'new']
202
251
        open('old', 'wb').write('\x00foobar\n')
203
252
        open('new', 'wb').write('foo\x00bar\n')
204
253
        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
210
259
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
211
260
 
212
261
 
213
 
class TestDiffDates(TestCaseWithTransport):
 
262
class TestShowDiffTreesHelper(TestCaseWithTransport):
 
263
    """Has a helper for running show_diff_trees"""
 
264
 
 
265
    def get_diff(self, tree1, tree2, specific_files=None, working_tree=None):
 
266
        output = StringIO()
 
267
        if working_tree is not None:
 
268
            extra_trees = (working_tree,)
 
269
        else:
 
270
            extra_trees = ()
 
271
        show_diff_trees(tree1, tree2, output, specific_files=specific_files,
 
272
                        extra_trees=extra_trees, old_label='old/',
 
273
                        new_label='new/')
 
274
        return output.getvalue()
 
275
 
 
276
 
 
277
class TestDiffDates(TestShowDiffTreesHelper):
214
278
 
215
279
    def setUp(self):
216
280
        super(TestDiffDates, self).setUp()
250
314
        # set the date stamps for files in the working tree to known values
251
315
        os.utime('file1', (1144195200, 1144195200)) # 2006-04-05 00:00:00 UTC
252
316
 
253
 
    def get_diff(self, tree1, tree2, specific_files=None, working_tree=None):
254
 
        output = StringIO()
255
 
        if working_tree is not None:
256
 
            extra_trees = (working_tree,)
257
 
        else:
258
 
            extra_trees = ()
259
 
        show_diff_trees(tree1, tree2, output, specific_files=specific_files,
260
 
                        extra_trees=extra_trees, old_label='old/', 
261
 
                        new_label='new/')
262
 
        return output.getvalue()
263
 
 
264
317
    def test_diff_rev_tree_working_tree(self):
265
318
        output = self.get_diff(self.wt.basis_tree(), self.wt)
266
319
        # note that the date for old/file1 is from rev 2 rather than from
350
403
        self.assertNotContainsRe(out, 'file1\t')
351
404
 
352
405
 
 
406
 
 
407
class TestShowDiffTrees(TestShowDiffTreesHelper):
 
408
    """Direct tests for show_diff_trees"""
 
409
 
 
410
    def test_modified_file(self):
 
411
        """Test when a file is modified."""
 
412
        tree = self.make_branch_and_tree('tree')
 
413
        self.build_tree_contents([('tree/file', 'contents\n')])
 
414
        tree.add(['file'], ['file-id'])
 
415
        tree.commit('one', rev_id='rev-1')
 
416
 
 
417
        self.build_tree_contents([('tree/file', 'new contents\n')])
 
418
        diff = self.get_diff(tree.basis_tree(), tree)
 
419
        self.assertContainsRe(diff, "=== modified file 'file'\n")
 
420
        self.assertContainsRe(diff, '--- old/file\t')
 
421
        self.assertContainsRe(diff, '\\+\\+\\+ new/file\t')
 
422
        self.assertContainsRe(diff, '-contents\n'
 
423
                                    '\\+new contents\n')
 
424
 
 
425
    def test_modified_file_in_renamed_dir(self):
 
426
        """Test when a file is modified in a renamed directory."""
 
427
        tree = self.make_branch_and_tree('tree')
 
428
        self.build_tree(['tree/dir/'])
 
429
        self.build_tree_contents([('tree/dir/file', 'contents\n')])
 
430
        tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
 
431
        tree.commit('one', rev_id='rev-1')
 
432
 
 
433
        tree.rename_one('dir', 'other')
 
434
        self.build_tree_contents([('tree/other/file', 'new contents\n')])
 
435
        diff = self.get_diff(tree.basis_tree(), tree)
 
436
        self.assertContainsRe(diff, "=== renamed directory 'dir' => 'other'\n")
 
437
        self.assertContainsRe(diff, "=== modified file 'other/file'\n")
 
438
        # XXX: This is technically incorrect, because it used to be at another
 
439
        # location. What to do?
 
440
        self.assertContainsRe(diff, '--- old/dir/file\t')
 
441
        self.assertContainsRe(diff, '\\+\\+\\+ new/other/file\t')
 
442
        self.assertContainsRe(diff, '-contents\n'
 
443
                                    '\\+new contents\n')
 
444
 
 
445
    def test_renamed_directory(self):
 
446
        """Test when only a directory is only renamed."""
 
447
        tree = self.make_branch_and_tree('tree')
 
448
        self.build_tree(['tree/dir/'])
 
449
        self.build_tree_contents([('tree/dir/file', 'contents\n')])
 
450
        tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
 
451
        tree.commit('one', rev_id='rev-1')
 
452
 
 
453
        tree.rename_one('dir', 'newdir')
 
454
        diff = self.get_diff(tree.basis_tree(), tree)
 
455
        # Renaming a directory should be a single "you renamed this dir" even
 
456
        # when there are files inside.
 
457
        self.assertEqual("=== renamed directory 'dir' => 'newdir'\n", diff)
 
458
 
 
459
    def test_renamed_file(self):
 
460
        """Test when a file is only renamed."""
 
461
        tree = self.make_branch_and_tree('tree')
 
462
        self.build_tree_contents([('tree/file', 'contents\n')])
 
463
        tree.add(['file'], ['file-id'])
 
464
        tree.commit('one', rev_id='rev-1')
 
465
 
 
466
        tree.rename_one('file', 'newname')
 
467
        diff = self.get_diff(tree.basis_tree(), tree)
 
468
        self.assertContainsRe(diff, "=== renamed file 'file' => 'newname'\n")
 
469
        # We shouldn't have a --- or +++ line, because there is no content
 
470
        # change
 
471
        self.assertNotContainsRe(diff, '---')
 
472
 
 
473
    def test_renamed_and_modified_file(self):
 
474
        """Test when a file is only renamed."""
 
475
        tree = self.make_branch_and_tree('tree')
 
476
        self.build_tree_contents([('tree/file', 'contents\n')])
 
477
        tree.add(['file'], ['file-id'])
 
478
        tree.commit('one', rev_id='rev-1')
 
479
 
 
480
        tree.rename_one('file', 'newname')
 
481
        self.build_tree_contents([('tree/newname', 'new contents\n')])
 
482
        diff = self.get_diff(tree.basis_tree(), tree)
 
483
        self.assertContainsRe(diff, "=== renamed file 'file' => 'newname'\n")
 
484
        self.assertContainsRe(diff, '--- old/file\t')
 
485
        self.assertContainsRe(diff, '\\+\\+\\+ new/newname\t')
 
486
        self.assertContainsRe(diff, '-contents\n'
 
487
                                    '\\+new contents\n')
 
488
 
 
489
    def test_binary_unicode_filenames(self):
 
490
        """Test that contents of files are *not* encoded in UTF-8 when there
 
491
        is a binary file in the diff.
 
492
        """
 
493
        # See https://bugs.launchpad.net/bugs/110092.
 
494
        self.requireFeature(UnicodeFilename)
 
495
 
 
496
        # This bug isn't triggered with cStringIO.
 
497
        from StringIO import StringIO
 
498
        tree = self.make_branch_and_tree('tree')
 
499
        alpha, omega = u'\u03b1', u'\u03c9'
 
500
        alpha_utf8, omega_utf8 = alpha.encode('utf8'), omega.encode('utf8')
 
501
        self.build_tree_contents(
 
502
            [('tree/' + alpha, chr(0)),
 
503
             ('tree/' + omega,
 
504
              ('The %s and the %s\n' % (alpha_utf8, omega_utf8)))])
 
505
        tree.add([alpha], ['file-id'])
 
506
        tree.add([omega], ['file-id-2'])
 
507
        diff_content = StringIO()
 
508
        show_diff_trees(tree.basis_tree(), tree, diff_content)
 
509
        diff = diff_content.getvalue()
 
510
        self.assertContainsRe(diff, r"=== added file '%s'" % alpha_utf8)
 
511
        self.assertContainsRe(
 
512
            diff, "Binary files a/%s.*and b/%s.* differ\n" % (alpha_utf8, alpha_utf8))
 
513
        self.assertContainsRe(diff, r"=== added file '%s'" % omega_utf8)
 
514
        self.assertContainsRe(diff, r"--- a/%s" % (omega_utf8,))
 
515
        self.assertContainsRe(diff, r"\+\+\+ b/%s" % (omega_utf8,))
 
516
 
 
517
    def test_unicode_filename(self):
 
518
        """Test when the filename are unicode."""
 
519
        self.requireFeature(UnicodeFilename)
 
520
 
 
521
        alpha, omega = u'\u03b1', u'\u03c9'
 
522
        autf8, outf8 = alpha.encode('utf8'), omega.encode('utf8')
 
523
 
 
524
        tree = self.make_branch_and_tree('tree')
 
525
        self.build_tree_contents([('tree/ren_'+alpha, 'contents\n')])
 
526
        tree.add(['ren_'+alpha], ['file-id-2'])
 
527
        self.build_tree_contents([('tree/del_'+alpha, 'contents\n')])
 
528
        tree.add(['del_'+alpha], ['file-id-3'])
 
529
        self.build_tree_contents([('tree/mod_'+alpha, 'contents\n')])
 
530
        tree.add(['mod_'+alpha], ['file-id-4'])
 
531
 
 
532
        tree.commit('one', rev_id='rev-1')
 
533
 
 
534
        tree.rename_one('ren_'+alpha, 'ren_'+omega)
 
535
        tree.remove('del_'+alpha)
 
536
        self.build_tree_contents([('tree/add_'+alpha, 'contents\n')])
 
537
        tree.add(['add_'+alpha], ['file-id'])
 
538
        self.build_tree_contents([('tree/mod_'+alpha, 'contents_mod\n')])
 
539
 
 
540
        diff = self.get_diff(tree.basis_tree(), tree)
 
541
        self.assertContainsRe(diff,
 
542
                "=== renamed file 'ren_%s' => 'ren_%s'\n"%(autf8, outf8))
 
543
        self.assertContainsRe(diff, "=== added file 'add_%s'"%autf8)
 
544
        self.assertContainsRe(diff, "=== modified file 'mod_%s'"%autf8)
 
545
        self.assertContainsRe(diff, "=== removed file 'del_%s'"%autf8)
 
546
 
353
547
class TestPatienceDiffLib(TestCase):
354
548
 
 
549
    def setUp(self):
 
550
        super(TestPatienceDiffLib, self).setUp()
 
551
        self._unique_lcs = bzrlib._patiencediff_py.unique_lcs_py
 
552
        self._recurse_matches = bzrlib._patiencediff_py.recurse_matches_py
 
553
        self._PatienceSequenceMatcher = \
 
554
            bzrlib._patiencediff_py.PatienceSequenceMatcher_py
 
555
 
355
556
    def test_unique_lcs(self):
356
 
        unique_lcs = bzrlib.patiencediff.unique_lcs
 
557
        unique_lcs = self._unique_lcs
357
558
        self.assertEquals(unique_lcs('', ''), [])
 
559
        self.assertEquals(unique_lcs('', 'a'), [])
 
560
        self.assertEquals(unique_lcs('a', ''), [])
358
561
        self.assertEquals(unique_lcs('a', 'a'), [(0,0)])
359
562
        self.assertEquals(unique_lcs('a', 'b'), [])
360
563
        self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
367
570
    def test_recurse_matches(self):
368
571
        def test_one(a, b, matches):
369
572
            test_matches = []
370
 
            bzrlib.patiencediff.recurse_matches(a, b, 0, 0, len(a), len(b),
371
 
                test_matches, 10)
 
573
            self._recurse_matches(
 
574
                a, b, 0, 0, len(a), len(b), test_matches, 10)
372
575
            self.assertEquals(test_matches, matches)
373
576
 
374
577
        test_one(['a', '', 'b', '', 'c'], ['a', 'a', 'b', 'c', 'c'],
375
578
                 [(0, 0), (2, 2), (4, 4)])
376
579
        test_one(['a', 'c', 'b', 'a', 'c'], ['a', 'b', 'c'],
377
580
                 [(0, 0), (2, 1), (4, 2)])
 
581
        # Even though 'bc' is not unique globally, and is surrounded by
 
582
        # non-matching lines, we should still match, because they are locally
 
583
        # unique
 
584
        test_one('abcdbce', 'afbcgdbce', [(0,0), (1, 2), (2, 3), (3, 5),
 
585
                                          (4, 6), (5, 7), (6, 8)])
378
586
 
379
587
        # recurse_matches doesn't match non-unique 
380
588
        # lines surrounded by bogus text.
390
598
        def chk_blocks(a, b, expected_blocks):
391
599
            # difflib always adds a signature of the total
392
600
            # length, with no matching entries at the end
393
 
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
 
601
            s = self._PatienceSequenceMatcher(None, a, b)
394
602
            blocks = s.get_matching_blocks()
395
603
            self.assertEquals((len(a), len(b), 0), blocks[-1])
396
604
            self.assertEquals(expected_blocks, blocks[:-1])
398
606
        # Some basic matching tests
399
607
        chk_blocks('', '', [])
400
608
        chk_blocks([], [], [])
 
609
        chk_blocks('abc', '', [])
 
610
        chk_blocks('', 'abc', [])
401
611
        chk_blocks('abcd', 'abcd', [(0, 0, 4)])
402
612
        chk_blocks('abcd', 'abce', [(0, 0, 3)])
403
613
        chk_blocks('eabc', 'abce', [(1, 0, 3)])
442
652
 
443
653
    def test_opcodes(self):
444
654
        def chk_ops(a, b, expected_codes):
445
 
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
 
655
            s = self._PatienceSequenceMatcher(None, a, b)
446
656
            self.assertEquals(expected_codes, s.get_opcodes())
447
657
 
448
658
        chk_ops('', '', [])
449
659
        chk_ops([], [], [])
 
660
        chk_ops('abc', '', [('delete', 0,3, 0,0)])
 
661
        chk_ops('', 'abc', [('insert', 0,0, 0,3)])
450
662
        chk_ops('abcd', 'abcd', [('equal',    0,4, 0,4)])
451
663
        chk_ops('abcd', 'abce', [('equal',   0,3, 0,3),
452
664
                                 ('replace', 3,4, 3,4)
514
726
                 ('equal',   10,11, 8,9)
515
727
                ])
516
728
 
 
729
    def test_grouped_opcodes(self):
 
730
        def chk_ops(a, b, expected_codes, n=3):
 
731
            s = self._PatienceSequenceMatcher(None, a, b)
 
732
            self.assertEquals(expected_codes, list(s.get_grouped_opcodes(n)))
 
733
 
 
734
        chk_ops('', '', [])
 
735
        chk_ops([], [], [])
 
736
        chk_ops('abc', '', [[('delete', 0,3, 0,0)]])
 
737
        chk_ops('', 'abc', [[('insert', 0,0, 0,3)]])
 
738
        chk_ops('abcd', 'abcd', [])
 
739
        chk_ops('abcd', 'abce', [[('equal',   0,3, 0,3),
 
740
                                  ('replace', 3,4, 3,4)
 
741
                                 ]])
 
742
        chk_ops('eabc', 'abce', [[('delete', 0,1, 0,0),
 
743
                                 ('equal',  1,4, 0,3),
 
744
                                 ('insert', 4,4, 3,4)
 
745
                                ]])
 
746
        chk_ops('abcdefghijklmnop', 'abcdefxydefghijklmnop',
 
747
                [[('equal',  3,6, 3,6),
 
748
                  ('insert', 6,6, 6,11),
 
749
                  ('equal',  6,9, 11,14)
 
750
                  ]])
 
751
        chk_ops('abcdefghijklmnop', 'abcdefxydefghijklmnop',
 
752
                [[('equal',  2,6, 2,6),
 
753
                  ('insert', 6,6, 6,11),
 
754
                  ('equal',  6,10, 11,15)
 
755
                  ]], 4)
 
756
        chk_ops('Xabcdef', 'abcdef',
 
757
                [[('delete', 0,1, 0,0),
 
758
                  ('equal',  1,4, 0,3)
 
759
                  ]])
 
760
        chk_ops('abcdef', 'abcdefX',
 
761
                [[('equal',  3,6, 3,6),
 
762
                  ('insert', 6,6, 6,7)
 
763
                  ]])
 
764
 
 
765
 
517
766
    def test_multiple_ranges(self):
518
767
        # There was an earlier bug where we used a bad set of ranges,
519
768
        # this triggers that specific bug, to make sure it doesn't regress
520
769
        def chk_blocks(a, b, expected_blocks):
521
770
            # difflib always adds a signature of the total
522
771
            # length, with no matching entries at the end
523
 
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
 
772
            s = self._PatienceSequenceMatcher(None, a, b)
524
773
            blocks = s.get_matching_blocks()
525
774
            x = blocks.pop()
526
775
            self.assertEquals(x, (len(a), len(b), 0))
588
837
        txt_b = ['hello there\n',
589
838
                 'how are you today?\n']
590
839
        unified_diff = bzrlib.patiencediff.unified_diff
591
 
        psm = bzrlib.patiencediff.PatienceSequenceMatcher
 
840
        psm = self._PatienceSequenceMatcher
592
841
        self.assertEquals([ '---  \n',
593
842
                           '+++  \n',
594
843
                           '@@ -1,3 +1,2 @@\n',
636
885
                                 sequencematcher=psm)))
637
886
 
638
887
 
 
888
class TestPatienceDiffLib_c(TestPatienceDiffLib):
 
889
 
 
890
    _test_needs_features = [CompiledPatienceDiffFeature]
 
891
 
 
892
    def setUp(self):
 
893
        super(TestPatienceDiffLib_c, self).setUp()
 
894
        import bzrlib._patiencediff_c
 
895
        self._unique_lcs = bzrlib._patiencediff_c.unique_lcs_c
 
896
        self._recurse_matches = bzrlib._patiencediff_c.recurse_matches_c
 
897
        self._PatienceSequenceMatcher = \
 
898
            bzrlib._patiencediff_c.PatienceSequenceMatcher_c
 
899
 
 
900
 
639
901
class TestPatienceDiffLibFiles(TestCaseInTempDir):
640
902
 
 
903
    def setUp(self):
 
904
        super(TestPatienceDiffLibFiles, self).setUp()
 
905
        self._PatienceSequenceMatcher = \
 
906
            bzrlib._patiencediff_py.PatienceSequenceMatcher_py
 
907
 
641
908
    def test_patience_unified_diff_files(self):
642
909
        txt_a = ['hello there\n',
643
910
                 'world\n',
648
915
        open('b1', 'wb').writelines(txt_b)
649
916
 
650
917
        unified_diff_files = bzrlib.patiencediff.unified_diff_files
651
 
        psm = bzrlib.patiencediff.PatienceSequenceMatcher
 
918
        psm = self._PatienceSequenceMatcher
652
919
        self.assertEquals(['--- a1 \n',
653
920
                           '+++ b1 \n',
654
921
                           '@@ -1,3 +1,2 @@\n',
699
966
                          ]
700
967
                          , list(unified_diff_files('a2', 'b2',
701
968
                                 sequencematcher=psm)))
 
969
 
 
970
 
 
971
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
 
972
 
 
973
    _test_needs_features = [CompiledPatienceDiffFeature]
 
974
 
 
975
    def setUp(self):
 
976
        super(TestPatienceDiffLibFiles_c, self).setUp()
 
977
        import bzrlib._patiencediff_c
 
978
        self._PatienceSequenceMatcher = \
 
979
            bzrlib._patiencediff_c.PatienceSequenceMatcher_c
 
980
 
 
981
 
 
982
class TestUsingCompiledIfAvailable(TestCase):
 
983
 
 
984
    def test_PatienceSequenceMatcher(self):
 
985
        if CompiledPatienceDiffFeature.available():
 
986
            from bzrlib._patiencediff_c import PatienceSequenceMatcher_c
 
987
            self.assertIs(PatienceSequenceMatcher_c,
 
988
                          bzrlib.patiencediff.PatienceSequenceMatcher)
 
989
        else:
 
990
            from bzrlib._patiencediff_py import PatienceSequenceMatcher_py
 
991
            self.assertIs(PatienceSequenceMatcher_py,
 
992
                          bzrlib.patiencediff.PatienceSequenceMatcher)
 
993
 
 
994
    def test_unique_lcs(self):
 
995
        if CompiledPatienceDiffFeature.available():
 
996
            from bzrlib._patiencediff_c import unique_lcs_c
 
997
            self.assertIs(unique_lcs_c,
 
998
                          bzrlib.patiencediff.unique_lcs)
 
999
        else:
 
1000
            from bzrlib._patiencediff_py import unique_lcs_py
 
1001
            self.assertIs(unique_lcs_py,
 
1002
                          bzrlib.patiencediff.unique_lcs)
 
1003
 
 
1004
    def test_recurse_matches(self):
 
1005
        if CompiledPatienceDiffFeature.available():
 
1006
            from bzrlib._patiencediff_c import recurse_matches_c
 
1007
            self.assertIs(recurse_matches_c,
 
1008
                          bzrlib.patiencediff.recurse_matches)
 
1009
        else:
 
1010
            from bzrlib._patiencediff_py import recurse_matches_py
 
1011
            self.assertIs(recurse_matches_py,
 
1012
                          bzrlib.patiencediff.recurse_matches)