mirror of https://github.com/python/cpython
Issue #7449, part 5: split Test.test_open() of ctypes/test/test_errno.py
* Split Test.test_open() in 2 functions: test_open() and test_thread_open() * Skip test_open() and test_thread_open() if we are unable to find the C library * Skip test_thread_open() if thread support is disabled * Use unittest.skipUnless(os.name == "nt", ...) on test_GetLastError()
This commit is contained in:
parent
613b4cf283
commit
9751472001
|
@ -1,12 +1,17 @@
|
|||
import unittest, os, errno
|
||||
from ctypes import *
|
||||
from ctypes.util import find_library
|
||||
from test import test_support
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
threading = None
|
||||
|
||||
libc_name = find_library("c")
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
@unittest.skipUnless(libc_name, 'Unable to find the C library')
|
||||
def test_open(self):
|
||||
libc_name = find_library("c")
|
||||
if libc_name is not None:
|
||||
libc = CDLL(libc_name, use_errno=True)
|
||||
if os.name == "nt":
|
||||
libc_open = libc._open
|
||||
|
@ -21,6 +26,10 @@ class Test(unittest.TestCase):
|
|||
self.assertEqual(set_errno(32), errno.ENOENT)
|
||||
self.assertEqual(get_errno(), 32)
|
||||
|
||||
@unittest.skipUnless(libc_name, 'Unable to find the C library')
|
||||
@unittest.skipUnless(threading, 'This test requires threading.')
|
||||
def test_open_thread(self):
|
||||
self.assertEqual(set_errno(32), errno.ENOENT)
|
||||
|
||||
def _worker():
|
||||
set_errno(0)
|
||||
|
@ -41,8 +50,7 @@ class Test(unittest.TestCase):
|
|||
self.assertEqual(get_errno(), 32)
|
||||
set_errno(0)
|
||||
|
||||
if os.name == "nt":
|
||||
|
||||
@unittest.skipUnless(os.name == "nt", 'Test specific to Windows')
|
||||
def test_GetLastError(self):
|
||||
dll = WinDLL("kernel32", use_last_error=True)
|
||||
GetModuleHandle = dll.GetModuleHandleA
|
||||
|
|
Loading…
Reference in New Issue