0
     »                          '+++ b\t2008-09-09\n',
                          '@@ -1,3 +1,2 @@\n',
                          ' hello there\n',
                          '-world\n',
                          ' how are you today?\n'
                          ], list(unified_diff(
                              txt_a, txt_b, fromfile='a', tofile='b',
                              fromfiledate='2008-08-08',
                              tofiledate='2008-09-09',
                              sequencematcher=psm)))


class TestPatienceDiffLib_c(TestPatienceDiffLib):

    def setUp(self):
        super().setUp()
        try:
            from . import _patiencediff_c
        except ImportError:
            self.skipTest('C extension not built')
        self._unique_lcs = _patiencediff_c.unique_lcs_c
        self._recurse_matches = _patiencediff_c.recurse_matches_c
        self._PatienceSequenceMatcher = \
            _patiencediff_c.PatienceSequenceMatcher_c

    def test_unhashable(self):
        """We should get a proper exception here."""
        # We need to be able to hash items in the sequence, lists are
        # unhashable, and thus cannot be diffed
        self.assertRaises(
            TypeError, self._PatienceSequenceMatcher, None, [[]], [])
        self.assertRaises(
            TypeError, self._PatienceSequenceMatcher, None,
            ['valid', []], [])
        self.assertRaises(
            TypeError, self._PatienceSequenceMatcher, None, ['valid'], [[]])
        self.assertRaises(
            TypeError, self._PatienceSequenceMatcher, None, ['valid'],
            ['valid', []])


class TestPatienceDiffLibFiles(unittest.TestCase):

    def setUp(self):
        super().setUp()
        self._PatienceSequenceMatcher = \
            _patiencediff_py.PatienceSequenceMatcher_py
        self.test_dir = tempfile.mkdtemp()
        self.addCleanup(lambda: shutil.rmtree(self.test_dir))

    def test_patience_unified_diff_files(self):
        txt_a = [b'hello there\n',
                 b'world\n',
                 b'how are you today?\n']
        txt_b = [b'hello there\n',
                 b'how are you today?\n']
        with open(os.path.join(self.test_dir, 'a1'), 'wb') as f:
            f.writelines(txt_a)
        with open(os.path.join(self.test_dir, 'b1'), 'wb') as f:
            f.writelines(txt_b)

        unified_diff_files = patiencediff.unified_diff_files
        psm = self._PatienceSequenceMatcher

        old_pwd = os.getcwd()
        os.chdir(self.test_dir)
        try:
            self.assertEqual(['--- a1\n',
                              '+++ b1\n',
                              '@@ -1,3 +1,2 @@\n',
                              ' hello there\n',
                              '-world\n',
                              ' how are you today?\n',
                              ], list(unified_diff_files(
                                  'a1', 'b1', sequencematcher=psm)))
        finally:
            os.chdir(old_pwd)

        txt_a = [x+'\n' for x in 'abcdefghijklmnop']
        txt_b = [x+'\n' for x in 'abcdefxydefghijklmnop']
        with open(os.path.join(self.test_dir, 'a2'), 'w') as f:
            f.writelines(txt_a)
        with open(os.path.join(self.test_dir, 'b2'), 'w') as f:
            f.writelines(txt_b)

        # This is the result with LongestCommonSubstring matching
        os.chdir(self.test_dir)
        try:
            self.assertEqual(['--- a2\n',
                              '+++ b2\n',
                              '@@ -1,6 +1,11 @@\n',
                              ' a\n',
                              ' b\n',
                              ' c\n',
                              '+d\n',
                              '+e\n',
                              '+f\n',
                              '+x\n',
                              '+y\n',
                              ' d\n',
                              ' e\n',
                              ' f\n'], list(unified_diff_files('a2', 'b2')))

            # And the patience diff
            self.assertEqual(['--- a2\n',
                         