summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_capi.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-03-09 18:03:38 (GMT)
committerGitHub <noreply@github.com>2020-03-09 18:03:38 (GMT)
commite5ccc94bbb153431698b2391df625e8d47a93276 (patch)
tree82c6656cd615dc3ae3311d42d2ef580fa1d8e4d8 /Lib/test/test_capi.py
parent413f01352a8268fb62bb47bde965462d7b82a06a (diff)
downloadcpython-e5ccc94bbb153431698b2391df625e8d47a93276.zip
cpython-e5ccc94bbb153431698b2391df625e8d47a93276.tar.gz
cpython-e5ccc94bbb153431698b2391df625e8d47a93276.tar.bz2
bpo-38643: Raise SystemError instead of crashing when PyNumber_ToBase is called with invalid base. (GH-18863)
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r--Lib/test/test_capi.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index ff18a21..5a85c48 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -502,6 +502,20 @@ class CAPITest(unittest.TestCase):
# Test that subtype_dealloc decref the newly assigned __class__ only once
self.assertEqual(new_type_refcnt, sys.getrefcount(_testcapi.HeapCTypeSubclass))
+ 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)
+
class TestPendingCalls(unittest.TestCase):