~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-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Development 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
26
25
import bzrlib.patiencediff
27
 
import bzrlib._patiencediff_py
28
 
from bzrlib.tests import (Feature, TestCase, TestCaseWithTransport,
 
26
from bzrlib.tests import (TestCase, TestCaseWithTransport,
29
27
                          TestCaseInTempDir, TestSkipped)
30
28
 
31
29
 
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
 
 
76
30
def udiff_lines(old, new, allow_binary=False):
77
31
    output = StringIO()
78
32
    internal_diff('old', old, 'new', new, output, allow_binary)
157
111
        self.check_patch(lines)
158
112
 
159
113
    def test_external_diff_binary_lang_c(self):
160
 
        old_env = {}
161
 
        for lang in ('LANG', 'LC_ALL', 'LANGUAGE'):
162
 
            old_env[lang] = osutils.set_or_unset_env(lang, 'C')
 
114
        orig_lang = os.environ.get('LANG')
163
115
        try:
 
116
            os.environ['LANG'] = 'C'
164
117
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
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'])
 
118
            self.assertEqual(['Binary files old and new differ\n', '\n'], lines)
170
119
        finally:
171
 
            for lang, old_val in old_env.iteritems():
172
 
                osutils.set_or_unset_env(lang, old_val)
 
120
            if orig_lang is None:
 
121
                del os.environ['LANG']
 
122
            else:
 
123
                os.environ['LANG'] = orig_lang
173
124
 
174
125
    def test_no_external_diff(self):
175
126
        """Check that NoDiff is raised when diff is not available"""
247
198
        # Make sure external_diff doesn't fail in the current LANG
248
199
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
249
200
 
250
 
        cmd = ['diff', '-u', '--binary', 'old', 'new']
 
201
        cmd = ['diff', '-u', 'old', 'new']
251
202
        open('old', 'wb').write('\x00foobar\n')
252
203
        open('new', 'wb').write('foo\x00bar\n')
253
204
        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
259
210
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
260
211
 
261
212
 
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):
 
213
class TestDiffDates(TestCaseWithTransport):
278
214
 
279
215
    def setUp(self):
280
216
        super(TestDiffDates, self).setUp()
314
250
        # set the date stamps for files in the working tree to known values
315
251
        os.utime('file1', (1144195200, 1144195200)) # 2006-04-05 00:00:00 UTC
316
252
 
 
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
 
317
264
    def test_diff_rev_tree_working_tree(self):
318
265
        output = self.get_diff(self.wt.basis_tree(), self.wt)
319
266
        # note that the date for old/file1 is from rev 2 rather than from
403
350
        self.assertNotContainsRe(out, 'file1\t')
404
351
 
405
352
 
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
 
 
547
353
class TestPatienceDiffLib(TestCase):
548
354
 
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
 
 
556
355
    def test_unique_lcs(self):
557
 
        unique_lcs = self._unique_lcs
 
356
        unique_lcs = bzrlib.patiencediff.unique_lcs
558
357
        self.assertEquals(unique_lcs('', ''), [])
559
 
        self.assertEquals(unique_lcs('', 'a'), [])
560
 
        self.assertEquals(unique_lcs('a', ''), [])
561
358
        self.assertEquals(unique_lcs('a', 'a'), [(0,0)])
562
359
        self.assertEquals(unique_lcs('a', 'b'), [])
563
360
        self.assertEquals(unique_lcs('ab', 'ab'), [(0,0), (1,1)])
570
367
    def test_recurse_matches(self):
571
368
        def test_one(a, b, matches):
572
369
            test_matches = []
573
 
            self._recurse_matches(
574
 
                a, b, 0, 0, len(a), len(b), test_matches, 10)
 
370
            bzrlib.patiencediff.recurse_matches(a, b, 0, 0, len(a), len(b),
 
371
                test_matches, 10)
575
372
            self.assertEquals(test_matches, matches)
576
373
 
577
374
        test_one(['a', '', 'b', '', 'c'], ['a', 'a', 'b', 'c', 'c'],
578
375
                 [(0, 0), (2, 2), (4, 4)])
579
376
        test_one(['a', 'c', 'b', 'a', 'c'], ['a', 'b', 'c'],
580
377
                 [(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)])
586
378
 
587
379
        # recurse_matches doesn't match non-unique 
588
380
        # lines surrounded by bogus text.
598
390
        def chk_blocks(a, b, expected_blocks):
599
391
            # difflib always adds a signature of the total
600
392
            # length, with no matching entries at the end
601
 
            s = self._PatienceSequenceMatcher(None, a, b)
 
393
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
602
394
            blocks = s.get_matching_blocks()
603
395
            self.assertEquals((len(a), len(b), 0), blocks[-1])
604
396
            self.assertEquals(expected_blocks, blocks[:-1])
606
398
        # Some basic matching tests
607
399
        chk_blocks('', '', [])
608
400
        chk_blocks([], [], [])
609
 
        chk_blocks('abc', '', [])
610
 
        chk_blocks('', 'abc', [])
611
401
        chk_blocks('abcd', 'abcd', [(0, 0, 4)])
612
402
        chk_blocks('abcd', 'abce', [(0, 0, 3)])
613
403
        chk_blocks('eabc', 'abce', [(1, 0, 3)])
652
442
 
653
443
    def test_opcodes(self):
654
444
        def chk_ops(a, b, expected_codes):
655
 
            s = self._PatienceSequenceMatcher(None, a, b)
 
445
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
656
446
            self.assertEquals(expected_codes, s.get_opcodes())
657
447
 
658
448
        chk_ops('', '', [])
659
449
        chk_ops([], [], [])
660
 
        chk_ops('abc', '', [('delete', 0,3, 0,0)])
661
 
        chk_ops('', 'abc', [('insert', 0,0, 0,3)])
662
450
        chk_ops('abcd', 'abcd', [('equal',    0,4, 0,4)])
663
451
        chk_ops('abcd', 'abce', [('equal',   0,3, 0,3),
664
452
                                 ('replace', 3,4, 3,4)
726
514
                 ('equal',   10,11, 8,9)
727
515
                ])
728
516
 
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
 
 
766
517
    def test_multiple_ranges(self):
767
518
        # There was an earlier bug where we used a bad set of ranges,
768
519
        # this triggers that specific bug, to make sure it doesn't regress
769
520
        def chk_blocks(a, b, expected_blocks):
770
521
            # difflib always adds a signature of the total
771
522
            # length, with no matching entries at the end
772
 
            s = self._PatienceSequenceMatcher(None, a, b)
 
523
            s = bzrlib.patiencediff.PatienceSequenceMatcher(None, a, b)
773
524
            blocks = s.get_matching_blocks()
774
525
            x = blocks.pop()
775
526
            self.assertEquals(x, (len(a), len(b), 0))
837
588
        txt_b = ['hello there\n',
838
589
                 'how are you today?\n']
839
590
        unified_diff = bzrlib.patiencediff.unified_diff
840
 
        psm = self._PatienceSequenceMatcher
 
591
        psm = bzrlib.patiencediff.PatienceSequenceMatcher
841
592
        self.assertEquals([ '---  \n',
842
593
                           '+++  \n',
843
594
                           '@@ -1,3 +1,2 @@\n',
885
636
                                 sequencematcher=psm)))
886
637
 
887
638
 
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
 
 
901
639
class TestPatienceDiffLibFiles(TestCaseInTempDir):
902
640
 
903
 
    def setUp(self):
904
 
        super(TestPatienceDiffLibFiles, self).setUp()
905
 
        self._PatienceSequenceMatcher = \
906
 
            bzrlib._patiencediff_py.PatienceSequenceMatcher_py
907
 
 
908
641
    def test_patience_unified_diff_files(self):
909
642
        txt_a = ['hello there\n',
910
643
                 'world\n',
915
648
        open('b1', 'wb').writelines(txt_b)
916
649
 
917
650
        unified_diff_files = bzrlib.patiencediff.unified_diff_files
918
 
        psm = self._PatienceSequenceMatcher
 
651
        psm = bzrlib.patiencediff.PatienceSequenceMatcher
919
652
        self.assertEquals(['--- a1 \n',
920
653
                           '+++ b1 \n',
921
654
                           '@@ -1,3 +1,2 @@\n',
966
699
                          ]
967
700
                          , list(unified_diff_files('a2', 'b2',
968
701
                                 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)