mirror of
https://github.com/python/cpython.git
synced 2025-11-24 12:20:42 +00:00
[3.14] gh-138669: Increase test coverage for difflib (GH-138670) (#138817)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Check if the ABI has changed (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
Co-authored-by: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com>
This commit is contained in:
parent
18dfc1d6c4
commit
80e59a8d7e
1 changed files with 39 additions and 0 deletions
|
|
@ -29,6 +29,16 @@ class TestWithAscii(unittest.TestCase):
|
|||
('delete', 40, 41, 40, 40),
|
||||
('equal', 41, 81, 40, 80)])
|
||||
|
||||
def test_opcode_caching(self):
|
||||
sm = difflib.SequenceMatcher(None, 'b' * 100, 'a' + 'b' * 100)
|
||||
opcode = sm.get_opcodes()
|
||||
self.assertEqual(opcode,
|
||||
[ ('insert', 0, 0, 0, 1),
|
||||
('equal', 0, 100, 1, 101)])
|
||||
# Implementation detail: opcodes are cached;
|
||||
# `get_opcodes()` returns the same object
|
||||
self.assertIs(opcode, sm.get_opcodes())
|
||||
|
||||
def test_bjunk(self):
|
||||
sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ',
|
||||
a='a' * 40 + 'b' * 40, b='a' * 44 + 'b' * 40)
|
||||
|
|
@ -293,6 +303,15 @@ class TestDiffer(unittest.TestCase):
|
|||
'+ kitten\n',
|
||||
'+ puppy\n'])
|
||||
|
||||
def test_one_insert(self):
|
||||
m = difflib.Differ().compare('b' * 2, 'a' + 'b' * 2)
|
||||
self.assertEqual(list(m), ['+ a', ' b', ' b'])
|
||||
|
||||
def test_one_delete(self):
|
||||
m = difflib.Differ().compare('a' + 'b' * 2, 'b' * 2)
|
||||
self.assertEqual(list(m), ['- a', ' b', ' b'])
|
||||
|
||||
|
||||
class TestOutputFormat(unittest.TestCase):
|
||||
def test_tab_delimiter(self):
|
||||
args = [['one'], ['two'], 'Original', 'Current',
|
||||
|
|
@ -585,6 +604,26 @@ class TestFindLongest(unittest.TestCase):
|
|||
self.assertFalse(self.longer_match_exists(a, b, match.size))
|
||||
|
||||
|
||||
class TestCloseMatches(unittest.TestCase):
|
||||
# Happy paths are tested in the doctests of `difflib.get_close_matches`.
|
||||
|
||||
def test_invalid_inputs(self):
|
||||
self.assertRaises(ValueError, difflib.get_close_matches, "spam", ['egg'], n=0)
|
||||
self.assertRaises(ValueError, difflib.get_close_matches, "spam", ['egg'], n=-1)
|
||||
self.assertRaises(ValueError, difflib.get_close_matches, "spam", ['egg'], cutoff=1.1)
|
||||
self.assertRaises(ValueError, difflib.get_close_matches, "spam", ['egg'], cutoff=-0.1)
|
||||
|
||||
|
||||
class TestRestore(unittest.TestCase):
|
||||
# Happy paths are tested in the doctests of `difflib.restore`.
|
||||
|
||||
def test_invalid_input(self):
|
||||
with self.assertRaises(ValueError):
|
||||
''.join(difflib.restore([], 0))
|
||||
with self.assertRaises(ValueError):
|
||||
''.join(difflib.restore([], 3))
|
||||
|
||||
|
||||
def setUpModule():
|
||||
difflib.HtmlDiff._default_prefix = 0
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue