##// END OF EJS Templates
Finished initial reworking and updating of setup.py and friends, including the MANIFEST.in. Everything seems...
Brian E Granger -
Show More
@@ -20,4 +20,5 b' __docformat__ = "restructuredtext en"'
20 20 #
21 21 # Distributed under the terms of the BSD License. The full license is in
22 22 # the file COPYING, distributed as part of this software.
23 #------------------------------------------------------------------------------- No newline at end of file
23 #-------------------------------------------------------------------------------
24 No newline at end of file
@@ -23,18 +23,21 b' __docformat__ = "restructuredtext en"'
23 23 # Imports
24 24 #-------------------------------------------------------------------------------
25 25
26 from twisted.application.service import IService
27 from IPython.kernel.controllerservice import ControllerService
28 from IPython.kernel.tests import multienginetest as met
29 from controllertest import IControllerCoreTestCase
30 from IPython.testing.util import DeferredTestCase
31
32 class BasicControllerServiceTest(DeferredTestCase,
33 IControllerCoreTestCase):
26 try:
27 from twisted.application.service import IService
28 from IPython.kernel.controllerservice import ControllerService
29 from IPython.kernel.tests import multienginetest as met
30 from controllertest import IControllerCoreTestCase
31 from IPython.testing.util import DeferredTestCase
32 except ImportError:
33 pass
34 else:
35 class BasicControllerServiceTest(DeferredTestCase,
36 IControllerCoreTestCase):
34 37
35 def setUp(self):
36 self.controller = ControllerService()
37 self.controller.startService()
38 def setUp(self):
39 self.controller = ControllerService()
40 self.controller.startService()
38 41
39 def tearDown(self):
40 self.controller.stopService()
42 def tearDown(self):
43 self.controller.stopService()
@@ -15,75 +15,78 b' __docformat__ = "restructuredtext en"'
15 15 # Imports
16 16 #-------------------------------------------------------------------------------
17 17
18 try:
19 from twisted.python import components
20 from twisted.internet import reactor, defer
21 from twisted.spread import pb
22 from twisted.internet.base import DelayedCall
23 DelayedCall.debug = True
18 24
19 from twisted.python import components
20 from twisted.internet import reactor, defer
21 from twisted.spread import pb
22 from twisted.internet.base import DelayedCall
23 DelayedCall.debug = True
25 import zope.interface as zi
24 26
25 import zope.interface as zi
26
27 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
28 from IPython.kernel import engineservice as es
29 from IPython.testing.util import DeferredTestCase
30 from IPython.kernel.controllerservice import IControllerBase
31 from IPython.kernel.enginefc import FCRemoteEngineRefFromService, IEngineBase
32 from IPython.kernel.engineservice import IEngineQueued
33 from IPython.kernel.engineconnector import EngineConnector
27 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
28 from IPython.kernel import engineservice as es
29 from IPython.testing.util import DeferredTestCase
30 from IPython.kernel.controllerservice import IControllerBase
31 from IPython.kernel.enginefc import FCRemoteEngineRefFromService, IEngineBase
32 from IPython.kernel.engineservice import IEngineQueued
33 from IPython.kernel.engineconnector import EngineConnector
34 34
35 from IPython.kernel.tests.engineservicetest import \
36 IEngineCoreTestCase, \
37 IEngineSerializedTestCase, \
38 IEngineQueuedTestCase
39
40 class EngineFCTest(DeferredTestCase,
41 IEngineCoreTestCase,
42 IEngineSerializedTestCase,
43 IEngineQueuedTestCase
44 ):
35 from IPython.kernel.tests.engineservicetest import \
36 IEngineCoreTestCase, \
37 IEngineSerializedTestCase, \
38 IEngineQueuedTestCase
39 except ImportError:
40 print "we got an error!!!"
41 pass
42 else:
43 class EngineFCTest(DeferredTestCase,
44 IEngineCoreTestCase,
45 IEngineSerializedTestCase,
46 IEngineQueuedTestCase
47 ):
45 48
46 zi.implements(IControllerBase)
49 zi.implements(IControllerBase)
47 50
48 def setUp(self):
49
50 # Start a server and append to self.servers
51 self.controller_reference = FCRemoteEngineRefFromService(self)
52 self.controller_tub = Tub()
53 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
54 self.controller_tub.setLocation('127.0.0.1:10105')
51 def setUp(self):
55 52
56 furl = self.controller_tub.registerReference(self.controller_reference)
57 self.controller_tub.startService()
53 # Start a server and append to self.servers
54 self.controller_reference = FCRemoteEngineRefFromService(self)
55 self.controller_tub = Tub()
56 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
57 self.controller_tub.setLocation('127.0.0.1:10105')
58
59 furl = self.controller_tub.registerReference(self.controller_reference)
60 self.controller_tub.startService()
61
62 # Start an EngineService and append to services/client
63 self.engine_service = es.EngineService()
64 self.engine_service.startService()
65 self.engine_tub = Tub()
66 self.engine_tub.startService()
67 engine_connector = EngineConnector(self.engine_tub)
68 d = engine_connector.connect_to_controller(self.engine_service, furl)
69 # This deferred doesn't fire until after register_engine has returned and
70 # thus, self.engine has been defined and the tets can proceed.
71 return d
58 72
59 # Start an EngineService and append to services/client
60 self.engine_service = es.EngineService()
61 self.engine_service.startService()
62 self.engine_tub = Tub()
63 self.engine_tub.startService()
64 engine_connector = EngineConnector(self.engine_tub)
65 d = engine_connector.connect_to_controller(self.engine_service, furl)
66 # This deferred doesn't fire until after register_engine has returned and
67 # thus, self.engine has been defined and the tets can proceed.
68 return d
69
70 def tearDown(self):
71 dlist = []
72 # Shut down the engine
73 d = self.engine_tub.stopService()
74 dlist.append(d)
75 # Shut down the controller
76 d = self.controller_tub.stopService()
77 dlist.append(d)
78 return defer.DeferredList(dlist)
79
80 #---------------------------------------------------------------------------
81 # Make me look like a basic controller
82 #---------------------------------------------------------------------------
83
84 def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None):
85 self.engine = IEngineQueued(IEngineBase(engine_ref))
86 return {'id':id}
87
88 def unregister_engine(self, id):
89 pass No newline at end of file
73 def tearDown(self):
74 dlist = []
75 # Shut down the engine
76 d = self.engine_tub.stopService()
77 dlist.append(d)
78 # Shut down the controller
79 d = self.controller_tub.stopService()
80 dlist.append(d)
81 return defer.DeferredList(dlist)
82
83 #---------------------------------------------------------------------------
84 # Make me look like a basic controller
85 #---------------------------------------------------------------------------
86
87 def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None):
88 self.engine = IEngineQueued(IEngineBase(engine_ref))
89 return {'id':id}
90
91 def unregister_engine(self, id):
92 pass No newline at end of file
@@ -23,42 +23,44 b' __docformat__ = "restructuredtext en"'
23 23 # Imports
24 24 #-------------------------------------------------------------------------------
25 25
26 from twisted.internet import defer
27 from twisted.application.service import IService
28
29 from IPython.kernel import engineservice as es
30 from IPython.testing.util import DeferredTestCase
31 from IPython.kernel.tests.engineservicetest import \
32 IEngineCoreTestCase, \
33 IEngineSerializedTestCase, \
34 IEngineQueuedTestCase, \
35 IEnginePropertiesTestCase
26 try:
27 from twisted.internet import defer
28 from twisted.application.service import IService
36 29
37
38 class BasicEngineServiceTest(DeferredTestCase,
39 IEngineCoreTestCase,
40 IEngineSerializedTestCase,
41 IEnginePropertiesTestCase):
30 from IPython.kernel import engineservice as es
31 from IPython.testing.util import DeferredTestCase
32 from IPython.kernel.tests.engineservicetest import \
33 IEngineCoreTestCase, \
34 IEngineSerializedTestCase, \
35 IEngineQueuedTestCase, \
36 IEnginePropertiesTestCase
37 except ImportError:
38 pass
39 else:
40 class BasicEngineServiceTest(DeferredTestCase,
41 IEngineCoreTestCase,
42 IEngineSerializedTestCase,
43 IEnginePropertiesTestCase):
42 44
43 def setUp(self):
44 self.engine = es.EngineService()
45 self.engine.startService()
45 def setUp(self):
46 self.engine = es.EngineService()
47 self.engine.startService()
46 48
47 def tearDown(self):
48 return self.engine.stopService()
49 def tearDown(self):
50 return self.engine.stopService()
49 51
50 class QueuedEngineServiceTest(DeferredTestCase,
51 IEngineCoreTestCase,
52 IEngineSerializedTestCase,
53 IEnginePropertiesTestCase,
54 IEngineQueuedTestCase):
52 class QueuedEngineServiceTest(DeferredTestCase,
53 IEngineCoreTestCase,
54 IEngineSerializedTestCase,
55 IEnginePropertiesTestCase,
56 IEngineQueuedTestCase):
55 57
56 def setUp(self):
57 self.rawEngine = es.EngineService()
58 self.rawEngine.startService()
59 self.engine = es.IEngineQueued(self.rawEngine)
58 def setUp(self):
59 self.rawEngine = es.EngineService()
60 self.rawEngine.startService()
61 self.engine = es.IEngineQueued(self.rawEngine)
60 62
61 def tearDown(self):
62 return self.rawEngine.stopService()
63 def tearDown(self):
64 return self.rawEngine.stopService()
63 65
64 66
@@ -15,38 +15,40 b' __docformat__ = "restructuredtext en"'
15 15 # Imports
16 16 #-------------------------------------------------------------------------------
17 17
18 from twisted.internet import defer
19 from IPython.testing.util import DeferredTestCase
20 from IPython.kernel.controllerservice import ControllerService
21 from IPython.kernel import multiengine as me
22 from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase,
23 ISynchronousMultiEngineTestCase)
18 try:
19 from twisted.internet import defer
20 from IPython.testing.util import DeferredTestCase
21 from IPython.kernel.controllerservice import ControllerService
22 from IPython.kernel import multiengine as me
23 from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase,
24 ISynchronousMultiEngineTestCase)
25 except ImportError:
26 pass
27 else:
28 class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase):
24 29
25
26 class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase):
27
28 def setUp(self):
29 self.controller = ControllerService()
30 self.controller.startService()
31 self.multiengine = me.IMultiEngine(self.controller)
32 self.engines = []
30 def setUp(self):
31 self.controller = ControllerService()
32 self.controller.startService()
33 self.multiengine = me.IMultiEngine(self.controller)
34 self.engines = []
33 35
34 def tearDown(self):
35 self.controller.stopService()
36 for e in self.engines:
37 e.stopService()
36 def tearDown(self):
37 self.controller.stopService()
38 for e in self.engines:
39 e.stopService()
38 40
39 41
40 class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase):
42 class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase):
41 43
42 def setUp(self):
43 self.controller = ControllerService()
44 self.controller.startService()
45 self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller))
46 self.engines = []
44 def setUp(self):
45 self.controller = ControllerService()
46 self.controller.startService()
47 self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller))
48 self.engines = []
47 49
48 def tearDown(self):
49 self.controller.stopService()
50 for e in self.engines:
51 e.stopService()
50 def tearDown(self):
51 self.controller.stopService()
52 for e in self.engines:
53 e.stopService()
52 54
@@ -14,55 +14,57 b' __docformat__ = "restructuredtext en"'
14 14 # Imports
15 15 #-------------------------------------------------------------------------------
16 16
17 from twisted.internet import defer, reactor
17 try:
18 from twisted.internet import defer, reactor
18 19
19 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
20 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
20 21
21 from IPython.testing.util import DeferredTestCase
22 from IPython.kernel.controllerservice import ControllerService
23 from IPython.kernel.multiengine import IMultiEngine
24 from IPython.kernel.tests.multienginetest import IFullSynchronousMultiEngineTestCase
25 from IPython.kernel.multienginefc import IFCSynchronousMultiEngine
26 from IPython.kernel import multiengine as me
27 from IPython.kernel.clientconnector import ClientConnector
28
29
30 class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase):
22 from IPython.testing.util import DeferredTestCase
23 from IPython.kernel.controllerservice import ControllerService
24 from IPython.kernel.multiengine import IMultiEngine
25 from IPython.kernel.tests.multienginetest import IFullSynchronousMultiEngineTestCase
26 from IPython.kernel.multienginefc import IFCSynchronousMultiEngine
27 from IPython.kernel import multiengine as me
28 from IPython.kernel.clientconnector import ClientConnector
29 except ImportError:
30 pass
31 else:
32 class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase):
31 33
32 def setUp(self):
34 def setUp(self):
33 35
34 self.engines = []
36 self.engines = []
35 37
36 self.controller = ControllerService()
37 self.controller.startService()
38 self.imultiengine = IMultiEngine(self.controller)
39 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
38 self.controller = ControllerService()
39 self.controller.startService()
40 self.imultiengine = IMultiEngine(self.controller)
41 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
40 42
41 self.controller_tub = Tub()
42 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
43 self.controller_tub.setLocation('127.0.0.1:10105')
43 self.controller_tub = Tub()
44 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
45 self.controller_tub.setLocation('127.0.0.1:10105')
44 46
45 furl = self.controller_tub.registerReference(self.mec_referenceable)
46 self.controller_tub.startService()
47 furl = self.controller_tub.registerReference(self.mec_referenceable)
48 self.controller_tub.startService()
47 49
48 self.client_tub = ClientConnector()
49 d = self.client_tub.get_multiengine_client(furl)
50 d.addCallback(self.handle_got_client)
51 return d
50 self.client_tub = ClientConnector()
51 d = self.client_tub.get_multiengine_client(furl)
52 d.addCallback(self.handle_got_client)
53 return d
52 54
53 def handle_got_client(self, client):
54 self.multiengine = client
55 def handle_got_client(self, client):
56 self.multiengine = client
55 57
56 def tearDown(self):
57 dlist = []
58 # Shut down the multiengine client
59 d = self.client_tub.tub.stopService()
60 dlist.append(d)
61 # Shut down the engines
62 for e in self.engines:
63 e.stopService()
64 # Shut down the controller
65 d = self.controller_tub.stopService()
66 d.addBoth(lambda _: self.controller.stopService())
67 dlist.append(d)
68 return defer.DeferredList(dlist)
58 def tearDown(self):
59 dlist = []
60 # Shut down the multiengine client
61 d = self.client_tub.tub.stopService()
62 dlist.append(d)
63 # Shut down the engines
64 for e in self.engines:
65 e.stopService()
66 # Shut down the controller
67 d = self.controller_tub.stopService()
68 d.addBoth(lambda _: self.controller.stopService())
69 dlist.append(d)
70 return defer.DeferredList(dlist)
@@ -15,85 +15,88 b' __docformat__ = "restructuredtext en"'
15 15 # Imports
16 16 #-------------------------------------------------------------------------------
17 17
18 import zope.interface as zi
19 from twisted.trial import unittest
20 from IPython.testing.util import DeferredTestCase
18 try:
19 import zope.interface as zi
20 from twisted.trial import unittest
21 from IPython.testing.util import DeferredTestCase
21 22
22 from IPython.kernel.newserialized import \
23 ISerialized, \
24 IUnSerialized, \
25 Serialized, \
26 UnSerialized, \
27 SerializeIt, \
28 UnSerializeIt
23 from IPython.kernel.newserialized import \
24 ISerialized, \
25 IUnSerialized, \
26 Serialized, \
27 UnSerialized, \
28 SerializeIt, \
29 UnSerializeIt
30 except ImportError:
31 pass
32 else:
33 #-------------------------------------------------------------------------------
34 # Tests
35 #-------------------------------------------------------------------------------
29 36
30 #-------------------------------------------------------------------------------
31 # Tests
32 #-------------------------------------------------------------------------------
33
34 class SerializedTestCase(unittest.TestCase):
37 class SerializedTestCase(unittest.TestCase):
35 38
36 def setUp(self):
37 pass
39 def setUp(self):
40 pass
38 41
39 def tearDown(self):
40 pass
42 def tearDown(self):
43 pass
41 44
42 def testSerializedInterfaces(self):
45 def testSerializedInterfaces(self):
43 46
44 us = UnSerialized({'a':10, 'b':range(10)})
45 s = ISerialized(us)
46 uss = IUnSerialized(s)
47 self.assert_(ISerialized.providedBy(s))
48 self.assert_(IUnSerialized.providedBy(us))
49 self.assert_(IUnSerialized.providedBy(uss))
50 for m in list(ISerialized):
51 self.assert_(hasattr(s, m))
52 for m in list(IUnSerialized):
53 self.assert_(hasattr(us, m))
54 for m in list(IUnSerialized):
55 self.assert_(hasattr(uss, m))
47 us = UnSerialized({'a':10, 'b':range(10)})
48 s = ISerialized(us)
49 uss = IUnSerialized(s)
50 self.assert_(ISerialized.providedBy(s))
51 self.assert_(IUnSerialized.providedBy(us))
52 self.assert_(IUnSerialized.providedBy(uss))
53 for m in list(ISerialized):
54 self.assert_(hasattr(s, m))
55 for m in list(IUnSerialized):
56 self.assert_(hasattr(us, m))
57 for m in list(IUnSerialized):
58 self.assert_(hasattr(uss, m))
56 59
57 def testPickleSerialized(self):
58 obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
59 original = UnSerialized(obj)
60 originalSer = ISerialized(original)
61 firstData = originalSer.getData()
62 firstTD = originalSer.getTypeDescriptor()
63 firstMD = originalSer.getMetadata()
64 self.assert_(firstTD == 'pickle')
65 self.assert_(firstMD == {})
66 unSerialized = IUnSerialized(originalSer)
67 secondObj = unSerialized.getObject()
68 for k, v in secondObj.iteritems():
69 self.assert_(obj[k] == v)
70 secondSer = ISerialized(UnSerialized(secondObj))
71 self.assert_(firstData == secondSer.getData())
72 self.assert_(firstTD == secondSer.getTypeDescriptor() )
73 self.assert_(firstMD == secondSer.getMetadata())
60 def testPickleSerialized(self):
61 obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
62 original = UnSerialized(obj)
63 originalSer = ISerialized(original)
64 firstData = originalSer.getData()
65 firstTD = originalSer.getTypeDescriptor()
66 firstMD = originalSer.getMetadata()
67 self.assert_(firstTD == 'pickle')
68 self.assert_(firstMD == {})
69 unSerialized = IUnSerialized(originalSer)
70 secondObj = unSerialized.getObject()
71 for k, v in secondObj.iteritems():
72 self.assert_(obj[k] == v)
73 secondSer = ISerialized(UnSerialized(secondObj))
74 self.assert_(firstData == secondSer.getData())
75 self.assert_(firstTD == secondSer.getTypeDescriptor() )
76 self.assert_(firstMD == secondSer.getMetadata())
74 77
75 def testNDArraySerialized(self):
76 try:
77 import numpy
78 except ImportError:
79 pass
80 else:
81 a = numpy.linspace(0.0, 1.0, 1000)
82 unSer1 = UnSerialized(a)
83 ser1 = ISerialized(unSer1)
84 td = ser1.getTypeDescriptor()
85 self.assert_(td == 'ndarray')
86 md = ser1.getMetadata()
87 self.assert_(md['shape'] == a.shape)
88 self.assert_(md['dtype'] == a.dtype.str)
89 buff = ser1.getData()
90 self.assert_(buff == numpy.getbuffer(a))
91 s = Serialized(buff, td, md)
92 us = IUnSerialized(s)
93 final = us.getObject()
94 self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final))
95 self.assert_(a.dtype.str == final.dtype.str)
96 self.assert_(a.shape == final.shape)
78 def testNDArraySerialized(self):
79 try:
80 import numpy
81 except ImportError:
82 pass
83 else:
84 a = numpy.linspace(0.0, 1.0, 1000)
85 unSer1 = UnSerialized(a)
86 ser1 = ISerialized(unSer1)
87 td = ser1.getTypeDescriptor()
88 self.assert_(td == 'ndarray')
89 md = ser1.getMetadata()
90 self.assert_(md['shape'] == a.shape)
91 self.assert_(md['dtype'] == a.dtype.str)
92 buff = ser1.getData()
93 self.assert_(buff == numpy.getbuffer(a))
94 s = Serialized(buff, td, md)
95 us = IUnSerialized(s)
96 final = us.getObject()
97 self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final))
98 self.assert_(a.dtype.str == final.dtype.str)
99 self.assert_(a.shape == final.shape)
97 100
98 101
99 102 No newline at end of file
@@ -16,191 +16,194 b' __docformat__ = "restructuredtext en"'
16 16 # Imports
17 17 #-------------------------------------------------------------------------------
18 18
19 from twisted.internet import defer
20 from twisted.python import failure
19 try:
20 from twisted.internet import defer
21 from twisted.python import failure
21 22
22 from IPython.testing import tcommon
23 from IPython.testing.tcommon import *
24 from IPython.testing.util import DeferredTestCase
25 import IPython.kernel.pendingdeferred as pd
26 from IPython.kernel import error
27 from IPython.kernel.util import printer
23 from IPython.testing import tcommon
24 from IPython.testing.tcommon import *
25 from IPython.testing.util import DeferredTestCase
26 import IPython.kernel.pendingdeferred as pd
27 from IPython.kernel import error
28 from IPython.kernel.util import printer
29 except ImportError:
30 pass
31 else:
28 32
29
30 #-------------------------------------------------------------------------------
31 # Setup for inline and standalone doctests
32 #-------------------------------------------------------------------------------
33 #-------------------------------------------------------------------------------
34 # Setup for inline and standalone doctests
35 #-------------------------------------------------------------------------------
33 36
34 37
35 # If you have standalone doctests in a separate file, set their names in the
36 # dt_files variable (as a single string or a list thereof):
37 dt_files = []
38 # If you have standalone doctests in a separate file, set their names in the
39 # dt_files variable (as a single string or a list thereof):
40 dt_files = []
38 41
39 # If you have any modules whose docstrings should be scanned for embedded tests
40 # as examples accorging to standard doctest practice, set them here (as a
41 # single string or a list thereof):
42 dt_modules = []
42 # If you have any modules whose docstrings should be scanned for embedded tests
43 # as examples accorging to standard doctest practice, set them here (as a
44 # single string or a list thereof):
45 dt_modules = []
43 46
44 #-------------------------------------------------------------------------------
45 # Regular Unittests
46 #-------------------------------------------------------------------------------
47 #-------------------------------------------------------------------------------
48 # Regular Unittests
49 #-------------------------------------------------------------------------------
47 50
48 51
49 class Foo(object):
52 class Foo(object):
50 53
51 def bar(self, bahz):
52 return defer.succeed('blahblah: %s' % bahz)
54 def bar(self, bahz):
55 return defer.succeed('blahblah: %s' % bahz)
53 56
54 class TwoPhaseFoo(pd.PendingDeferredManager):
57 class TwoPhaseFoo(pd.PendingDeferredManager):
55 58
56 def __init__(self, foo):
57 self.foo = foo
58 pd.PendingDeferredManager.__init__(self)
59 def __init__(self, foo):
60 self.foo = foo
61 pd.PendingDeferredManager.__init__(self)
59 62
60 @pd.two_phase
61 def bar(self, bahz):
62 return self.foo.bar(bahz)
63 @pd.two_phase
64 def bar(self, bahz):
65 return self.foo.bar(bahz)
63 66
64 class PendingDeferredManagerTest(DeferredTestCase):
67 class PendingDeferredManagerTest(DeferredTestCase):
65 68
66 def setUp(self):
67 self.pdm = pd.PendingDeferredManager()
69 def setUp(self):
70 self.pdm = pd.PendingDeferredManager()
68 71
69 def tearDown(self):
70 pass
72 def tearDown(self):
73 pass
74
75 def testBasic(self):
76 dDict = {}
77 # Create 10 deferreds and save them
78 for i in range(10):
79 d = defer.Deferred()
80 did = self.pdm.save_pending_deferred(d)
81 dDict[did] = d
82 # Make sure they are begin saved
83 for k in dDict.keys():
84 self.assert_(self.pdm.quick_has_id(k))
85 # Get the pending deferred (block=True), then callback with 'foo' and compare
86 for did in dDict.keys()[0:5]:
87 d = self.pdm.get_pending_deferred(did,block=True)
88 dDict[did].callback('foo')
89 d.addCallback(lambda r: self.assert_(r=='foo'))
90 # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised
91 for did in dDict.keys()[5:10]:
92 d = self.pdm.get_pending_deferred(did,block=False)
93 d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
94 # Now callback the last 5, get them and compare.
95 for did in dDict.keys()[5:10]:
96 dDict[did].callback('foo')
97 d = self.pdm.get_pending_deferred(did,block=False)
98 d.addCallback(lambda r: self.assert_(r=='foo'))
71 99
72 def testBasic(self):
73 dDict = {}
74 # Create 10 deferreds and save them
75 for i in range(10):
100 def test_save_then_delete(self):
76 101 d = defer.Deferred()
77 102 did = self.pdm.save_pending_deferred(d)
78 dDict[did] = d
79 # Make sure they are begin saved
80 for k in dDict.keys():
81 self.assert_(self.pdm.quick_has_id(k))
82 # Get the pending deferred (block=True), then callback with 'foo' and compare
83 for did in dDict.keys()[0:5]:
84 d = self.pdm.get_pending_deferred(did,block=True)
85 dDict[did].callback('foo')
86 d.addCallback(lambda r: self.assert_(r=='foo'))
87 # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised
88 for did in dDict.keys()[5:10]:
89 d = self.pdm.get_pending_deferred(did,block=False)
90 d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
91 # Now callback the last 5, get them and compare.
92 for did in dDict.keys()[5:10]:
93 dDict[did].callback('foo')
94 d = self.pdm.get_pending_deferred(did,block=False)
95 d.addCallback(lambda r: self.assert_(r=='foo'))
103 self.assert_(self.pdm.quick_has_id(did))
104 self.pdm.delete_pending_deferred(did)
105 self.assert_(not self.pdm.quick_has_id(did))
96 106
97 def test_save_then_delete(self):
98 d = defer.Deferred()
99 did = self.pdm.save_pending_deferred(d)
100 self.assert_(self.pdm.quick_has_id(did))
101 self.pdm.delete_pending_deferred(did)
102 self.assert_(not self.pdm.quick_has_id(did))
103
104 def test_save_get_delete(self):
105 d = defer.Deferred()
106 did = self.pdm.save_pending_deferred(d)
107 d2 = self.pdm.get_pending_deferred(did,True)
108 d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException))
109 self.pdm.delete_pending_deferred(did)
110 return d2
107 def test_save_get_delete(self):
108 d = defer.Deferred()
109 did = self.pdm.save_pending_deferred(d)
110 d2 = self.pdm.get_pending_deferred(did,True)
111 d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException))
112 self.pdm.delete_pending_deferred(did)
113 return d2
111 114
112 def test_double_get(self):
113 d = defer.Deferred()
114 did = self.pdm.save_pending_deferred(d)
115 d2 = self.pdm.get_pending_deferred(did,True)
116 d3 = self.pdm.get_pending_deferred(did,True)
117 d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException))
115 def test_double_get(self):
116 d = defer.Deferred()
117 did = self.pdm.save_pending_deferred(d)
118 d2 = self.pdm.get_pending_deferred(did,True)
119 d3 = self.pdm.get_pending_deferred(did,True)
120 d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException))
118 121
119 def test_get_after_callback(self):
120 d = defer.Deferred()
121 did = self.pdm.save_pending_deferred(d)
122 d.callback('foo')
123 d2 = self.pdm.get_pending_deferred(did,True)
124 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
125 self.assert_(not self.pdm.quick_has_id(did))
126
127 def test_get_before_callback(self):
128 d = defer.Deferred()
129 did = self.pdm.save_pending_deferred(d)
130 d2 = self.pdm.get_pending_deferred(did,True)
131 d.callback('foo')
132 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
133 self.assert_(not self.pdm.quick_has_id(did))
134 d = defer.Deferred()
135 did = self.pdm.save_pending_deferred(d)
136 d2 = self.pdm.get_pending_deferred(did,True)
137 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
138 d.callback('foo')
139 self.assert_(not self.pdm.quick_has_id(did))
122 def test_get_after_callback(self):
123 d = defer.Deferred()
124 did = self.pdm.save_pending_deferred(d)
125 d.callback('foo')
126 d2 = self.pdm.get_pending_deferred(did,True)
127 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
128 self.assert_(not self.pdm.quick_has_id(did))
129
130 def test_get_before_callback(self):
131 d = defer.Deferred()
132 did = self.pdm.save_pending_deferred(d)
133 d2 = self.pdm.get_pending_deferred(did,True)
134 d.callback('foo')
135 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
136 self.assert_(not self.pdm.quick_has_id(did))
137 d = defer.Deferred()
138 did = self.pdm.save_pending_deferred(d)
139 d2 = self.pdm.get_pending_deferred(did,True)
140 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
141 d.callback('foo')
142 self.assert_(not self.pdm.quick_has_id(did))
140 143
141 def test_get_after_errback(self):
142 class MyError(Exception):
143 pass
144 d = defer.Deferred()
145 did = self.pdm.save_pending_deferred(d)
146 d.errback(failure.Failure(MyError('foo')))
147 d2 = self.pdm.get_pending_deferred(did,True)
148 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
149 self.assert_(not self.pdm.quick_has_id(did))
150
151 def test_get_before_errback(self):
152 class MyError(Exception):
153 pass
154 d = defer.Deferred()
155 did = self.pdm.save_pending_deferred(d)
156 d2 = self.pdm.get_pending_deferred(did,True)
157 d.errback(failure.Failure(MyError('foo')))
158 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
159 self.assert_(not self.pdm.quick_has_id(did))
160 d = defer.Deferred()
161 did = self.pdm.save_pending_deferred(d)
162 d2 = self.pdm.get_pending_deferred(did,True)
163 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
164 d.errback(failure.Failure(MyError('foo')))
165 self.assert_(not self.pdm.quick_has_id(did))
144 def test_get_after_errback(self):
145 class MyError(Exception):
146 pass
147 d = defer.Deferred()
148 did = self.pdm.save_pending_deferred(d)
149 d.errback(failure.Failure(MyError('foo')))
150 d2 = self.pdm.get_pending_deferred(did,True)
151 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
152 self.assert_(not self.pdm.quick_has_id(did))
153
154 def test_get_before_errback(self):
155 class MyError(Exception):
156 pass
157 d = defer.Deferred()
158 did = self.pdm.save_pending_deferred(d)
159 d2 = self.pdm.get_pending_deferred(did,True)
160 d.errback(failure.Failure(MyError('foo')))
161 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
162 self.assert_(not self.pdm.quick_has_id(did))
163 d = defer.Deferred()
164 did = self.pdm.save_pending_deferred(d)
165 d2 = self.pdm.get_pending_deferred(did,True)
166 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
167 d.errback(failure.Failure(MyError('foo')))
168 self.assert_(not self.pdm.quick_has_id(did))
166 169
167 def test_noresult_noblock(self):
168 d = defer.Deferred()
169 did = self.pdm.save_pending_deferred(d)
170 d2 = self.pdm.get_pending_deferred(did,False)
171 d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
172
173 def test_with_callbacks(self):
174 d = defer.Deferred()
175 d.addCallback(lambda r: r+' foo')
176 d.addCallback(lambda r: r+' bar')
177 did = self.pdm.save_pending_deferred(d)
178 d2 = self.pdm.get_pending_deferred(did,True)
179 d.callback('bam')
180 d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar'))
170 def test_noresult_noblock(self):
171 d = defer.Deferred()
172 did = self.pdm.save_pending_deferred(d)
173 d2 = self.pdm.get_pending_deferred(did,False)
174 d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
175
176 def test_with_callbacks(self):
177 d = defer.Deferred()
178 d.addCallback(lambda r: r+' foo')
179 d.addCallback(lambda r: r+' bar')
180 did = self.pdm.save_pending_deferred(d)
181 d2 = self.pdm.get_pending_deferred(did,True)
182 d.callback('bam')
183 d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar'))
181 184
182 def test_with_errbacks(self):
183 class MyError(Exception):
184 pass
185 d = defer.Deferred()
186 d.addCallback(lambda r: 'foo')
187 d.addErrback(lambda f: 'caught error')
188 did = self.pdm.save_pending_deferred(d)
189 d2 = self.pdm.get_pending_deferred(did,True)
190 d.errback(failure.Failure(MyError('bam')))
191 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
185 def test_with_errbacks(self):
186 class MyError(Exception):
187 pass
188 d = defer.Deferred()
189 d.addCallback(lambda r: 'foo')
190 d.addErrback(lambda f: 'caught error')
191 did = self.pdm.save_pending_deferred(d)
192 d2 = self.pdm.get_pending_deferred(did,True)
193 d.errback(failure.Failure(MyError('bam')))
194 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
192 195
193 def test_nested_deferreds(self):
194 d = defer.Deferred()
195 d2 = defer.Deferred()
196 d.addCallback(lambda r: d2)
197 did = self.pdm.save_pending_deferred(d)
198 d.callback('foo')
199 d3 = self.pdm.get_pending_deferred(did,False)
200 d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
201 d2.callback('bar')
202 d3 = self.pdm.get_pending_deferred(did,False)
203 d3.addCallback(lambda r: self.assertEquals(r,'bar'))
196 def test_nested_deferreds(self):
197 d = defer.Deferred()
198 d2 = defer.Deferred()
199 d.addCallback(lambda r: d2)
200 did = self.pdm.save_pending_deferred(d)
201 d.callback('foo')
202 d3 = self.pdm.get_pending_deferred(did,False)
203 d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
204 d2.callback('bar')
205 d3 = self.pdm.get_pending_deferred(did,False)
206 d3.addCallback(lambda r: self.assertEquals(r,'bar'))
204 207
205 208 #-------------------------------------------------------------------------------
206 209 # Regular Unittests
@@ -15,33 +15,36 b' __docformat__ = "restructuredtext en"'
15 15 # Imports
16 16 #-------------------------------------------------------------------------------
17 17
18 import time
19
20 from twisted.internet import defer
21 from twisted.trial import unittest
22
23 from IPython.kernel import task, controllerservice as cs, engineservice as es
24 from IPython.kernel.multiengine import IMultiEngine
25 from IPython.testing.util import DeferredTestCase
26 from IPython.kernel.tests.tasktest import ITaskControllerTestCase
27
28 #-------------------------------------------------------------------------------
29 # Tests
30 #-------------------------------------------------------------------------------
31
32 class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase):
18 try:
19 import time
20
21 from twisted.internet import defer
22 from twisted.trial import unittest
23
24 from IPython.kernel import task, controllerservice as cs, engineservice as es
25 from IPython.kernel.multiengine import IMultiEngine
26 from IPython.testing.util import DeferredTestCase
27 from IPython.kernel.tests.tasktest import ITaskControllerTestCase
28 except ImportError:
29 pass
30 else:
31 #-------------------------------------------------------------------------------
32 # Tests
33 #-------------------------------------------------------------------------------
34
35 class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase):
33 36
34 def setUp(self):
35 self.controller = cs.ControllerService()
36 self.controller.startService()
37 self.multiengine = IMultiEngine(self.controller)
38 self.tc = task.ITaskController(self.controller)
39 self.tc.failurePenalty = 0
40 self.engines=[]
37 def setUp(self):
38 self.controller = cs.ControllerService()
39 self.controller.startService()
40 self.multiengine = IMultiEngine(self.controller)
41 self.tc = task.ITaskController(self.controller)
42 self.tc.failurePenalty = 0
43 self.engines=[]
41 44
42 def tearDown(self):
43 self.controller.stopService()
44 for e in self.engines:
45 e.stopService()
45 def tearDown(self):
46 self.controller.stopService()
47 for e in self.engines:
48 e.stopService()
46 49
47 50
@@ -14,73 +14,77 b' __docformat__ = "restructuredtext en"'
14 14 # Imports
15 15 #-------------------------------------------------------------------------------
16 16
17 import time
17 try:
18 import time
18 19
19 from twisted.internet import defer, reactor
20 from twisted.internet import defer, reactor
20 21
21 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
22 from IPython.kernel.fcutil import Tub, UnauthenticatedTub
22 23
23 from IPython.kernel import task as taskmodule
24 from IPython.kernel import controllerservice as cs
25 import IPython.kernel.multiengine as me
26 from IPython.testing.util import DeferredTestCase
27 from IPython.kernel.multienginefc import IFCSynchronousMultiEngine
28 from IPython.kernel.taskfc import IFCTaskController
29 from IPython.kernel.util import printer
30 from IPython.kernel.tests.tasktest import ITaskControllerTestCase
31 from IPython.kernel.clientconnector import ClientConnector
24 from IPython.kernel import task as taskmodule
25 from IPython.kernel import controllerservice as cs
26 import IPython.kernel.multiengine as me
27 from IPython.testing.util import DeferredTestCase
28 from IPython.kernel.multienginefc import IFCSynchronousMultiEngine
29 from IPython.kernel.taskfc import IFCTaskController
30 from IPython.kernel.util import printer
31 from IPython.kernel.tests.tasktest import ITaskControllerTestCase
32 from IPython.kernel.clientconnector import ClientConnector
33 except ImportError:
34 pass
35 else:
32 36
33 #-------------------------------------------------------------------------------
34 # Tests
35 #-------------------------------------------------------------------------------
37 #-------------------------------------------------------------------------------
38 # Tests
39 #-------------------------------------------------------------------------------
36 40
37 class TaskTest(DeferredTestCase, ITaskControllerTestCase):
41 class TaskTest(DeferredTestCase, ITaskControllerTestCase):
38 42
39 def setUp(self):
43 def setUp(self):
40 44
41 self.engines = []
45 self.engines = []
42 46
43 self.controller = cs.ControllerService()
44 self.controller.startService()
45 self.imultiengine = me.IMultiEngine(self.controller)
46 self.itc = taskmodule.ITaskController(self.controller)
47 self.itc.failurePenalty = 0
47 self.controller = cs.ControllerService()
48 self.controller.startService()
49 self.imultiengine = me.IMultiEngine(self.controller)
50 self.itc = taskmodule.ITaskController(self.controller)
51 self.itc.failurePenalty = 0
48 52
49 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
50 self.tc_referenceable = IFCTaskController(self.itc)
53 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
54 self.tc_referenceable = IFCTaskController(self.itc)
51 55
52 self.controller_tub = Tub()
53 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
54 self.controller_tub.setLocation('127.0.0.1:10105')
56 self.controller_tub = Tub()
57 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
58 self.controller_tub.setLocation('127.0.0.1:10105')
55 59
56 mec_furl = self.controller_tub.registerReference(self.mec_referenceable)
57 tc_furl = self.controller_tub.registerReference(self.tc_referenceable)
58 self.controller_tub.startService()
60 mec_furl = self.controller_tub.registerReference(self.mec_referenceable)
61 tc_furl = self.controller_tub.registerReference(self.tc_referenceable)
62 self.controller_tub.startService()
59 63
60 self.client_tub = ClientConnector()
61 d = self.client_tub.get_multiengine_client(mec_furl)
62 d.addCallback(self.handle_mec_client)
63 d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl))
64 d.addCallback(self.handle_tc_client)
65 return d
64 self.client_tub = ClientConnector()
65 d = self.client_tub.get_multiengine_client(mec_furl)
66 d.addCallback(self.handle_mec_client)
67 d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl))
68 d.addCallback(self.handle_tc_client)
69 return d
66 70
67 def handle_mec_client(self, client):
68 self.multiengine = client
71 def handle_mec_client(self, client):
72 self.multiengine = client
69 73
70 def handle_tc_client(self, client):
71 self.tc = client
74 def handle_tc_client(self, client):
75 self.tc = client
72 76
73 def tearDown(self):
74 dlist = []
75 # Shut down the multiengine client
76 d = self.client_tub.tub.stopService()
77 dlist.append(d)
78 # Shut down the engines
79 for e in self.engines:
80 e.stopService()
81 # Shut down the controller
82 d = self.controller_tub.stopService()
83 d.addBoth(lambda _: self.controller.stopService())
84 dlist.append(d)
85 return defer.DeferredList(dlist)
77 def tearDown(self):
78 dlist = []
79 # Shut down the multiengine client
80 d = self.client_tub.tub.stopService()
81 dlist.append(d)
82 # Shut down the engines
83 for e in self.engines:
84 e.stopService()
85 # Shut down the controller
86 d = self.controller_tub.stopService()
87 d.addBoth(lambda _: self.controller.stopService())
88 dlist.append(d)
89 return defer.DeferredList(dlist)
86 90
@@ -8,6 +8,11 b' graft setupext'
8 8
9 9 graft IPython/UserConfig
10 10
11 graft IPython/kernel
12 graft IPython/config
13 graft IPython/testing
14 graft IPython/tools
15
11 16 graft doc
12 17 exclude doc/\#*
13 18 exclude doc/*.1
@@ -72,12 +72,7 b" if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):"
72 72
73 73 # List of things to be updated. Each entry is a triplet of args for
74 74 # target_update()
75 to_update = [ # The do_sphinx scripts builds html and pdf, so just one
76 # target is enough to cover all manual generation
77 ('doc/manual/ipython.pdf',
78 ['IPython/Release.py','doc/source/ipython.rst'],
79 "cd doc && python do_sphinx.py" ),
80
75 to_update = [
81 76 # FIXME - Disabled for now: we need to redo an automatic way
82 77 # of generating the magic info inside the rst.
83 78 #('doc/magic.tex',
@@ -93,6 +88,18 b" if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):"
93 88 "cd doc && gzip -9c pycolor.1 > pycolor.1.gz"),
94 89 ]
95 90
91 try:
92 import sphinx
93 except ImportError:
94 pass
95 else:
96 # The do_sphinx scripts builds html and pdf, so just one
97 # target is enough to cover all manual generation
98 to_update.append(
99 ('doc/manual/ipython.pdf',
100 ['IPython/Release.py','doc/source/ipython.rst'],
101 "cd doc && python do_sphinx.py")
102 )
96 103 [ target_update(*t) for t in to_update ]
97 104
98 105 #---------------------------------------------------------------------------
@@ -152,9 +159,6 b' else:'
152 159 # Do the actual setup now
153 160 #---------------------------------------------------------------------------
154 161
155 print packages
156
157
158 162 setup_args['packages'] = packages
159 163 setup_args['package_data'] = package_data
160 164 setup_args['scripts'] = scripts
@@ -11,7 +11,7 b" sys.path.insert(0,'%s/usr/local/lib/python%s/site-packages' %"
11 11
12 12 # now, import setuptools and call the actual setup
13 13 import setuptools
14 print sys.argv
14 # print sys.argv
15 15 #sys.argv=['','bdist_egg']
16 16 execfile('setup.py')
17 17
General Comments 0
You need to be logged in to leave comments. Login now