diff options
Diffstat (limited to 'Lib/test/test_capi.py')
| -rw-r--r-- | Lib/test/test_capi.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 0460679..529a2a5 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -2,12 +2,16 @@ # these are all functions _testcapi exports whose name begins with 'test_'. from __future__ import with_statement +import random +import subprocess import sys import time -import random import unittest -import threading from test import support +try: + import threading +except ImportError: + threading = None import _testcapi @@ -32,7 +36,24 @@ class CAPITest(unittest.TestCase): self.assertEqual(testfunction.attribute, "test") self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test") - + @unittest.skipUnless(threading, 'Threading required for this test.') + def test_no_FatalError_infinite_loop(self): + p = subprocess.Popen([sys.executable, "-c", + 'import _testcapi;' + '_testcapi.crash_no_current_thread()'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + (out, err) = p.communicate() + self.assertEqual(out, b'') + # This used to cause an infinite loop. + self.assertEqual(err.rstrip(), + b'Fatal Python error:' + b' PyThreadState_Get: no current thread') + + def test_memoryview_from_NULL_pointer(self): + self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) + +@unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): def pendingcalls_submit(self, l, n): @@ -148,17 +169,10 @@ def test_main(): raise support.TestFailed( "Couldn't find main thread correctly in the list") - try: - _testcapi._test_thread_state - have_thread_state = True - except AttributeError: - have_thread_state = False - - if have_thread_state: + if threading: import _thread import time TestThreadState() - import threading t = threading.Thread(target=TestThreadState) t.start() t.join() |
