Tim Peters | d66595f | 2001-02-04 03:09:53 +0000 | [diff] [blame] | 1 | # Run the _testcapi module tests (tests for the Python/C API): by defn, |
Guido van Rossum | 361c535 | 2001-04-13 17:03:04 +0000 | [diff] [blame] | 2 | # these are all functions _testcapi exports whose name begins with 'test_'. |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 3 | |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 4 | import os |
Antoine Pitrou | 2f828f2 | 2012-01-18 00:21:11 +0100 | [diff] [blame] | 5 | import pickle |
Jeffrey Yasskin | 8e0bdfd | 2010-05-13 18:31:05 +0000 | [diff] [blame] | 6 | import random |
| 7 | import subprocess |
Martin v. Löwis | 6ce7ed2 | 2005-03-03 12:26:35 +0000 | [diff] [blame] | 8 | import sys |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 9 | import time |
Benjamin Peterson | 9b6df6a | 2008-10-16 23:56:29 +0000 | [diff] [blame] | 10 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 11 | from test import support |
Victor Stinner | 45df820 | 2010-04-28 22:31:17 +0000 | [diff] [blame] | 12 | try: |
Stefan Krah | fd24f9e | 2012-08-20 11:04:24 +0200 | [diff] [blame] | 13 | import _posixsubprocess |
| 14 | except ImportError: |
| 15 | _posixsubprocess = None |
| 16 | try: |
Victor Stinner | 45df820 | 2010-04-28 22:31:17 +0000 | [diff] [blame] | 17 | import threading |
| 18 | except ImportError: |
| 19 | threading = None |
Serhiy Storchaka | 5cfc79d | 2014-02-07 10:06:39 +0200 | [diff] [blame^] | 20 | # Skip this test if the _testcapi module isn't available. |
| 21 | _testcapi = support.import_module('_testcapi') |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 22 | |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 23 | |
Benjamin Peterson | 9b6df6a | 2008-10-16 23:56:29 +0000 | [diff] [blame] | 24 | def testfunction(self): |
| 25 | """some doc""" |
| 26 | return self |
| 27 | |
| 28 | class InstanceMethod: |
| 29 | id = _testcapi.instancemethod(id) |
| 30 | testfunction = _testcapi.instancemethod(testfunction) |
| 31 | |
| 32 | class CAPITest(unittest.TestCase): |
| 33 | |
| 34 | def test_instancemethod(self): |
| 35 | inst = InstanceMethod() |
| 36 | self.assertEqual(id(inst), inst.id()) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 37 | self.assertTrue(inst.testfunction() is inst) |
Benjamin Peterson | 9b6df6a | 2008-10-16 23:56:29 +0000 | [diff] [blame] | 38 | self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__) |
| 39 | self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc__) |
| 40 | |
| 41 | InstanceMethod.testfunction.attribute = "test" |
| 42 | self.assertEqual(testfunction.attribute, "test") |
| 43 | self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test") |
| 44 | |
Stefan Krah | 0ca4624 | 2010-06-09 08:56:28 +0000 | [diff] [blame] | 45 | @unittest.skipUnless(threading, 'Threading required for this test.') |
Jeffrey Yasskin | 8e0bdfd | 2010-05-13 18:31:05 +0000 | [diff] [blame] | 46 | def test_no_FatalError_infinite_loop(self): |
Ezio Melotti | 25a4045 | 2013-03-05 20:26:17 +0200 | [diff] [blame] | 47 | with support.suppress_crash_popup(): |
| 48 | p = subprocess.Popen([sys.executable, "-c", |
Ezio Melotti | e1857d9 | 2013-03-05 20:31:34 +0200 | [diff] [blame] | 49 | 'import _testcapi;' |
| 50 | '_testcapi.crash_no_current_thread()'], |
| 51 | stdout=subprocess.PIPE, |
| 52 | stderr=subprocess.PIPE) |
Jeffrey Yasskin | 8e0bdfd | 2010-05-13 18:31:05 +0000 | [diff] [blame] | 53 | (out, err) = p.communicate() |
| 54 | self.assertEqual(out, b'') |
| 55 | # This used to cause an infinite loop. |
Vinay Sajip | 7395404 | 2012-05-06 11:34:50 +0100 | [diff] [blame] | 56 | self.assertTrue(err.rstrip().startswith( |
Jeffrey Yasskin | 8e0bdfd | 2010-05-13 18:31:05 +0000 | [diff] [blame] | 57 | b'Fatal Python error:' |
Vinay Sajip | 7395404 | 2012-05-06 11:34:50 +0100 | [diff] [blame] | 58 | b' PyThreadState_Get: no current thread')) |
Jeffrey Yasskin | 8e0bdfd | 2010-05-13 18:31:05 +0000 | [diff] [blame] | 59 | |
Antoine Pitrou | 915605c | 2011-02-24 20:53:48 +0000 | [diff] [blame] | 60 | def test_memoryview_from_NULL_pointer(self): |
| 61 | self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer) |
Benjamin Peterson | 9b6df6a | 2008-10-16 23:56:29 +0000 | [diff] [blame] | 62 | |
Martin v. Löwis | aa2efcb | 2012-04-19 14:33:43 +0200 | [diff] [blame] | 63 | def test_exc_info(self): |
| 64 | raised_exception = ValueError("5") |
| 65 | new_exc = TypeError("TEST") |
| 66 | try: |
| 67 | raise raised_exception |
| 68 | except ValueError as e: |
| 69 | tb = e.__traceback__ |
| 70 | orig_sys_exc_info = sys.exc_info() |
| 71 | orig_exc_info = _testcapi.set_exc_info(new_exc.__class__, new_exc, None) |
| 72 | new_sys_exc_info = sys.exc_info() |
| 73 | new_exc_info = _testcapi.set_exc_info(*orig_exc_info) |
| 74 | reset_sys_exc_info = sys.exc_info() |
| 75 | |
| 76 | self.assertEqual(orig_exc_info[1], e) |
| 77 | |
| 78 | self.assertSequenceEqual(orig_exc_info, (raised_exception.__class__, raised_exception, tb)) |
| 79 | self.assertSequenceEqual(orig_sys_exc_info, orig_exc_info) |
| 80 | self.assertSequenceEqual(reset_sys_exc_info, orig_exc_info) |
| 81 | self.assertSequenceEqual(new_exc_info, (new_exc.__class__, new_exc, None)) |
| 82 | self.assertSequenceEqual(new_sys_exc_info, new_exc_info) |
| 83 | else: |
| 84 | self.assertTrue(False) |
| 85 | |
Stefan Krah | fd24f9e | 2012-08-20 11:04:24 +0200 | [diff] [blame] | 86 | @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') |
| 87 | def test_seq_bytes_to_charp_array(self): |
| 88 | # Issue #15732: crash in _PySequence_BytesToCharpArray() |
| 89 | class Z(object): |
| 90 | def __len__(self): |
| 91 | return 1 |
| 92 | self.assertRaises(TypeError, _posixsubprocess.fork_exec, |
| 93 | 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) |
Stefan Krah | 7cacd2e | 2012-08-21 08:16:09 +0200 | [diff] [blame] | 94 | # Issue #15736: overflow in _PySequence_BytesToCharpArray() |
| 95 | class Z(object): |
| 96 | def __len__(self): |
| 97 | return sys.maxsize |
| 98 | def __getitem__(self, i): |
| 99 | return b'x' |
| 100 | self.assertRaises(MemoryError, _posixsubprocess.fork_exec, |
| 101 | 1,Z(),3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) |
Stefan Krah | fd24f9e | 2012-08-20 11:04:24 +0200 | [diff] [blame] | 102 | |
Stefan Krah | db579d7 | 2012-08-20 14:36:47 +0200 | [diff] [blame] | 103 | @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this test.') |
| 104 | def test_subprocess_fork_exec(self): |
| 105 | class Z(object): |
| 106 | def __len__(self): |
| 107 | return 1 |
| 108 | |
| 109 | # Issue #15738: crash in subprocess_fork_exec() |
| 110 | self.assertRaises(TypeError, _posixsubprocess.fork_exec, |
| 111 | Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) |
| 112 | |
Victor Stinner | 45df820 | 2010-04-28 22:31:17 +0000 | [diff] [blame] | 113 | @unittest.skipUnless(threading, 'Threading required for this test.') |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 114 | class TestPendingCalls(unittest.TestCase): |
| 115 | |
| 116 | def pendingcalls_submit(self, l, n): |
| 117 | def callback(): |
| 118 | #this function can be interrupted by thread switching so let's |
| 119 | #use an atomic operation |
| 120 | l.append(None) |
| 121 | |
| 122 | for i in range(n): |
| 123 | time.sleep(random.random()*0.02) #0.01 secs on average |
| 124 | #try submitting callback until successful. |
| 125 | #rely on regular interrupt to flush queue if we are |
| 126 | #unsuccessful. |
| 127 | while True: |
| 128 | if _testcapi._pending_threadfunc(callback): |
| 129 | break; |
| 130 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 131 | def pendingcalls_wait(self, l, n, context = None): |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 132 | #now, stick around until l[0] has grown to 10 |
| 133 | count = 0; |
| 134 | while len(l) != n: |
| 135 | #this busy loop is where we expect to be interrupted to |
| 136 | #run our callbacks. Note that callbacks are only run on the |
| 137 | #main thread |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 138 | if False and support.verbose: |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 139 | print("(%i)"%(len(l),),) |
| 140 | for i in range(1000): |
| 141 | a = i*i |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 142 | if context and not context.event.is_set(): |
| 143 | continue |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 144 | count += 1 |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 145 | self.assertTrue(count < 10000, |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 146 | "timeout waiting for %i callbacks, got %i"%(n, len(l))) |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 147 | if False and support.verbose: |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 148 | print("(%i)"%(len(l),)) |
| 149 | |
| 150 | def test_pendingcalls_threaded(self): |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 151 | |
| 152 | #do every callback on a separate thread |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 153 | n = 32 #total callbacks |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 154 | threads = [] |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 155 | class foo(object):pass |
| 156 | context = foo() |
| 157 | context.l = [] |
| 158 | context.n = 2 #submits per thread |
| 159 | context.nThreads = n // context.n |
| 160 | context.nFinished = 0 |
| 161 | context.lock = threading.Lock() |
| 162 | context.event = threading.Event() |
| 163 | |
| 164 | for i in range(context.nThreads): |
| 165 | t = threading.Thread(target=self.pendingcalls_thread, args = (context,)) |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 166 | t.start() |
| 167 | threads.append(t) |
| 168 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 169 | self.pendingcalls_wait(context.l, n, context) |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 170 | |
| 171 | for t in threads: |
| 172 | t.join() |
| 173 | |
Benjamin Peterson | e1cdfd7 | 2009-01-18 21:02:37 +0000 | [diff] [blame] | 174 | def pendingcalls_thread(self, context): |
| 175 | try: |
| 176 | self.pendingcalls_submit(context.l, context.n) |
| 177 | finally: |
| 178 | with context.lock: |
| 179 | context.nFinished += 1 |
| 180 | nFinished = context.nFinished |
| 181 | if False and support.verbose: |
| 182 | print("finished threads: ", nFinished) |
| 183 | if nFinished == context.nThreads: |
| 184 | context.event.set() |
| 185 | |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 186 | def test_pendingcalls_non_threaded(self): |
Ezio Melotti | 1392500 | 2011-03-16 11:05:33 +0200 | [diff] [blame] | 187 | #again, just using the main thread, likely they will all be dispatched at |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 188 | #once. It is ok to ask for too many, because we loop until we find a slot. |
| 189 | #the loop can be interrupted to dispatch. |
| 190 | #there are only 32 dispatch slots, so we go for twice that! |
| 191 | l = [] |
| 192 | n = 64 |
| 193 | self.pendingcalls_submit(l, n) |
| 194 | self.pendingcalls_wait(l, n) |
| 195 | |
Antoine Pitrou | 2f828f2 | 2012-01-18 00:21:11 +0100 | [diff] [blame] | 196 | def test_subinterps(self): |
Antoine Pitrou | 2f828f2 | 2012-01-18 00:21:11 +0100 | [diff] [blame] | 197 | import builtins |
| 198 | r, w = os.pipe() |
| 199 | code = """if 1: |
| 200 | import sys, builtins, pickle |
| 201 | with open({:d}, "wb") as f: |
| 202 | pickle.dump(id(sys.modules), f) |
| 203 | pickle.dump(id(builtins), f) |
| 204 | """.format(w) |
| 205 | with open(r, "rb") as f: |
| 206 | ret = _testcapi.run_in_subinterp(code) |
| 207 | self.assertEqual(ret, 0) |
| 208 | self.assertNotEqual(pickle.load(f), id(sys.modules)) |
| 209 | self.assertNotEqual(pickle.load(f), id(builtins)) |
| 210 | |
Martin v. Löwis | c15bdef | 2009-05-29 14:47:46 +0000 | [diff] [blame] | 211 | # Bug #6012 |
| 212 | class Test6012(unittest.TestCase): |
| 213 | def test(self): |
| 214 | self.assertEqual(_testcapi.argparsing("Hello", "World"), 1) |
Benjamin Peterson | a54c909 | 2009-01-13 02:11:23 +0000 | [diff] [blame] | 215 | |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 216 | |
| 217 | class EmbeddingTest(unittest.TestCase): |
| 218 | |
Antoine Pitrou | 71cbafb | 2011-06-30 20:02:54 +0200 | [diff] [blame] | 219 | @unittest.skipIf( |
| 220 | sys.platform.startswith('win'), |
| 221 | "test doesn't work under Windows") |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 222 | def test_subinterps(self): |
| 223 | # XXX only tested under Unix checkouts |
| 224 | basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
| 225 | oldcwd = os.getcwd() |
| 226 | # This is needed otherwise we get a fatal error: |
| 227 | # "Py_Initialize: Unable to get the locale encoding |
| 228 | # LookupError: no codec search functions registered: can't find encoding" |
| 229 | os.chdir(basepath) |
| 230 | try: |
| 231 | exe = os.path.join(basepath, "Modules", "_testembed") |
| 232 | if not os.path.exists(exe): |
| 233 | self.skipTest("%r doesn't exist" % exe) |
| 234 | p = subprocess.Popen([exe], |
| 235 | stdout=subprocess.PIPE, |
| 236 | stderr=subprocess.PIPE) |
| 237 | (out, err) = p.communicate() |
| 238 | self.assertEqual(p.returncode, 0, |
| 239 | "bad returncode %d, stderr is %r" % |
| 240 | (p.returncode, err)) |
| 241 | if support.verbose: |
| 242 | print() |
| 243 | print(out.decode('latin1')) |
| 244 | print(err.decode('latin1')) |
| 245 | finally: |
| 246 | os.chdir(oldcwd) |
| 247 | |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 248 | class SkipitemTest(unittest.TestCase): |
| 249 | |
| 250 | def test_skipitem(self): |
| 251 | """ |
| 252 | If this test failed, you probably added a new "format unit" |
| 253 | in Python/getargs.c, but neglected to update our poor friend |
| 254 | skipitem() in the same file. (If so, shame on you!) |
| 255 | |
Larry Hastings | 48ed360 | 2012-06-22 12:58:36 -0700 | [diff] [blame] | 256 | With a few exceptions**, this function brute-force tests all |
| 257 | printable ASCII*** characters (32 to 126 inclusive) as format units, |
| 258 | checking to see that PyArg_ParseTupleAndKeywords() return consistent |
| 259 | errors both when the unit is attempted to be used and when it is |
| 260 | skipped. If the format unit doesn't exist, we'll get one of two |
| 261 | specific error messages (one for used, one for skipped); if it does |
| 262 | exist we *won't* get that error--we'll get either no error or some |
| 263 | other error. If we get the specific "does not exist" error for one |
| 264 | test and not for the other, there's a mismatch, and the test fails. |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 265 | |
Larry Hastings | 48ed360 | 2012-06-22 12:58:36 -0700 | [diff] [blame] | 266 | ** Some format units have special funny semantics and it would |
| 267 | be difficult to accomodate them here. Since these are all |
| 268 | well-established and properly skipped in skipitem() we can |
| 269 | get away with not testing them--this test is really intended |
| 270 | to catch *new* format units. |
| 271 | |
| 272 | *** Python C source files must be ASCII. Therefore it's impossible |
| 273 | to have non-ASCII format units. |
| 274 | |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 275 | """ |
| 276 | empty_tuple = () |
| 277 | tuple_1 = (0,) |
| 278 | dict_b = {'b':1} |
| 279 | keywords = ["a", "b"] |
| 280 | |
Larry Hastings | 48ed360 | 2012-06-22 12:58:36 -0700 | [diff] [blame] | 281 | for i in range(32, 127): |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 282 | c = chr(i) |
| 283 | |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 284 | # skip parentheses, the error reporting is inconsistent about them |
| 285 | # skip 'e', it's always a two-character code |
| 286 | # skip '|' and '$', they don't represent arguments anyway |
Larry Hastings | 48ed360 | 2012-06-22 12:58:36 -0700 | [diff] [blame] | 287 | if c in '()e|$': |
Larry Hastings | 8f904da | 2012-06-22 03:56:29 -0700 | [diff] [blame] | 288 | continue |
| 289 | |
| 290 | # test the format unit when not skipped |
| 291 | format = c + "i" |
| 292 | try: |
| 293 | # (note: the format string must be bytes!) |
| 294 | _testcapi.parse_tuple_and_keywords(tuple_1, dict_b, |
| 295 | format.encode("ascii"), keywords) |
| 296 | when_not_skipped = False |
| 297 | except TypeError as e: |
| 298 | s = "argument 1 must be impossible<bad format char>, not int" |
| 299 | when_not_skipped = (str(e) == s) |
| 300 | except RuntimeError as e: |
| 301 | when_not_skipped = False |
| 302 | |
| 303 | # test the format unit when skipped |
| 304 | optional_format = "|" + format |
| 305 | try: |
| 306 | _testcapi.parse_tuple_and_keywords(empty_tuple, dict_b, |
| 307 | optional_format.encode("ascii"), keywords) |
| 308 | when_skipped = False |
| 309 | except RuntimeError as e: |
| 310 | s = "impossible<bad format char>: '{}'".format(format) |
| 311 | when_skipped = (str(e) == s) |
| 312 | |
| 313 | message = ("test_skipitem_parity: " |
| 314 | "detected mismatch between convertsimple and skipitem " |
| 315 | "for format unit '{}' ({}), not skipped {}, skipped {}".format( |
| 316 | c, i, when_skipped, when_not_skipped)) |
| 317 | self.assertIs(when_skipped, when_not_skipped, message) |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 318 | |
Jesus Cea | 6e1d2b6 | 2012-10-04 16:06:30 +0200 | [diff] [blame] | 319 | def test_parse_tuple_and_keywords(self): |
| 320 | # parse_tuple_and_keywords error handling tests |
| 321 | self.assertRaises(TypeError, _testcapi.parse_tuple_and_keywords, |
| 322 | (), {}, 42, []) |
| 323 | self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords, |
| 324 | (), {}, b'', 42) |
| 325 | self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords, |
| 326 | (), {}, b'', [''] * 42) |
| 327 | self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords, |
| 328 | (), {}, b'', [42]) |
| 329 | |
Ezio Melotti | 29267c8 | 2013-02-23 05:52:46 +0200 | [diff] [blame] | 330 | @unittest.skipUnless(threading, 'Threading required for this test.') |
| 331 | class TestThreadState(unittest.TestCase): |
| 332 | |
| 333 | @support.reap_threads |
| 334 | def test_thread_state(self): |
| 335 | # some extra thread-state tests driven via _testcapi |
| 336 | def target(): |
| 337 | idents = [] |
| 338 | |
| 339 | def callback(): |
Ezio Melotti | 35246bd | 2013-02-23 05:58:38 +0200 | [diff] [blame] | 340 | idents.append(threading.get_ident()) |
Ezio Melotti | 29267c8 | 2013-02-23 05:52:46 +0200 | [diff] [blame] | 341 | |
| 342 | _testcapi._test_thread_state(callback) |
| 343 | a = b = callback |
| 344 | time.sleep(1) |
| 345 | # Check our main thread is in the list exactly 3 times. |
Ezio Melotti | 35246bd | 2013-02-23 05:58:38 +0200 | [diff] [blame] | 346 | self.assertEqual(idents.count(threading.get_ident()), 3, |
Ezio Melotti | 29267c8 | 2013-02-23 05:52:46 +0200 | [diff] [blame] | 347 | "Couldn't find main thread correctly in the list") |
| 348 | |
| 349 | target() |
| 350 | t = threading.Thread(target=target) |
| 351 | t.start() |
| 352 | t.join() |
| 353 | |
Zachary Ware | c12f09e | 2013-11-11 22:47:04 -0600 | [diff] [blame] | 354 | class Test_testcapi(unittest.TestCase): |
| 355 | def test__testcapi(self): |
| 356 | for name in dir(_testcapi): |
| 357 | if name.startswith('test_'): |
| 358 | test = getattr(_testcapi, name) |
| 359 | test() |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 360 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 361 | if __name__ == "__main__": |
Zachary Ware | c12f09e | 2013-11-11 22:47:04 -0600 | [diff] [blame] | 362 | unittest.main() |