File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 5
5
from __future__ import absolute_import , division , print_function
6
6
7
7
import copy
8
+ import functools
8
9
import gc
9
10
import inspect
10
11
import itertools
@@ -1957,3 +1958,42 @@ class C(object):
1957
1958
assert 1 == len (recwarn .list )
1958
1959
else :
1959
1960
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
You can’t perform that action at this time.
0 commit comments