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 | |
| 4 | import sys |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 5 | from test import test_support |
Tim Peters | d66595f | 2001-02-04 03:09:53 +0000 | [diff] [blame] | 6 | import _testcapi |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 7 | |
Tim Peters | d66595f | 2001-02-04 03:09:53 +0000 | [diff] [blame] | 8 | for name in dir(_testcapi): |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 9 | if name.startswith('test_'): |
Tim Peters | d66595f | 2001-02-04 03:09:53 +0000 | [diff] [blame] | 10 | test = getattr(_testcapi, name) |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 11 | if test_support.verbose: |
| 12 | print "internal", name |
| 13 | try: |
| 14 | test() |
Tim Peters | d66595f | 2001-02-04 03:09:53 +0000 | [diff] [blame] | 15 | except _testcapi.error: |
Tim Peters | 9ea17ac | 2001-02-02 05:57:15 +0000 | [diff] [blame] | 16 | raise test_support.TestFailed, sys.exc_info()[1] |
Mark Hammond | 8d98d2c | 2003-04-19 15:41:53 +0000 | [diff] [blame] | 17 | |
| 18 | # some extra thread-state tests driven via _testcapi |
| 19 | def TestThreadState(): |
| 20 | import thread |
| 21 | import time |
| 22 | |
| 23 | if test_support.verbose: |
| 24 | print "auto-thread-state" |
| 25 | |
| 26 | idents = [] |
| 27 | |
| 28 | def callback(): |
| 29 | idents.append(thread.get_ident()) |
Tim Peters | 0eadaac | 2003-04-24 16:02:54 +0000 | [diff] [blame] | 30 | |
Mark Hammond | 8d98d2c | 2003-04-19 15:41:53 +0000 | [diff] [blame] | 31 | _testcapi._test_thread_state(callback) |
| 32 | time.sleep(1) |
| 33 | # Check our main thread is in the list exactly 3 times. |
| 34 | if idents.count(thread.get_ident()) != 3: |
| 35 | raise test_support.TestFailed, \ |
| 36 | "Couldn't find main thread correctly in the list" |
| 37 | |
| 38 | try: |
| 39 | _testcapi._test_thread_state |
| 40 | have_thread_state = True |
| 41 | except AttributeError: |
| 42 | have_thread_state = False |
Tim Peters | 0eadaac | 2003-04-24 16:02:54 +0000 | [diff] [blame] | 43 | |
Mark Hammond | 8d98d2c | 2003-04-19 15:41:53 +0000 | [diff] [blame] | 44 | if have_thread_state: |
| 45 | TestThreadState() |