14
14
_PyHASH_MODULUS = sys .hash_info .modulus
15
15
_PyHASH_INF = sys .hash_info .inf
16
16
17
+
18
+ class DummyIntegral (int ):
19
+ """Dummy Integral class to test conversion of the Rational to float."""
20
+
21
+ def __mul__ (self , other ):
22
+ return DummyIntegral (super ().__mul__ (other ))
23
+ __rmul__ = __mul__
24
+
25
+ def __truediv__ (self , other ):
26
+ return NotImplemented
27
+ __rtruediv__ = __truediv__
28
+
29
+ @property
30
+ def numerator (self ):
31
+ return DummyIntegral (self )
32
+
33
+ @property
34
+ def denominator (self ):
35
+ return DummyIntegral (1 )
36
+
37
+
17
38
class HashTest (unittest .TestCase ):
18
39
def check_equal_hash (self , x , y ):
19
40
# check both that x and y are equal and that their hashes are equal
@@ -113,6 +134,8 @@ def test_decimals(self):
113
134
self .check_equal_hash (D ('12300.00' ), D (12300 ))
114
135
self .check_equal_hash (D ('12300.000' ), D (12300 ))
115
136
137
+ # TODO: RUSTPYTHON
138
+ @unittest .expectedFailure
116
139
def test_fractions (self ):
117
140
# check special case for fractions where either the numerator
118
141
# or the denominator is a multiple of _PyHASH_MODULUS
@@ -121,6 +144,13 @@ def test_fractions(self):
121
144
self .assertEqual (hash (F (7 * _PyHASH_MODULUS , 1 )), 0 )
122
145
self .assertEqual (hash (F (- _PyHASH_MODULUS , 1 )), 0 )
123
146
147
+ # The numbers ABC doesn't enforce that the "true" division
148
+ # of integers produces a float. This tests that the
149
+ # Rational.__float__() method has required type conversions.
150
+ x = F (DummyIntegral (1 ), DummyIntegral (2 ), _normalize = False )
151
+ self .assertRaises (TypeError , lambda : x .numerator / x .denominator )
152
+ self .assertEqual (float (x ), 0.5 )
153
+
124
154
def test_hash_normalization (self ):
125
155
# Test for a bug encountered while changing long_hash.
126
156
#
0 commit comments