Commit 36b9fbb8 authored by Florent Xicluna's avatar Florent Xicluna

Skip tests which depend on multiprocessing.sharedctypes, if _ctypes is not available.

parent f91a6796
...@@ -62,6 +62,16 @@ HAVE_GETVALUE = not getattr(_multiprocessing, ...@@ -62,6 +62,16 @@ HAVE_GETVALUE = not getattr(_multiprocessing,
WIN32 = (sys.platform == "win32") WIN32 = (sys.platform == "win32")
#
# Some tests require ctypes
#
try:
from ctypes import Structure, Value, copy, c_int, c_double
except ImportError:
Structure = object
c_int = c_double = None
# #
# Creates a wrapper for a function which records the time it takes to finish # Creates a wrapper for a function which records the time it takes to finish
# #
...@@ -505,7 +515,7 @@ class _TestQueue(BaseTestCase): ...@@ -505,7 +515,7 @@ class _TestQueue(BaseTestCase):
queue = self.JoinableQueue() queue = self.JoinableQueue()
if sys.version_info < (2, 5) and not hasattr(queue, 'task_done'): if sys.version_info < (2, 5) and not hasattr(queue, 'task_done'):
return self.skipTest("requires 'queue.task_done()' method")
workers = [self.Process(target=self._test_task_done, args=(queue,)) workers = [self.Process(target=self._test_task_done, args=(queue,))
for i in xrange(4)] for i in xrange(4)]
...@@ -782,6 +792,8 @@ class _TestEvent(BaseTestCase): ...@@ -782,6 +792,8 @@ class _TestEvent(BaseTestCase):
class _TestValue(BaseTestCase): class _TestValue(BaseTestCase):
ALLOWED_TYPES = ('processes',)
codes_values = [ codes_values = [
('i', 4343, 24234), ('i', 4343, 24234),
('d', 3.625, -4.25), ('d', 3.625, -4.25),
...@@ -794,10 +806,8 @@ class _TestValue(BaseTestCase): ...@@ -794,10 +806,8 @@ class _TestValue(BaseTestCase):
sv.value = cv[2] sv.value = cv[2]
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_value(self, raw=False): def test_value(self, raw=False):
if self.TYPE != 'processes':
return
if raw: if raw:
values = [self.RawValue(code, value) values = [self.RawValue(code, value)
for code, value, _ in self.codes_values] for code, value, _ in self.codes_values]
...@@ -815,13 +825,12 @@ class _TestValue(BaseTestCase): ...@@ -815,13 +825,12 @@ class _TestValue(BaseTestCase):
for sv, cv in zip(values, self.codes_values): for sv, cv in zip(values, self.codes_values):
self.assertEqual(sv.value, cv[2]) self.assertEqual(sv.value, cv[2])
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_rawvalue(self): def test_rawvalue(self):
self.test_value(raw=True) self.test_value(raw=True)
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_getobj_getlock(self): def test_getobj_getlock(self):
if self.TYPE != 'processes':
return
val1 = self.Value('i', 5) val1 = self.Value('i', 5)
lock1 = val1.get_lock() lock1 = val1.get_lock()
obj1 = val1.get_obj() obj1 = val1.get_obj()
...@@ -849,14 +858,14 @@ class _TestValue(BaseTestCase): ...@@ -849,14 +858,14 @@ class _TestValue(BaseTestCase):
class _TestArray(BaseTestCase): class _TestArray(BaseTestCase):
ALLOWED_TYPES = ('processes',)
def f(self, seq): def f(self, seq):
for i in range(1, len(seq)): for i in range(1, len(seq)):
seq[i] += seq[i-1] seq[i] += seq[i-1]
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_array(self, raw=False): def test_array(self, raw=False):
if self.TYPE != 'processes':
return
seq = [680, 626, 934, 821, 150, 233, 548, 982, 714, 831] seq = [680, 626, 934, 821, 150, 233, 548, 982, 714, 831]
if raw: if raw:
arr = self.RawArray('i', seq) arr = self.RawArray('i', seq)
...@@ -879,13 +888,12 @@ class _TestArray(BaseTestCase): ...@@ -879,13 +888,12 @@ class _TestArray(BaseTestCase):
self.assertEqual(list(arr[:]), seq) self.assertEqual(list(arr[:]), seq)
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_rawarray(self): def test_rawarray(self):
self.test_array(raw=True) self.test_array(raw=True)
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_getobj_getlock_obj(self): def test_getobj_getlock_obj(self):
if self.TYPE != 'processes':
return
arr1 = self.Array('i', range(10)) arr1 = self.Array('i', range(10))
lock1 = arr1.get_lock() lock1 = arr1.get_lock()
obj1 = arr1.get_obj() obj1 = arr1.get_obj()
...@@ -1569,12 +1577,6 @@ class _TestHeap(BaseTestCase): ...@@ -1569,12 +1577,6 @@ class _TestHeap(BaseTestCase):
# #
# #
try:
from ctypes import Structure, Value, copy, c_int, c_double
except ImportError:
Structure = object
c_int = c_double = None
class _Foo(Structure): class _Foo(Structure):
_fields_ = [ _fields_ = [
('x', c_int), ('x', c_int),
...@@ -1594,10 +1596,8 @@ class _TestSharedCTypes(BaseTestCase): ...@@ -1594,10 +1596,8 @@ class _TestSharedCTypes(BaseTestCase):
for i in range(len(arr)): for i in range(len(arr)):
arr[i] *= 2 arr[i] *= 2
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_sharedctypes(self, lock=False): def test_sharedctypes(self, lock=False):
if c_int is None:
return
x = Value('i', 7, lock=lock) x = Value('i', 7, lock=lock)
y = Value(c_double, 1.0/3.0, lock=lock) y = Value(c_double, 1.0/3.0, lock=lock)
foo = Value(_Foo, 3, 2, lock=lock) foo = Value(_Foo, 3, 2, lock=lock)
...@@ -1620,10 +1620,8 @@ class _TestSharedCTypes(BaseTestCase): ...@@ -1620,10 +1620,8 @@ class _TestSharedCTypes(BaseTestCase):
def test_synchronize(self): def test_synchronize(self):
self.test_sharedctypes(lock=True) self.test_sharedctypes(lock=True)
@unittest.skipIf(c_int is None, "requires _ctypes")
def test_copy(self): def test_copy(self):
if c_int is None:
return
foo = _Foo(2, 5.0) foo = _Foo(2, 5.0)
bar = copy(foo) bar = copy(foo)
foo.x = 0 foo.x = 0
...@@ -1695,13 +1693,17 @@ class _TestImportStar(BaseTestCase): ...@@ -1695,13 +1693,17 @@ class _TestImportStar(BaseTestCase):
ALLOWED_TYPES = ('processes',) ALLOWED_TYPES = ('processes',)
def test_import(self): def test_import(self):
modules = ( modules = [
'multiprocessing', 'multiprocessing.connection', 'multiprocessing', 'multiprocessing.connection',
'multiprocessing.heap', 'multiprocessing.managers', 'multiprocessing.heap', 'multiprocessing.managers',
'multiprocessing.pool', 'multiprocessing.process', 'multiprocessing.pool', 'multiprocessing.process',
'multiprocessing.reduction', 'multiprocessing.sharedctypes', 'multiprocessing.reduction',
'multiprocessing.synchronize', 'multiprocessing.util' 'multiprocessing.synchronize', 'multiprocessing.util'
) ]
if c_int is not None:
# This module requires _ctypes
modules.append('multiprocessing.sharedctypes')
for name in modules: for name in modules:
__import__(name) __import__(name)
...@@ -1781,12 +1783,12 @@ class _TestLogging(BaseTestCase): ...@@ -1781,12 +1783,12 @@ class _TestLogging(BaseTestCase):
class TestInvalidHandle(unittest.TestCase): class TestInvalidHandle(unittest.TestCase):
@unittest.skipIf(WIN32, "skipped on Windows")
def test_invalid_handles(self): def test_invalid_handles(self):
if WIN32:
return
conn = _multiprocessing.Connection(44977608) conn = _multiprocessing.Connection(44977608)
self.assertRaises(IOError, conn.poll) self.assertRaises(IOError, conn.poll)
self.assertRaises(IOError, _multiprocessing.Connection, -1) self.assertRaises(IOError, _multiprocessing.Connection, -1)
# #
# Functions used to create test cases from the base ones in this module # Functions used to create test cases from the base ones in this module
# #
...@@ -1803,7 +1805,7 @@ def get_attributes(Source, names): ...@@ -1803,7 +1805,7 @@ def get_attributes(Source, names):
def create_test_cases(Mixin, type): def create_test_cases(Mixin, type):
result = {} result = {}
glob = globals() glob = globals()
Type = type[0].upper() + type[1:] Type = type.capitalize()
for name in glob.keys(): for name in glob.keys():
if name.startswith('_Test'): if name.startswith('_Test'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment