(self)
| 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): |
nothing calls this directly
no test coverage detected