|
12 | 12 |
|
13 | 13 | import pytest
|
14 | 14 |
|
15 |
| -from hypothesis import assume, given |
| 15 | +from hypothesis import given |
16 | 16 | from hypothesis.strategies import booleans
|
17 | 17 |
|
18 | 18 | import attr
|
|
21 | 21 | from attr._make import NOTHING, Attribute
|
22 | 22 | from attr.exceptions import FrozenInstanceError
|
23 | 23 |
|
24 |
| -from .strategies import optional_bool |
25 |
| - |
26 | 24 |
|
27 | 25 | @attr.s
|
28 | 26 | class C1:
|
@@ -643,44 +641,19 @@ class C:
|
643 | 641 |
|
644 | 642 | assert ei.value.args[0] in possible_errors
|
645 | 643 |
|
646 |
| - @given(cmp=optional_bool, eq=optional_bool, order=optional_bool) |
647 |
| - def test_cmp_deprecated_attribute(self, cmp, eq, order): |
| 644 | + @pytest.mark.parametrize("slots", [True, False]) |
| 645 | + @pytest.mark.parametrize("cmp", [True, False]) |
| 646 | + def test_attrib_cmp_shortcut(self, slots, cmp): |
648 | 647 | """
|
649 |
| - Accessing Attribute.cmp raises a deprecation warning but returns True |
650 |
| - if cmp is True, or eq and order are *both* effectively True. |
| 648 | + Setting cmp on `attr.ib`s sets both eq and order. |
651 | 649 | """
|
652 |
| - # These cases are invalid and raise a ValueError. |
653 |
| - assume(cmp is None or (eq is None and order is None)) |
654 |
| - assume(not (eq is False and order is True)) |
655 |
| - |
656 |
| - if cmp is not None: |
657 |
| - rv = cmp |
658 |
| - elif eq is True or eq is None: |
659 |
| - rv = order is None or order is True |
660 |
| - elif cmp is None and eq is None and order is None: |
661 |
| - rv = True |
662 |
| - elif cmp is None or eq is None: |
663 |
| - rv = False |
664 |
| - else: |
665 |
| - pytest.fail( |
666 |
| - "Unexpected state: cmp=%r eq=%r order=%r" % (cmp, eq, order) |
667 |
| - ) |
668 |
| - |
669 |
| - with pytest.deprecated_call() as dc: |
670 |
| - |
671 |
| - @attr.s |
672 |
| - class C: |
673 |
| - x = attr.ib(cmp=cmp, eq=eq, order=order) |
674 | 650 |
|
675 |
| - assert rv == attr.fields(C).x.cmp |
676 |
| - |
677 |
| - (w,) = dc.list |
| 651 | + @attr.s(slots=slots) |
| 652 | + class C: |
| 653 | + x = attr.ib(cmp=cmp) |
678 | 654 |
|
679 |
| - assert ( |
680 |
| - "The usage of `cmp` is deprecated and will be removed on or after " |
681 |
| - "2021-06-01. Please use `eq` and `order` instead." |
682 |
| - == w.message.args[0] |
683 |
| - ) |
| 655 | + assert cmp is attr.fields(C).x.eq |
| 656 | + assert cmp is attr.fields(C).x.order |
684 | 657 |
|
685 | 658 | @pytest.mark.parametrize("slots", [True, False])
|
686 | 659 | def test_no_setattr_if_validate_without_validators(self, slots):
|
|
0 commit comments