|
8 | 8 | from collections.abc import Iterable
|
9 | 9 | from collections.abc import Mapping
|
10 | 10 | from collections.abc import Sequence
|
11 |
| -from collections.abc import Set as AbstractSet |
12 | 11 | import os
|
13 | 12 | import pprint
|
14 | 13 | from typing import Any
|
15 | 14 | from typing import Literal
|
16 |
| -from typing import Protocol |
17 | 15 | from unicodedata import normalize
|
18 | 16 |
|
19 | 17 | from _pytest import outcomes
|
20 | 18 | import _pytest._code
|
21 | 19 | from _pytest._io.pprint import PrettyPrinter
|
22 | 20 | from _pytest._io.saferepr import saferepr
|
23 | 21 | from _pytest._io.saferepr import saferepr_unlimited
|
| 22 | +from _pytest.assertion._compare_set import _compare_eq_set |
| 23 | +from _pytest.assertion._compare_set import _compare_gt_set |
| 24 | +from _pytest.assertion._compare_set import _compare_gte_set |
| 25 | +from _pytest.assertion._compare_set import _compare_lt_set |
| 26 | +from _pytest.assertion._compare_set import _compare_lte_set |
| 27 | +from _pytest.assertion._typing import _HighlightFunc |
24 | 28 | from _pytest.config import Config
|
25 | 29 |
|
26 | 30 |
|
|
38 | 42 | _config: Config | None = None
|
39 | 43 |
|
40 | 44 |
|
41 |
| -class _HighlightFunc(Protocol): |
42 |
| - def __call__(self, source: str, lexer: Literal["diff", "python"] = "python") -> str: |
43 |
| - """Apply highlighting to the given source.""" |
44 |
| - |
45 |
| - |
46 | 45 | def dummy_highlighter(source: str, lexer: Literal["diff", "python"] = "python") -> str:
|
47 | 46 | """Dummy highlighter that returns the text unprocessed.
|
48 | 47 |
|
@@ -426,75 +425,6 @@ def _compare_eq_sequence(
|
426 | 425 | return explanation
|
427 | 426 |
|
428 | 427 |
|
429 |
| -def _compare_eq_set( |
430 |
| - left: AbstractSet[Any], |
431 |
| - right: AbstractSet[Any], |
432 |
| - highlighter: _HighlightFunc, |
433 |
| - verbose: int = 0, |
434 |
| -) -> list[str]: |
435 |
| - explanation = [] |
436 |
| - explanation.extend(_set_one_sided_diff("left", left, right, highlighter)) |
437 |
| - explanation.extend(_set_one_sided_diff("right", right, left, highlighter)) |
438 |
| - return explanation |
439 |
| - |
440 |
| - |
441 |
| -def _compare_gt_set( |
442 |
| - left: AbstractSet[Any], |
443 |
| - right: AbstractSet[Any], |
444 |
| - highlighter: _HighlightFunc, |
445 |
| - verbose: int = 0, |
446 |
| -) -> list[str]: |
447 |
| - explanation = _compare_gte_set(left, right, highlighter) |
448 |
| - if not explanation: |
449 |
| - return ["Both sets are equal"] |
450 |
| - return explanation |
451 |
| - |
452 |
| - |
453 |
| -def _compare_lt_set( |
454 |
| - left: AbstractSet[Any], |
455 |
| - right: AbstractSet[Any], |
456 |
| - highlighter: _HighlightFunc, |
457 |
| - verbose: int = 0, |
458 |
| -) -> list[str]: |
459 |
| - explanation = _compare_lte_set(left, right, highlighter) |
460 |
| - if not explanation: |
461 |
| - return ["Both sets are equal"] |
462 |
| - return explanation |
463 |
| - |
464 |
| - |
465 |
| -def _compare_gte_set( |
466 |
| - left: AbstractSet[Any], |
467 |
| - right: AbstractSet[Any], |
468 |
| - highlighter: _HighlightFunc, |
469 |
| - verbose: int = 0, |
470 |
| -) -> list[str]: |
471 |
| - return _set_one_sided_diff("right", right, left, highlighter) |
472 |
| - |
473 |
| - |
474 |
| -def _compare_lte_set( |
475 |
| - left: AbstractSet[Any], |
476 |
| - right: AbstractSet[Any], |
477 |
| - highlighter: _HighlightFunc, |
478 |
| - verbose: int = 0, |
479 |
| -) -> list[str]: |
480 |
| - return _set_one_sided_diff("left", left, right, highlighter) |
481 |
| - |
482 |
| - |
483 |
| -def _set_one_sided_diff( |
484 |
| - posn: str, |
485 |
| - set1: AbstractSet[Any], |
486 |
| - set2: AbstractSet[Any], |
487 |
| - highlighter: _HighlightFunc, |
488 |
| -) -> list[str]: |
489 |
| - explanation = [] |
490 |
| - diff = set1 - set2 |
491 |
| - if diff: |
492 |
| - explanation.append(f"Extra items in the {posn} set:") |
493 |
| - for item in diff: |
494 |
| - explanation.append(highlighter(saferepr(item))) |
495 |
| - return explanation |
496 |
| - |
497 |
| - |
498 | 428 | def _compare_eq_dict(
|
499 | 429 | left: Mapping[Any, Any],
|
500 | 430 | right: Mapping[Any, Any],
|
|
0 commit comments