summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-03-12 07:30:56 (GMT)
committerGitHub <noreply@github.com>2020-03-12 07:30:56 (GMT)
commitab9c72912178cfdb4d0637be036d78913b769154 (patch)
tree77073e14869d7d6dd3d571fff812d6984d379dd2 /Lib/test
parent99ef1ac9a7793dcdf624d2400e51ed34eb8d0af3 (diff)
downloadcpython-ab9c72912178cfdb4d0637be036d78913b769154.zip
cpython-ab9c72912178cfdb4d0637be036d78913b769154.tar.gz
cpython-ab9c72912178cfdb4d0637be036d78913b769154.tar.bz2
[3.8] bpo-38643: Raise SystemError instead of crashing when PyNumber_ToBase is called with invalid base. (GH-18863). (GH-18954)
(cherry picked from commit e5ccc94bbb153431698b2391df625e8d47a93276)
Diffstat (limited to 'Lib/test')
-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 2761ab3..584c104 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -473,6 +473,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):