MCPcopy Index your code
hub / github.com/python/cpython / test_levenshtein_distance_short_circuit

Method test_levenshtein_distance_short_circuit

Lib/test/test_traceback.py:5118–5140  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5116
5117 @support.requires_resource('cpu')
5118 def test_levenshtein_distance_short_circuit(self):
5119 if not LEVENSHTEIN_DATA_FILE.is_file():
5120 self.fail(
5121 f"{LEVENSHTEIN_DATA_FILE} is missing."
5122 f" Run `make regen-test-levenshtein`"
5123 )
5124
5125 with LEVENSHTEIN_DATA_FILE.open("r") as f:
5126 examples = json.load(f)
5127 for a, b, expected in examples:
5128 res1 = traceback._levenshtein_distance(a, b, 1000)
5129 self.assertEqual(res1, expected, msg=(a, b))
5130
5131 for threshold in [expected, expected + 1, expected + 2]:
5132 # big enough thresholds shouldn't change the result
5133 res2 = traceback._levenshtein_distance(a, b, threshold)
5134 self.assertEqual(res2, expected, msg=(a, b, threshold))
5135
5136 for threshold in range(expected):
5137 # for small thresholds, the only piece of information
5138 # we receive is "strings not close enough".
5139 res3 = traceback._levenshtein_distance(a, b, threshold)
5140 self.assertGreater(res3, threshold, msg=(a, b, threshold))
5141
5142 @cpython_only
5143 def test_suggestions_extension(self):

Callers

nothing calls this directly

Calls 6

assertGreaterMethod · 0.80
is_fileMethod · 0.45
failMethod · 0.45
openMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected