-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Incomplete test coverage of PyNumber_ToBase
#93884
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
Comments
Please could you clarify which tests you're looking at? I'm not seeing any direct C-level tests of |
I guess you are trying to add the following test cases. I have run those cases on Windows and they work well. :)
def test_pynumber_tobase(self):
from _testcapi import pynumber_tobase
self.assertEqual(pynumber_tobase(123, 2), '0b1111011')
self.assertEqual(pynumber_tobase(123, 8), '0o173')
self.assertEqual(pynumber_tobase(123, 10), '123')
self.assertEqual(pynumber_tobase(123, 16), '0x7b')
self.assertEqual(pynumber_tobase(-123, 2), '-0b1111011')
self.assertEqual(pynumber_tobase(-123, 8), '-0o173')
self.assertEqual(pynumber_tobase(-123, 10), '-123')
self.assertEqual(pynumber_tobase(-123, 16), '-0x7b')
self.assertRaises(TypeError, pynumber_tobase, 123.0, 10)
self.assertRaises(TypeError, pynumber_tobase, '123', 10)
self.assertRaises(SystemError, pynumber_tobase, 123, 0)
# Test for large number(out of range of a longlong,i.e.[-2**63, 2**63-1])
large_number = 2**64
self.assertEqual(pynumber_tobase(large_number, 2),
'0b10000000000000000000000000000000000000000000000000000000000000000')
self.assertEqual(pynumber_tobase(large_number, 8),'0o2000000000000000000000')
self.assertEqual(pynumber_tobase(large_number, 10),'18446744073709551616')
self.assertEqual(pynumber_tobase(large_number, 16),'0x10000000000000000')
# Test for large negative number
self.assertEqual(pynumber_tobase(-large_number, 2),
'-0b10000000000000000000000000000000000000000000000000000000000000000')
self.assertEqual(pynumber_tobase(-large_number, 8),'-0o2000000000000000000000')
self.assertEqual(pynumber_tobase(-large_number, 10),'-18446744073709551616')
self.assertEqual(pynumber_tobase(-large_number, 16),'-0x10000000000000000') |
@JustAnotherArchivist @CharlieZhao95 I think you're both referring to test cases that are in PyPy's test suite, not CPython's. In CPython the In particular, I don't think there's a whole lot of value adding direct C-API tests for That said, the tests for |
@mdickinson The @CharlieZhao95 That's pretty much what I had in mind, yes. Plus tests for the |
(Side note: |
Thanks! Sorry about that - I missed that I was looking at an old checkout locally. |
More or less, yes. There's a difference for subclasses of |
@JustAnotherArchivist I find that those cases you're talking about are already mentioned in file # bad index
def test_error(self):
self.o.ind = 'dumb'
self.n.ind = 'bad'
self.assertRaises(TypeError, operator.index, self.o)
self.assertRaises(TypeError, operator.index, self.n)
self.assertRaises(TypeError, slice(self.o).indices, 0)
self.assertRaises(TypeError, slice(self.n).indices, 0)
....
# large numbers
class OverflowTestCase(unittest.TestCase):
def setUp(self):
self.pos = 2**100
self.neg = -self.pos
def test_large_longs(self):
self.assertEqual(self.pos.__index__(), self.pos)
self.assertEqual(self.neg.__index__(), self.neg)
.... Maybe we could focus more on testing the |
@CharlieZhao95 Yeah, they're tested directly, but I meant testing that As for the |
Link to #93884 * Test with some large negative and positive values(out of range of a longlong,i.e.[-2\*\*63, 2\*\*63-1]) * Test with objects of non-int type Automerge-Triggered-By: GH:mdickinson
Uh oh!
There was an error while loading. Please reload this page.
I discovered that the tests for
PyNumber_ToBase
only ever check one smallint
value's conversions. The function description and implementation makes it quite clear that the intent is to support arbitrary ints, as would be expected for a function working with Pythonint
s. Tests should be added for some large negative and positive values in different bases to ensure that that's indeed the case and also for thePyNumber_Index
conversion part.(This has likely contributed to a bug in PyPy, namely that the function only accepts values in the
int64_t
range in PyPy: https://foss.heptapod.net/pypy/pypy/-/issues/3765)The text was updated successfully, but these errors were encountered: