Skip to content

Commit 416d88d

Browse files
committed
Add test demonstrating total_ordering
1 parent e677845 commit 416d88d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/test_make.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import absolute_import, division, print_function
66

77
import copy
8+
import functools
89
import gc
910
import inspect
1011
import itertools
@@ -1957,3 +1958,42 @@ class C(object):
19571958
assert 1 == len(recwarn.list)
19581959
else:
19591960
assert 0 == len(recwarn.list)
1961+
1962+
@pytest.mark.parametrize("slots", [True, False])
1963+
def test_total_ordering(self, slots):
1964+
"""
1965+
functools.total_ordering works as expected if an order method and an eq
1966+
method are detected.
1967+
"""
1968+
1969+
@attr.s(auto_detect=True, slots=slots)
1970+
@functools.total_ordering
1971+
class C(object):
1972+
x = attr.ib()
1973+
own_eq_called = attr.ib(default=False)
1974+
own_le_called = attr.ib(default=False)
1975+
1976+
def __eq__(self, o):
1977+
self.own_eq_called = True
1978+
return self.x == o.x
1979+
1980+
def __le__(self, o):
1981+
self.own_le_called = True
1982+
return self.x <= o.x
1983+
1984+
c1, c2 = C(1), C(2)
1985+
1986+
assert c1 < c2
1987+
assert c1.own_le_called
1988+
1989+
c1, c2 = C(1), C(2)
1990+
1991+
assert c2 > c1
1992+
assert c2.own_le_called
1993+
1994+
c1, c2 = C(1), C(2)
1995+
1996+
assert c2 != c1
1997+
assert c1 == c1
1998+
1999+
assert c1.own_eq_called

0 commit comments

Comments
 (0)