Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-102837: few coverage nitpicks for the math module #102523

Merged
merged 20 commits into from
Sep 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests for bad __floor__/__ceil__ descriptors (cover L1165, L1236)
  • Loading branch information
skirpichev committed Sep 2, 2023
commit 6498162bdf0944d3eb16e9d7e13845b31275d2e5
12 changes: 12 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,16 @@ def __ceil__(self):
return 42
class TestNoCeil:
pass
class TestBadCeil:
class BadCeil:
def __get__(self, obj, objtype=None):
raise ValueError
__ceil__ = BadCeil()
self.assertEqual(math.ceil(TestCeil()), 42)
self.assertEqual(math.ceil(FloatCeil()), 42)
self.assertEqual(math.ceil(FloatLike(42.5)), 43)
self.assertRaises(TypeError, math.ceil, TestNoCeil())
self.assertRaises(ValueError, math.ceil, TestBadCeil())

t = TestNoCeil()
t.__ceil__ = lambda *args: args
Expand Down Expand Up @@ -571,10 +577,16 @@ def __floor__(self):
return 42
class TestNoFloor:
pass
class TestBadFloor:
class BadFloor:
def __get__(self, obj, objtype=None):
raise ValueError
__floor__ = BadFloor()
self.assertEqual(math.floor(TestFloor()), 42)
self.assertEqual(math.floor(FloatFloor()), 42)
self.assertEqual(math.floor(FloatLike(41.9)), 41)
self.assertRaises(TypeError, math.floor, TestNoFloor())
self.assertRaises(ValueError, math.floor, TestBadFloor())

t = TestNoFloor()
t.__floor__ = lambda *args: args
Expand Down
Loading