Commit 9942ed7d authored by Jelmer Vernooij's avatar Jelmer Vernooij

Fix tests.

parent c9d2a612
build
patiencediff.egg-info
......@@ -109,14 +109,14 @@ def unified_diff_files(a, b, sequencematcher=None):
file_a = sys.stdin
time_a = time.time()
else:
file_a = open(a, 'rb')
file_a = open(a, 'r')
time_a = os.stat(a).st_mtime
if b == '-':
file_b = sys.stdin
time_b = time.time()
else:
file_b = open(b, 'rb')
file_b = open(b, 'r')
time_b = os.stat(b).st_mtime
# TODO: Include fromfiledate and tofiledate
......
......@@ -1168,44 +1168,13 @@ static char PatienceSequenceMatcher_doc[] =
static PyTypeObject PatienceSequenceMatcherType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"PatienceSequenceMatcher", /* tp_name */
sizeof(PatienceSequenceMatcher), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)PatienceSequenceMatcher_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags*/
PatienceSequenceMatcher_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PatienceSequenceMatcher_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PatienceSequenceMatcher_new, /* tp_new */
.tp_name = "PatienceSequenceMatcher",
.tp_basicsize = sizeof(PatienceSequenceMatcher),
.tp_dealloc = (destructor)PatienceSequenceMatcher_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = PatienceSequenceMatcher_doc,
.tp_methods = PatienceSequenceMatcher_methods,
.tp_new = PatienceSequenceMatcher_new,
};
......
......@@ -14,9 +14,17 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import patiencediff
import shutil
import sys
import tempfile
import unittest
from . import _patiencediff_c, _patiencediff_py
from . import _patiencediff_py
if sys.version_info[0] == 3:
unichr = chr
class TestPatienceDiffLib(unittest.TestCase):
......@@ -411,11 +419,12 @@ pynff pzq_zxqve(Pbzznaq):
class TestPatienceDiffLib_c(TestPatienceDiffLib):
# TODO(jelmer): _test_needs_features = [features.compiled_patiencediff_feature]
def setUp(self):
super(TestPatienceDiffLib_c, self).setUp()
from . import _patiencediff_c
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 = \
......@@ -435,12 +444,14 @@ class TestPatienceDiffLib_c(TestPatienceDiffLib):
None, ['valid'], ['valid', []])
class TestPatienceDiffLibFiles(unittest.TestCaseInTempDir):
class TestPatienceDiffLibFiles(unittest.TestCase):
def setUp(self):
super(TestPatienceDiffLibFiles, self).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',
......@@ -465,8 +476,8 @@ class TestPatienceDiffLibFiles(unittest.TestCaseInTempDir):
txt_a = [x+'\n' for x in 'abcdefghijklmnop']
txt_b = [x+'\n' for x in 'abcdefxydefghijklmnop']
with open('a2', 'wb') as f: f.writelines(txt_a)
with open('b2', 'wb') as f: f.writelines(txt_b)
with open('a2', 'w') as f: f.writelines(txt_a)
with open('b2', 'w') as f: f.writelines(txt_b)
# This is the result with LongestCommonSubstring matching
self.assertEqual(['--- a2\n',
......@@ -506,11 +517,12 @@ class TestPatienceDiffLibFiles(unittest.TestCaseInTempDir):
class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
_test_needs_features = [features.compiled_patiencediff_feature]
def setUp(self):
super(TestPatienceDiffLibFiles_c, self).setUp()
from . import _patiencediff_c
try:
from . import _patiencediff_c
except ImportError:
self.skipTest('C extension not built')
self._PatienceSequenceMatcher = \
_patiencediff_c.PatienceSequenceMatcher_c
......@@ -518,32 +530,35 @@ class TestPatienceDiffLibFiles_c(TestPatienceDiffLibFiles):
class TestUsingCompiledIfAvailable(unittest.TestCase):
def test_PatienceSequenceMatcher(self):
if features.compiled_patiencediff_feature.available():
try:
from ._patiencediff_c import PatienceSequenceMatcher_c
self.assertIs(PatienceSequenceMatcher_c,
patiencediff.PatienceSequenceMatcher)
else:
except ImportError:
from ._patiencediff_py import PatienceSequenceMatcher_py
self.assertIs(PatienceSequenceMatcher_py,
patiencediff.PatienceSequenceMatcher)
else:
self.assertIs(PatienceSequenceMatcher_c,
patiencediff.PatienceSequenceMatcher)
def test_unique_lcs(self):
if features.compiled_patiencediff_feature.available():
try:
from ._patiencediff_c import unique_lcs_c
self.assertIs(unique_lcs_c,
patiencediff.unique_lcs)
else:
except ImportError:
from ._patiencediff_py import unique_lcs_py
self.assertIs(unique_lcs_py,
patiencediff.unique_lcs)
else:
self.assertIs(unique_lcs_c,
patiencediff.unique_lcs)
def test_recurse_matches(self):
if features.compiled_patiencediff_feature.available():
try:
from ._patiencediff_c import recurse_matches_c
self.assertIs(recurse_matches_c,
patiencediff.recurse_matches)
else:
except ImportError:
from ._patiencediff_py import recurse_matches_py
self.assertIs(recurse_matches_py,
patiencediff.recurse_matches)
else:
self.assertIs(recurse_matches_c,
patiencediff.recurse_matches)
......@@ -25,4 +25,5 @@ setup(name="patiencediff",
'Operating System :: POSIX',
],
ext_modules=[Extension('patiencediff._patiencediff_c',
['patiencediff/_patiencediff_c.c'])])
['patiencediff/_patiencediff_c.c'])]
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment