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