@@ -63,6 +63,16 @@ def latin(s):
6363
6464WIN32 = (sys .platform == "win32" )
6565
66+ #
67+ # Some tests require ctypes
68+ #
69+
70+ try :
71+ from ctypes import Structure , Value , copy , c_int , c_double
72+ except ImportError :
73+ Structure = object
74+ c_int = c_double = None
75+
6676#
6777# Creates a wrapper for a function which records the time it takes to finish
6878#
@@ -506,7 +516,7 @@ def test_task_done(self):
506516 queue = self .JoinableQueue ()
507517
508518 if sys .version_info < (2 , 5 ) and not hasattr (queue , 'task_done' ):
509- return
519+ self . skipTest ( "requires 'queue.task_done()' method" )
510520
511521 workers = [self .Process (target = self ._test_task_done , args = (queue ,))
512522 for i in range (4 )]
@@ -783,6 +793,8 @@ def test_event(self):
783793
784794class _TestValue (BaseTestCase ):
785795
796+ ALLOWED_TYPES = ('processes' ,)
797+
786798 codes_values = [
787799 ('i' , 4343 , 24234 ),
788800 ('d' , 3.625 , - 4.25 ),
@@ -795,10 +807,8 @@ def _test(self, values):
795807 sv .value = cv [2 ]
796808
797809
810+ @unittest .skipIf (c_int is None , "requires _ctypes" )
798811 def test_value (self , raw = False ):
799- if self .TYPE != 'processes' :
800- return
801-
802812 if raw :
803813 values = [self .RawValue (code , value )
804814 for code , value , _ in self .codes_values ]
@@ -816,13 +826,12 @@ def test_value(self, raw=False):
816826 for sv , cv in zip (values , self .codes_values ):
817827 self .assertEqual (sv .value , cv [2 ])
818828
829+ @unittest .skipIf (c_int is None , "requires _ctypes" )
819830 def test_rawvalue (self ):
820831 self .test_value (raw = True )
821832
833+ @unittest .skipIf (c_int is None , "requires _ctypes" )
822834 def test_getobj_getlock (self ):
823- if self .TYPE != 'processes' :
824- return
825-
826835 val1 = self .Value ('i' , 5 )
827836 lock1 = val1 .get_lock ()
828837 obj1 = val1 .get_obj ()
@@ -850,14 +859,14 @@ def test_getobj_getlock(self):
850859
851860class _TestArray (BaseTestCase ):
852861
862+ ALLOWED_TYPES = ('processes' ,)
863+
853864 def f (self , seq ):
854865 for i in range (1 , len (seq )):
855866 seq [i ] += seq [i - 1 ]
856867
868+ @unittest .skipIf (c_int is None , "requires _ctypes" )
857869 def test_array (self , raw = False ):
858- if self .TYPE != 'processes' :
859- return
860-
861870 seq = [680 , 626 , 934 , 821 , 150 , 233 , 548 , 982 , 714 , 831 ]
862871 if raw :
863872 arr = self .RawArray ('i' , seq )
@@ -880,13 +889,12 @@ def test_array(self, raw=False):
880889
881890 self .assertEqual (list (arr [:]), seq )
882891
892+ @unittest .skipIf (c_int is None , "requires _ctypes" )
883893 def test_rawarray (self ):
884894 self .test_array (raw = True )
885895
896+ @unittest .skipIf (c_int is None , "requires _ctypes" )
886897 def test_getobj_getlock_obj (self ):
887- if self .TYPE != 'processes' :
888- return
889-
890898 arr1 = self .Array ('i' , list (range (10 )))
891899 lock1 = arr1 .get_lock ()
892900 obj1 = arr1 .get_obj ()
@@ -1538,12 +1546,6 @@ def test_heap(self):
15381546#
15391547#
15401548
1541- try :
1542- from ctypes import Structure , Value , copy , c_int , c_double
1543- except ImportError :
1544- Structure = object
1545- c_int = c_double = None
1546-
15471549class _Foo (Structure ):
15481550 _fields_ = [
15491551 ('x' , c_int ),
@@ -1563,10 +1565,8 @@ def _double(self, x, y, foo, arr, string):
15631565 for i in range (len (arr )):
15641566 arr [i ] *= 2
15651567
1568+ @unittest .skipIf (c_int is None , "requires _ctypes" )
15661569 def test_sharedctypes (self , lock = False ):
1567- if c_int is None :
1568- return
1569-
15701570 x = Value ('i' , 7 , lock = lock )
15711571 y = Value (ctypes .c_double , 1.0 / 3.0 , lock = lock )
15721572 foo = Value (_Foo , 3 , 2 , lock = lock )
@@ -1589,10 +1589,8 @@ def test_sharedctypes(self, lock=False):
15891589 def test_synchronize (self ):
15901590 self .test_sharedctypes (lock = True )
15911591
1592+ @unittest .skipIf (c_int is None , "requires _ctypes" )
15921593 def test_copy (self ):
1593- if c_int is None :
1594- return
1595-
15961594 foo = _Foo (2 , 5.0 )
15971595 bar = copy (foo )
15981596 foo .x = 0
@@ -1664,13 +1662,17 @@ class _TestImportStar(BaseTestCase):
16641662 ALLOWED_TYPES = ('processes' ,)
16651663
16661664 def test_import (self ):
1667- modules = (
1665+ modules = [
16681666 'multiprocessing' , 'multiprocessing.connection' ,
16691667 'multiprocessing.heap' , 'multiprocessing.managers' ,
16701668 'multiprocessing.pool' , 'multiprocessing.process' ,
1671- 'multiprocessing.reduction' , 'multiprocessing.sharedctypes' ,
1669+ 'multiprocessing.reduction' ,
16721670 'multiprocessing.synchronize' , 'multiprocessing.util'
1673- )
1671+ ]
1672+
1673+ if c_int is not None :
1674+ # This module requires _ctypes
1675+ modules .append ('multiprocessing.sharedctypes' )
16741676
16751677 for name in modules :
16761678 __import__ (name )
@@ -1730,12 +1732,12 @@ def test_level(self):
17301732
17311733class TestInvalidHandle (unittest .TestCase ):
17321734
1735+ @unittest .skipIf (WIN32 , "skipped on Windows" )
17331736 def test_invalid_handles (self ):
1734- if WIN32 :
1735- return
17361737 conn = _multiprocessing .Connection (44977608 )
17371738 self .assertRaises (IOError , conn .poll )
17381739 self .assertRaises (IOError , _multiprocessing .Connection , - 1 )
1740+
17391741#
17401742# Functions used to create test cases from the base ones in this module
17411743#
@@ -1752,7 +1754,7 @@ def get_attributes(Source, names):
17521754def create_test_cases (Mixin , type ):
17531755 result = {}
17541756 glob = globals ()
1755- Type = type [ 0 ]. upper () + type [ 1 :]
1757+ Type = type . capitalize ()
17561758
17571759 for name in list (glob .keys ()):
17581760 if name .startswith ('_Test' ):
0 commit comments