FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test_numeric_tower.py from Cpython v3.11.2 by Masorubka1 · Pull Request #4843 · RustPython/RustPython · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
30 changes: 30 additions & 0 deletions Lib/test/test_numeric_tower.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@
_PyHASH_MODULUS = sys.hash_info.modulus
_PyHASH_INF = sys.hash_info.inf


class DummyIntegral(int):
"""Dummy Integral class to test conversion of the Rational to float."""

def __mul__(self, other):
return DummyIntegral(super().__mul__(other))
__rmul__ = __mul__

def __truediv__(self, other):
return NotImplemented
__rtruediv__ = __truediv__

@property
def numerator(self):
return DummyIntegral(self)

@property
def denominator(self):
return DummyIntegral(1)


class HashTest(unittest.TestCase):
def check_equal_hash(self, x, y):
# check both that x and y are equal and that their hashes are equal
Expand Down Expand Up @@ -113,6 +134,8 @@ def test_decimals(self):
self.check_equal_hash(D('12300.00'), D(12300))
self.check_equal_hash(D('12300.000'), D(12300))

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_fractions(self):
# check special case for fractions where either the numerator
# or the denominator is a multiple of _PyHASH_MODULUS
Expand All @@ -121,6 +144,13 @@ def test_fractions(self):
self.assertEqual(hash(F(7*_PyHASH_MODULUS, 1)), 0)
self.assertEqual(hash(F(-_PyHASH_MODULUS, 1)), 0)

# The numbers ABC doesn't enforce that the "true" division
# of integers produces a float. This tests that the
# Rational.__float__() method has required type conversions.
x = F(DummyIntegral(1), DummyIntegral(2), _normalize=False)
self.assertRaises(TypeError, lambda: x.numerator/x.denominator)
self.assertEqual(float(x), 0.5)

def test_hash_normalization(self):
# Test for a bug encountered while changing long_hash.
#
Expand Down

Back | FazBrowse Home | New Git URL