##// END OF EJS Templates
Fixing tests that are broken when dependencies are missing....
Brian Granger -
r1557:50c55f4b merge
parent child Browse files
Show More
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
@@ -26,10 +26,10 b' zope.interface is required to run asynchronous frontends.""" % e.message'
26 26
27 27 from frontendbase import FrontEndBase, IFrontEnd, IFrontEndFactory
28 28
29 from IPython.kernel.engineservice import IEngineCore
30 29 from IPython.kernel.core.history import FrontEndHistory
31 30
32 31 try:
32 from IPython.kernel.engineservice import IEngineCore
33 33 from twisted.python.failure import Failure
34 34 except ImportError, e:
35 35 e.message = """%s
@@ -14,28 +14,31 b' __docformat__ = "restructuredtext en"'
14 14 #---------------------------------------------------------------------------
15 15 # Imports
16 16 #---------------------------------------------------------------------------
17 from IPython.kernel.core.interpreter import Interpreter
18 import IPython.kernel.engineservice as es
19 from IPython.testing.util import DeferredTestCase
20 from twisted.internet.defer import succeed
21 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController
22
23 from Foundation import NSMakeRect
24 from AppKit import NSTextView, NSScrollView
17
18 try:
19 from IPython.kernel.core.interpreter import Interpreter
20 import IPython.kernel.engineservice as es
21 from IPython.testing.util import DeferredTestCase
22 from twisted.internet.defer import succeed
23 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController
24 from Foundation import NSMakeRect
25 from AppKit import NSTextView, NSScrollView
26 except ImportError:
27 import nose
28 raise nose.SkipTest("This test requires zope.interface, Twisted, Foolscap and PyObjC")
25 29
26 30 class TestIPythonCocoaControler(DeferredTestCase):
27 31 """Tests for IPythonCocoaController"""
28
32
29 33 def setUp(self):
30 34 self.controller = IPythonCocoaController.alloc().init()
31 35 self.engine = es.EngineService()
32 36 self.engine.startService()
33
34
37
35 38 def tearDown(self):
36 39 self.controller = None
37 40 self.engine.stopService()
38
41
39 42 def testControllerExecutesCode(self):
40 43 code ="""5+5"""
41 44 expected = Interpreter().execute(code)
@@ -47,45 +50,45 b' class TestIPythonCocoaControler(DeferredTestCase):'
47 50 self.assertDeferredEquals(
48 51 self.controller.execute(code).addCallback(removeNumberAndID),
49 52 expected)
50
53
51 54 def testControllerMirrorsUserNSWithValuesAsStrings(self):
52 55 code = """userns1=1;userns2=2"""
53 56 def testControllerUserNS(result):
54 57 self.assertEquals(self.controller.userNS['userns1'], 1)
55 58 self.assertEquals(self.controller.userNS['userns2'], 2)
56
59
57 60 self.controller.execute(code).addCallback(testControllerUserNS)
58
59
61
62
60 63 def testControllerInstantiatesIEngine(self):
61 64 self.assert_(es.IEngineBase.providedBy(self.controller.engine))
62
65
63 66 def testControllerCompletesToken(self):
64 67 code = """longNameVariable=10"""
65 68 def testCompletes(result):
66 69 self.assert_("longNameVariable" in result)
67
70
68 71 def testCompleteToken(result):
69 72 self.controller.complete("longNa").addCallback(testCompletes)
70
73
71 74 self.controller.execute(code).addCallback(testCompletes)
72
73
75
76
74 77 def testCurrentIndent(self):
75 78 """test that current_indent_string returns current indent or None.
76 79 Uses _indent_for_block for direct unit testing.
77 80 """
78
81
79 82 self.controller.tabUsesSpaces = True
80 83 self.assert_(self.controller._indent_for_block("""a=3""") == None)
81 84 self.assert_(self.controller._indent_for_block("") == None)
82 85 block = """def test():\n a=3"""
83 86 self.assert_(self.controller._indent_for_block(block) == \
84 87 ' ' * self.controller.tabSpaces)
85
88
86 89 block = """if(True):\n%sif(False):\n%spass""" % \
87 90 (' '*self.controller.tabSpaces,
88 91 2*' '*self.controller.tabSpaces)
89 92 self.assert_(self.controller._indent_for_block(block) == \
90 93 2*(' '*self.controller.tabSpaces))
91
94
@@ -28,7 +28,6 b' from zopeinterface import Interface, Attribute, implements, classProvides'
28 28
29 29 from IPython.kernel.core.history import FrontEndHistory
30 30 from IPython.kernel.core.util import Bunch
31 from IPython.kernel.engineservice import IEngineCore
32 31
33 32 ##############################################################################
34 33 # TEMPORARY!!! fake configuration, while we decide whether to use tconfig or
@@ -16,9 +16,14 b' __docformat__ = "restructuredtext en"'
16 16 #---------------------------------------------------------------------------
17 17
18 18 import unittest
19 from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase
20 from IPython.frontend import frontendbase
21 from IPython.kernel.engineservice import EngineService
19
20 try:
21 from IPython.frontend.asyncfrontendbase import AsyncFrontEndBase
22 from IPython.frontend import frontendbase
23 from IPython.kernel.engineservice import EngineService
24 except ImportError:
25 import nose
26 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
22 27
23 28 class FrontEndCallbackChecker(AsyncFrontEndBase):
24 29 """FrontEndBase subclass for checking callbacks"""
@@ -28,11 +33,11 b' class FrontEndCallbackChecker(AsyncFrontEndBase):'
28 33 self.updateCalled = False
29 34 self.renderResultCalled = False
30 35 self.renderErrorCalled = False
31
36
32 37 def update_cell_prompt(self, result, blockID=None):
33 38 self.updateCalled = True
34 39 return result
35
40
36 41 def render_result(self, result):
37 42 self.renderResultCalled = True
38 43 return result
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
1 NO CONTENT: modified file chmod 100755 => 100644
@@ -20,7 +20,6 b' from twisted.internet import defer'
20 20 from IPython.kernel import engineservice as es
21 21 from IPython.kernel import multiengine as me
22 22 from IPython.kernel import newserialized
23 from IPython.kernel.error import NotDefined
24 23 from IPython.testing import util
25 24 from IPython.testing.parametric import parametric, Parametric
26 25 from IPython.kernel import newserialized
@@ -30,14 +30,15 b' try:'
30 30 from controllertest import IControllerCoreTestCase
31 31 from IPython.testing.util import DeferredTestCase
32 32 except ImportError:
33 pass
34 else:
35 class BasicControllerServiceTest(DeferredTestCase,
36 IControllerCoreTestCase):
37
38 def setUp(self):
39 self.controller = ControllerService()
40 self.controller.startService()
41
42 def tearDown(self):
43 self.controller.stopService()
33 import nose
34 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
35
36 class BasicControllerServiceTest(DeferredTestCase,
37 IControllerCoreTestCase):
38
39 def setUp(self):
40 self.controller = ControllerService()
41 self.controller.startService()
42
43 def tearDown(self):
44 self.controller.stopService()
@@ -37,56 +37,57 b' try:'
37 37 IEngineSerializedTestCase, \
38 38 IEngineQueuedTestCase
39 39 except ImportError:
40 print "we got an error!!!"
41 raise
42 else:
43 class EngineFCTest(DeferredTestCase,
44 IEngineCoreTestCase,
45 IEngineSerializedTestCase,
46 IEngineQueuedTestCase
47 ):
48
49 zi.implements(IControllerBase)
50
51 def setUp(self):
52
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
72
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
40 import nose
41 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
42
43
44 class EngineFCTest(DeferredTestCase,
45 IEngineCoreTestCase,
46 IEngineSerializedTestCase,
47 IEngineQueuedTestCase
48 ):
49
50 zi.implements(IControllerBase)
51
52 def setUp(self):
53
54 # Start a server and append to self.servers
55 self.controller_reference = FCRemoteEngineRefFromService(self)
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')
59
60 furl = self.controller_tub.registerReference(self.controller_reference)
61 self.controller_tub.startService()
62
63 # Start an EngineService and append to services/client
64 self.engine_service = es.EngineService()
65 self.engine_service.startService()
66 self.engine_tub = Tub()
67 self.engine_tub.startService()
68 engine_connector = EngineConnector(self.engine_tub)
69 d = engine_connector.connect_to_controller(self.engine_service, furl)
70 # This deferred doesn't fire until after register_engine has returned and
71 # thus, self.engine has been defined and the tets can proceed.
72 return d
73
74 def tearDown(self):
75 dlist = []
76 # Shut down the engine
77 d = self.engine_tub.stopService()
78 dlist.append(d)
79 # Shut down the controller
80 d = self.controller_tub.stopService()
81 dlist.append(d)
82 return defer.DeferredList(dlist)
83
84 #---------------------------------------------------------------------------
85 # Make me look like a basic controller
86 #---------------------------------------------------------------------------
87
88 def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None):
89 self.engine = IEngineQueued(IEngineBase(engine_ref))
90 return {'id':id}
91
92 def unregister_engine(self, id):
93 pass No newline at end of file
@@ -35,44 +35,46 b' try:'
35 35 IEngineQueuedTestCase, \
36 36 IEnginePropertiesTestCase
37 37 except ImportError:
38 pass
39 else:
40 class BasicEngineServiceTest(DeferredTestCase,
41 IEngineCoreTestCase,
42 IEngineSerializedTestCase,
43 IEnginePropertiesTestCase):
44
45 def setUp(self):
46 self.engine = es.EngineService()
47 self.engine.startService()
48
49 def tearDown(self):
50 return self.engine.stopService()
51
52 class ThreadedEngineServiceTest(DeferredTestCase,
53 IEngineCoreTestCase,
54 IEngineSerializedTestCase,
55 IEnginePropertiesTestCase):
56
57 def setUp(self):
58 self.engine = es.ThreadedEngineService()
59 self.engine.startService()
38 import nose
39 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
40
41
42 class BasicEngineServiceTest(DeferredTestCase,
43 IEngineCoreTestCase,
44 IEngineSerializedTestCase,
45 IEnginePropertiesTestCase):
46
47 def setUp(self):
48 self.engine = es.EngineService()
49 self.engine.startService()
50
51 def tearDown(self):
52 return self.engine.stopService()
53
54 class ThreadedEngineServiceTest(DeferredTestCase,
55 IEngineCoreTestCase,
56 IEngineSerializedTestCase,
57 IEnginePropertiesTestCase):
58
59 def setUp(self):
60 self.engine = es.ThreadedEngineService()
61 self.engine.startService()
62
63 def tearDown(self):
64 return self.engine.stopService()
65
66 class QueuedEngineServiceTest(DeferredTestCase,
67 IEngineCoreTestCase,
68 IEngineSerializedTestCase,
69 IEnginePropertiesTestCase,
70 IEngineQueuedTestCase):
71
72 def setUp(self):
73 self.rawEngine = es.EngineService()
74 self.rawEngine.startService()
75 self.engine = es.IEngineQueued(self.rawEngine)
60 76
61 def tearDown(self):
62 return self.engine.stopService()
63
64 class QueuedEngineServiceTest(DeferredTestCase,
65 IEngineCoreTestCase,
66 IEngineSerializedTestCase,
67 IEnginePropertiesTestCase,
68 IEngineQueuedTestCase):
69
70 def setUp(self):
71 self.rawEngine = es.EngineService()
72 self.rawEngine.startService()
73 self.engine = es.IEngineQueued(self.rawEngine)
74
75 def tearDown(self):
76 return self.rawEngine.stopService()
77
78
77 def tearDown(self):
78 return self.rawEngine.stopService()
79
80
@@ -23,32 +23,34 b' try:'
23 23 from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase,
24 24 ISynchronousMultiEngineTestCase)
25 25 except ImportError:
26 pass
27 else:
28 class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase):
26 import nose
27 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
28
29
30 class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase):
31
32 def setUp(self):
33 self.controller = ControllerService()
34 self.controller.startService()
35 self.multiengine = me.IMultiEngine(self.controller)
36 self.engines = []
29 37
30 def setUp(self):
31 self.controller = ControllerService()
32 self.controller.startService()
33 self.multiengine = me.IMultiEngine(self.controller)
34 self.engines = []
35
36 def tearDown(self):
37 self.controller.stopService()
38 for e in self.engines:
39 e.stopService()
40
41
42 class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase):
38 def tearDown(self):
39 self.controller.stopService()
40 for e in self.engines:
41 e.stopService()
42
43
44 class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase):
45
46 def setUp(self):
47 self.controller = ControllerService()
48 self.controller.startService()
49 self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller))
50 self.engines = []
43 51
44 def setUp(self):
45 self.controller = ControllerService()
46 self.controller.startService()
47 self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller))
48 self.engines = []
49
50 def tearDown(self):
51 self.controller.stopService()
52 for e in self.engines:
53 e.stopService()
52 def tearDown(self):
53 self.controller.stopService()
54 for e in self.engines:
55 e.stopService()
54 56
@@ -30,115 +30,115 b' try:'
30 30 from IPython.kernel.error import CompositeError
31 31 from IPython.kernel.util import printer
32 32 except ImportError:
33 pass
34 else:
33 import nose
34 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
35 35
36 def _raise_it(f):
37 try:
38 f.raiseException()
39 except CompositeError, e:
40 e.raise_exception()
36 def _raise_it(f):
37 try:
38 f.raiseException()
39 except CompositeError, e:
40 e.raise_exception()
41
42
43 class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase):
44
45 def setUp(self):
41 46
47 self.engines = []
48
49 self.controller = ControllerService()
50 self.controller.startService()
51 self.imultiengine = IMultiEngine(self.controller)
52 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
53
54 self.controller_tub = Tub()
55 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
56 self.controller_tub.setLocation('127.0.0.1:10105')
42 57
43 class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase):
58 furl = self.controller_tub.registerReference(self.mec_referenceable)
59 self.controller_tub.startService()
44 60
45 def setUp(self):
46
47 self.engines = []
48
49 self.controller = ControllerService()
50 self.controller.startService()
51 self.imultiengine = IMultiEngine(self.controller)
52 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
53
54 self.controller_tub = Tub()
55 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
56 self.controller_tub.setLocation('127.0.0.1:10105')
57
58 furl = self.controller_tub.registerReference(self.mec_referenceable)
59 self.controller_tub.startService()
60
61 self.client_tub = ClientConnector()
62 d = self.client_tub.get_multiengine_client(furl)
63 d.addCallback(self.handle_got_client)
64 return d
65
66 def handle_got_client(self, client):
67 self.multiengine = client
61 self.client_tub = ClientConnector()
62 d = self.client_tub.get_multiengine_client(furl)
63 d.addCallback(self.handle_got_client)
64 return d
68 65
69 def tearDown(self):
70 dlist = []
71 # Shut down the multiengine client
72 d = self.client_tub.tub.stopService()
73 dlist.append(d)
74 # Shut down the engines
75 for e in self.engines:
76 e.stopService()
77 # Shut down the controller
78 d = self.controller_tub.stopService()
79 d.addBoth(lambda _: self.controller.stopService())
80 dlist.append(d)
81 return defer.DeferredList(dlist)
66 def handle_got_client(self, client):
67 self.multiengine = client
68
69 def tearDown(self):
70 dlist = []
71 # Shut down the multiengine client
72 d = self.client_tub.tub.stopService()
73 dlist.append(d)
74 # Shut down the engines
75 for e in self.engines:
76 e.stopService()
77 # Shut down the controller
78 d = self.controller_tub.stopService()
79 d.addBoth(lambda _: self.controller.stopService())
80 dlist.append(d)
81 return defer.DeferredList(dlist)
82 82
83 def test_mapper(self):
84 self.addEngine(4)
85 m = self.multiengine.mapper()
86 self.assertEquals(m.multiengine,self.multiengine)
87 self.assertEquals(m.dist,'b')
88 self.assertEquals(m.targets,'all')
89 self.assertEquals(m.block,True)
90
91 def test_map_default(self):
92 self.addEngine(4)
93 m = self.multiengine.mapper()
94 d = m.map(lambda x: 2*x, range(10))
95 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
96 d.addCallback(lambda _: self.multiengine.map(lambda x: 2*x, range(10)))
97 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
98 return d
99
100 def test_map_noblock(self):
101 self.addEngine(4)
102 m = self.multiengine.mapper(block=False)
103 d = m.map(lambda x: 2*x, range(10))
104 d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
105 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
106 return d
107
108 def test_mapper_fail(self):
109 self.addEngine(4)
110 m = self.multiengine.mapper()
111 d = m.map(lambda x: 1/0, range(10))
112 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
113 return d
114
115 def test_parallel(self):
116 self.addEngine(4)
117 p = self.multiengine.parallel()
118 self.assert_(isinstance(p, ParallelFunction))
119 @p
120 def f(x): return 2*x
121 d = f(range(10))
122 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
123 return d
124
125 def test_parallel_noblock(self):
126 self.addEngine(1)
127 p = self.multiengine.parallel(block=False)
128 self.assert_(isinstance(p, ParallelFunction))
129 @p
130 def f(x): return 2*x
131 d = f(range(10))
132 d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
133 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
134 return d
135
136 def test_parallel_fail(self):
137 self.addEngine(4)
138 p = self.multiengine.parallel()
139 self.assert_(isinstance(p, ParallelFunction))
140 @p
141 def f(x): return 1/0
142 d = f(range(10))
143 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
144 return d No newline at end of file
83 def test_mapper(self):
84 self.addEngine(4)
85 m = self.multiengine.mapper()
86 self.assertEquals(m.multiengine,self.multiengine)
87 self.assertEquals(m.dist,'b')
88 self.assertEquals(m.targets,'all')
89 self.assertEquals(m.block,True)
90
91 def test_map_default(self):
92 self.addEngine(4)
93 m = self.multiengine.mapper()
94 d = m.map(lambda x: 2*x, range(10))
95 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
96 d.addCallback(lambda _: self.multiengine.map(lambda x: 2*x, range(10)))
97 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
98 return d
99
100 def test_map_noblock(self):
101 self.addEngine(4)
102 m = self.multiengine.mapper(block=False)
103 d = m.map(lambda x: 2*x, range(10))
104 d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
105 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
106 return d
107
108 def test_mapper_fail(self):
109 self.addEngine(4)
110 m = self.multiengine.mapper()
111 d = m.map(lambda x: 1/0, range(10))
112 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
113 return d
114
115 def test_parallel(self):
116 self.addEngine(4)
117 p = self.multiengine.parallel()
118 self.assert_(isinstance(p, ParallelFunction))
119 @p
120 def f(x): return 2*x
121 d = f(range(10))
122 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
123 return d
124
125 def test_parallel_noblock(self):
126 self.addEngine(1)
127 p = self.multiengine.parallel(block=False)
128 self.assert_(isinstance(p, ParallelFunction))
129 @p
130 def f(x): return 2*x
131 d = f(range(10))
132 d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True))
133 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
134 return d
135
136 def test_parallel_fail(self):
137 self.addEngine(4)
138 p = self.multiengine.parallel()
139 self.assert_(isinstance(p, ParallelFunction))
140 @p
141 def f(x): return 1/0
142 d = f(range(10))
143 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
144 return d No newline at end of file
@@ -28,75 +28,75 b' try:'
28 28 SerializeIt, \
29 29 UnSerializeIt
30 30 except ImportError:
31 pass
32 else:
33 #-------------------------------------------------------------------------------
34 # Tests
35 #-------------------------------------------------------------------------------
31 import nose
32 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
33
34 #-------------------------------------------------------------------------------
35 # Tests
36 #-------------------------------------------------------------------------------
37
38 class SerializedTestCase(unittest.TestCase):
39
40 def setUp(self):
41 pass
36 42
37 class SerializedTestCase(unittest.TestCase):
43 def tearDown(self):
44 pass
38 45
39 def setUp(self):
40 pass
41
42 def tearDown(self):
43 pass
44
45 def testSerializedInterfaces(self):
46 def testSerializedInterfaces(self):
46 47
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))
48 us = UnSerialized({'a':10, 'b':range(10)})
49 s = ISerialized(us)
50 uss = IUnSerialized(s)
51 self.assert_(ISerialized.providedBy(s))
52 self.assert_(IUnSerialized.providedBy(us))
53 self.assert_(IUnSerialized.providedBy(uss))
54 for m in list(ISerialized):
55 self.assert_(hasattr(s, m))
56 for m in list(IUnSerialized):
57 self.assert_(hasattr(us, m))
58 for m in list(IUnSerialized):
59 self.assert_(hasattr(uss, m))
59 60
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())
61 def testPickleSerialized(self):
62 obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
63 original = UnSerialized(obj)
64 originalSer = ISerialized(original)
65 firstData = originalSer.getData()
66 firstTD = originalSer.getTypeDescriptor()
67 firstMD = originalSer.getMetadata()
68 self.assert_(firstTD == 'pickle')
69 self.assert_(firstMD == {})
70 unSerialized = IUnSerialized(originalSer)
71 secondObj = unSerialized.getObject()
72 for k, v in secondObj.iteritems():
73 self.assert_(obj[k] == v)
74 secondSer = ISerialized(UnSerialized(secondObj))
75 self.assert_(firstData == secondSer.getData())
76 self.assert_(firstTD == secondSer.getTypeDescriptor() )
77 self.assert_(firstMD == secondSer.getMetadata())
78
79 def testNDArraySerialized(self):
80 try:
81 import numpy
82 except ImportError:
83 pass
84 else:
85 a = numpy.linspace(0.0, 1.0, 1000)
86 unSer1 = UnSerialized(a)
87 ser1 = ISerialized(unSer1)
88 td = ser1.getTypeDescriptor()
89 self.assert_(td == 'ndarray')
90 md = ser1.getMetadata()
91 self.assert_(md['shape'] == a.shape)
92 self.assert_(md['dtype'] == a.dtype.str)
93 buff = ser1.getData()
94 self.assert_(buff == numpy.getbuffer(a))
95 s = Serialized(buff, td, md)
96 us = IUnSerialized(s)
97 final = us.getObject()
98 self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final))
99 self.assert_(a.dtype.str == final.dtype.str)
100 self.assert_(a.shape == final.shape)
101
77 102
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)
100
101
102 No newline at end of file
@@ -25,162 +25,162 b' try:'
25 25 from IPython.kernel import error
26 26 from IPython.kernel.util import printer
27 27 except ImportError:
28 pass
29 else:
28 import nose
29 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
30 30
31 class Foo(object):
32
33 def bar(self, bahz):
34 return defer.succeed('blahblah: %s' % bahz)
31 class Foo(object):
35 32
36 class TwoPhaseFoo(pd.PendingDeferredManager):
37
38 def __init__(self, foo):
39 self.foo = foo
40 pd.PendingDeferredManager.__init__(self)
33 def bar(self, bahz):
34 return defer.succeed('blahblah: %s' % bahz)
41 35
42 @pd.two_phase
43 def bar(self, bahz):
44 return self.foo.bar(bahz)
36 class TwoPhaseFoo(pd.PendingDeferredManager):
45 37
46 class PendingDeferredManagerTest(DeferredTestCase):
47
48 def setUp(self):
49 self.pdm = pd.PendingDeferredManager()
50
51 def tearDown(self):
52 pass
53
54 def testBasic(self):
55 dDict = {}
56 # Create 10 deferreds and save them
57 for i in range(10):
58 d = defer.Deferred()
59 did = self.pdm.save_pending_deferred(d)
60 dDict[did] = d
61 # Make sure they are begin saved
62 for k in dDict.keys():
63 self.assert_(self.pdm.quick_has_id(k))
64 # Get the pending deferred (block=True), then callback with 'foo' and compare
65 for did in dDict.keys()[0:5]:
66 d = self.pdm.get_pending_deferred(did,block=True)
67 dDict[did].callback('foo')
68 d.addCallback(lambda r: self.assert_(r=='foo'))
69 # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised
70 for did in dDict.keys()[5:10]:
71 d = self.pdm.get_pending_deferred(did,block=False)
72 d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
73 # Now callback the last 5, get them and compare.
74 for did in dDict.keys()[5:10]:
75 dDict[did].callback('foo')
76 d = self.pdm.get_pending_deferred(did,block=False)
77 d.addCallback(lambda r: self.assert_(r=='foo'))
78
79 def test_save_then_delete(self):
80 d = defer.Deferred()
81 did = self.pdm.save_pending_deferred(d)
82 self.assert_(self.pdm.quick_has_id(did))
83 self.pdm.delete_pending_deferred(did)
84 self.assert_(not self.pdm.quick_has_id(did))
85
86 def test_save_get_delete(self):
87 d = defer.Deferred()
88 did = self.pdm.save_pending_deferred(d)
89 d2 = self.pdm.get_pending_deferred(did,True)
90 d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException))
91 self.pdm.delete_pending_deferred(did)
92 return d2
93
94 def test_double_get(self):
95 d = defer.Deferred()
96 did = self.pdm.save_pending_deferred(d)
97 d2 = self.pdm.get_pending_deferred(did,True)
98 d3 = self.pdm.get_pending_deferred(did,True)
99 d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException))
100
101 def test_get_after_callback(self):
102 d = defer.Deferred()
103 did = self.pdm.save_pending_deferred(d)
104 d.callback('foo')
105 d2 = self.pdm.get_pending_deferred(did,True)
106 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
107 self.assert_(not self.pdm.quick_has_id(did))
38 def __init__(self, foo):
39 self.foo = foo
40 pd.PendingDeferredManager.__init__(self)
108 41
109 def test_get_before_callback(self):
110 d = defer.Deferred()
111 did = self.pdm.save_pending_deferred(d)
112 d2 = self.pdm.get_pending_deferred(did,True)
113 d.callback('foo')
114 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
115 self.assert_(not self.pdm.quick_has_id(did))
116 d = defer.Deferred()
117 did = self.pdm.save_pending_deferred(d)
118 d2 = self.pdm.get_pending_deferred(did,True)
119 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
120 d.callback('foo')
121 self.assert_(not self.pdm.quick_has_id(did))
122
123 def test_get_after_errback(self):
124 class MyError(Exception):
125 pass
126 d = defer.Deferred()
127 did = self.pdm.save_pending_deferred(d)
128 d.errback(failure.Failure(MyError('foo')))
129 d2 = self.pdm.get_pending_deferred(did,True)
130 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
131 self.assert_(not self.pdm.quick_has_id(did))
132
133 def test_get_before_errback(self):
134 class MyError(Exception):
135 pass
136 d = defer.Deferred()
137 did = self.pdm.save_pending_deferred(d)
138 d2 = self.pdm.get_pending_deferred(did,True)
139 d.errback(failure.Failure(MyError('foo')))
140 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
141 self.assert_(not self.pdm.quick_has_id(did))
142 d = defer.Deferred()
143 did = self.pdm.save_pending_deferred(d)
144 d2 = self.pdm.get_pending_deferred(did,True)
145 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
146 d.errback(failure.Failure(MyError('foo')))
147 self.assert_(not self.pdm.quick_has_id(did))
148
149 def test_noresult_noblock(self):
150 d = defer.Deferred()
151 did = self.pdm.save_pending_deferred(d)
152 d2 = self.pdm.get_pending_deferred(did,False)
153 d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
42 @pd.two_phase
43 def bar(self, bahz):
44 return self.foo.bar(bahz)
154 45
155 def test_with_callbacks(self):
156 d = defer.Deferred()
157 d.addCallback(lambda r: r+' foo')
158 d.addCallback(lambda r: r+' bar')
159 did = self.pdm.save_pending_deferred(d)
160 d2 = self.pdm.get_pending_deferred(did,True)
161 d.callback('bam')
162 d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar'))
46 class PendingDeferredManagerTest(DeferredTestCase):
47
48 def setUp(self):
49 self.pdm = pd.PendingDeferredManager()
163 50
164 def test_with_errbacks(self):
165 class MyError(Exception):
166 pass
51 def tearDown(self):
52 pass
53
54 def testBasic(self):
55 dDict = {}
56 # Create 10 deferreds and save them
57 for i in range(10):
167 58 d = defer.Deferred()
168 d.addCallback(lambda r: 'foo')
169 d.addErrback(lambda f: 'caught error')
170 59 did = self.pdm.save_pending_deferred(d)
171 d2 = self.pdm.get_pending_deferred(did,True)
172 d.errback(failure.Failure(MyError('bam')))
173 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
60 dDict[did] = d
61 # Make sure they are begin saved
62 for k in dDict.keys():
63 self.assert_(self.pdm.quick_has_id(k))
64 # Get the pending deferred (block=True), then callback with 'foo' and compare
65 for did in dDict.keys()[0:5]:
66 d = self.pdm.get_pending_deferred(did,block=True)
67 dDict[did].callback('foo')
68 d.addCallback(lambda r: self.assert_(r=='foo'))
69 # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised
70 for did in dDict.keys()[5:10]:
71 d = self.pdm.get_pending_deferred(did,block=False)
72 d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
73 # Now callback the last 5, get them and compare.
74 for did in dDict.keys()[5:10]:
75 dDict[did].callback('foo')
76 d = self.pdm.get_pending_deferred(did,block=False)
77 d.addCallback(lambda r: self.assert_(r=='foo'))
78
79 def test_save_then_delete(self):
80 d = defer.Deferred()
81 did = self.pdm.save_pending_deferred(d)
82 self.assert_(self.pdm.quick_has_id(did))
83 self.pdm.delete_pending_deferred(did)
84 self.assert_(not self.pdm.quick_has_id(did))
85
86 def test_save_get_delete(self):
87 d = defer.Deferred()
88 did = self.pdm.save_pending_deferred(d)
89 d2 = self.pdm.get_pending_deferred(did,True)
90 d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException))
91 self.pdm.delete_pending_deferred(did)
92 return d2
93
94 def test_double_get(self):
95 d = defer.Deferred()
96 did = self.pdm.save_pending_deferred(d)
97 d2 = self.pdm.get_pending_deferred(did,True)
98 d3 = self.pdm.get_pending_deferred(did,True)
99 d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException))
100
101 def test_get_after_callback(self):
102 d = defer.Deferred()
103 did = self.pdm.save_pending_deferred(d)
104 d.callback('foo')
105 d2 = self.pdm.get_pending_deferred(did,True)
106 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
107 self.assert_(not self.pdm.quick_has_id(did))
108
109 def test_get_before_callback(self):
110 d = defer.Deferred()
111 did = self.pdm.save_pending_deferred(d)
112 d2 = self.pdm.get_pending_deferred(did,True)
113 d.callback('foo')
114 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
115 self.assert_(not self.pdm.quick_has_id(did))
116 d = defer.Deferred()
117 did = self.pdm.save_pending_deferred(d)
118 d2 = self.pdm.get_pending_deferred(did,True)
119 d2.addCallback(lambda r: self.assertEquals(r,'foo'))
120 d.callback('foo')
121 self.assert_(not self.pdm.quick_has_id(did))
122
123 def test_get_after_errback(self):
124 class MyError(Exception):
125 pass
126 d = defer.Deferred()
127 did = self.pdm.save_pending_deferred(d)
128 d.errback(failure.Failure(MyError('foo')))
129 d2 = self.pdm.get_pending_deferred(did,True)
130 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
131 self.assert_(not self.pdm.quick_has_id(did))
132
133 def test_get_before_errback(self):
134 class MyError(Exception):
135 pass
136 d = defer.Deferred()
137 did = self.pdm.save_pending_deferred(d)
138 d2 = self.pdm.get_pending_deferred(did,True)
139 d.errback(failure.Failure(MyError('foo')))
140 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
141 self.assert_(not self.pdm.quick_has_id(did))
142 d = defer.Deferred()
143 did = self.pdm.save_pending_deferred(d)
144 d2 = self.pdm.get_pending_deferred(did,True)
145 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
146 d.errback(failure.Failure(MyError('foo')))
147 self.assert_(not self.pdm.quick_has_id(did))
174 148
175 def test_nested_deferreds(self):
176 d = defer.Deferred()
177 d2 = defer.Deferred()
178 d.addCallback(lambda r: d2)
179 did = self.pdm.save_pending_deferred(d)
180 d.callback('foo')
181 d3 = self.pdm.get_pending_deferred(did,False)
182 d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
183 d2.callback('bar')
184 d3 = self.pdm.get_pending_deferred(did,False)
185 d3.addCallback(lambda r: self.assertEquals(r,'bar'))
149 def test_noresult_noblock(self):
150 d = defer.Deferred()
151 did = self.pdm.save_pending_deferred(d)
152 d2 = self.pdm.get_pending_deferred(did,False)
153 d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
154
155 def test_with_callbacks(self):
156 d = defer.Deferred()
157 d.addCallback(lambda r: r+' foo')
158 d.addCallback(lambda r: r+' bar')
159 did = self.pdm.save_pending_deferred(d)
160 d2 = self.pdm.get_pending_deferred(did,True)
161 d.callback('bam')
162 d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar'))
163
164 def test_with_errbacks(self):
165 class MyError(Exception):
166 pass
167 d = defer.Deferred()
168 d.addCallback(lambda r: 'foo')
169 d.addErrback(lambda f: 'caught error')
170 did = self.pdm.save_pending_deferred(d)
171 d2 = self.pdm.get_pending_deferred(did,True)
172 d.errback(failure.Failure(MyError('bam')))
173 d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException))
174
175 def test_nested_deferreds(self):
176 d = defer.Deferred()
177 d2 = defer.Deferred()
178 d.addCallback(lambda r: d2)
179 did = self.pdm.save_pending_deferred(d)
180 d.callback('foo')
181 d3 = self.pdm.get_pending_deferred(did,False)
182 d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException))
183 d2.callback('bar')
184 d3 = self.pdm.get_pending_deferred(did,False)
185 d3.addCallback(lambda r: self.assertEquals(r,'bar'))
186 186
@@ -26,25 +26,26 b' try:'
26 26 from IPython.testing.util import DeferredTestCase
27 27 from IPython.kernel.tests.tasktest import ITaskControllerTestCase
28 28 except ImportError:
29 pass
30 else:
31 #-------------------------------------------------------------------------------
32 # Tests
33 #-------------------------------------------------------------------------------
29 import nose
30 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
34 31
35 class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase):
32 #-------------------------------------------------------------------------------
33 # Tests
34 #-------------------------------------------------------------------------------
35
36 class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase):
37
38 def setUp(self):
39 self.controller = cs.ControllerService()
40 self.controller.startService()
41 self.multiengine = IMultiEngine(self.controller)
42 self.tc = task.ITaskController(self.controller)
43 self.tc.failurePenalty = 0
44 self.engines=[]
36 45
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=[]
44
45 def tearDown(self):
46 self.controller.stopService()
47 for e in self.engines:
48 e.stopService()
46 def tearDown(self):
47 self.controller.stopService()
48 for e in self.engines:
49 e.stopService()
49 50
50 51
@@ -33,129 +33,130 b' try:'
33 33 from IPython.kernel.error import CompositeError
34 34 from IPython.kernel.parallelfunction import ParallelFunction
35 35 except ImportError:
36 pass
37 else:
36 import nose
37 raise nose.SkipTest("This test requires zope.interface, Twisted and Foolscap")
38 38
39 #-------------------------------------------------------------------------------
40 # Tests
41 #-------------------------------------------------------------------------------
42 39
43 def _raise_it(f):
44 try:
45 f.raiseException()
46 except CompositeError, e:
47 e.raise_exception()
40 #-------------------------------------------------------------------------------
41 # Tests
42 #-------------------------------------------------------------------------------
48 43
49 class TaskTest(DeferredTestCase, ITaskControllerTestCase):
44 def _raise_it(f):
45 try:
46 f.raiseException()
47 except CompositeError, e:
48 e.raise_exception()
50 49
51 def setUp(self):
52
53 self.engines = []
54
55 self.controller = cs.ControllerService()
56 self.controller.startService()
57 self.imultiengine = me.IMultiEngine(self.controller)
58 self.itc = taskmodule.ITaskController(self.controller)
59 self.itc.failurePenalty = 0
60
61 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
62 self.tc_referenceable = IFCTaskController(self.itc)
63
64 self.controller_tub = Tub()
65 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
66 self.controller_tub.setLocation('127.0.0.1:10105')
67
68 mec_furl = self.controller_tub.registerReference(self.mec_referenceable)
69 tc_furl = self.controller_tub.registerReference(self.tc_referenceable)
70 self.controller_tub.startService()
71
72 self.client_tub = ClientConnector()
73 d = self.client_tub.get_multiengine_client(mec_furl)
74 d.addCallback(self.handle_mec_client)
75 d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl))
76 d.addCallback(self.handle_tc_client)
77 return d
78
79 def handle_mec_client(self, client):
80 self.multiengine = client
50 class TaskTest(DeferredTestCase, ITaskControllerTestCase):
51
52 def setUp(self):
53
54 self.engines = []
55
56 self.controller = cs.ControllerService()
57 self.controller.startService()
58 self.imultiengine = me.IMultiEngine(self.controller)
59 self.itc = taskmodule.ITaskController(self.controller)
60 self.itc.failurePenalty = 0
61
62 self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
63 self.tc_referenceable = IFCTaskController(self.itc)
64
65 self.controller_tub = Tub()
66 self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
67 self.controller_tub.setLocation('127.0.0.1:10105')
68
69 mec_furl = self.controller_tub.registerReference(self.mec_referenceable)
70 tc_furl = self.controller_tub.registerReference(self.tc_referenceable)
71 self.controller_tub.startService()
72
73 self.client_tub = ClientConnector()
74 d = self.client_tub.get_multiengine_client(mec_furl)
75 d.addCallback(self.handle_mec_client)
76 d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl))
77 d.addCallback(self.handle_tc_client)
78 return d
79
80 def handle_mec_client(self, client):
81 self.multiengine = client
82
83 def handle_tc_client(self, client):
84 self.tc = client
85
86 def tearDown(self):
87 dlist = []
88 # Shut down the multiengine client
89 d = self.client_tub.tub.stopService()
90 dlist.append(d)
91 # Shut down the engines
92 for e in self.engines:
93 e.stopService()
94 # Shut down the controller
95 d = self.controller_tub.stopService()
96 d.addBoth(lambda _: self.controller.stopService())
97 dlist.append(d)
98 return defer.DeferredList(dlist)
99
100 def test_mapper(self):
101 self.addEngine(1)
102 m = self.tc.mapper()
103 self.assertEquals(m.task_controller,self.tc)
104 self.assertEquals(m.clear_before,False)
105 self.assertEquals(m.clear_after,False)
106 self.assertEquals(m.retries,0)
107 self.assertEquals(m.recovery_task,None)
108 self.assertEquals(m.depend,None)
109 self.assertEquals(m.block,True)
110
111 def test_map_default(self):
112 self.addEngine(1)
113 m = self.tc.mapper()
114 d = m.map(lambda x: 2*x, range(10))
115 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
116 d.addCallback(lambda _: self.tc.map(lambda x: 2*x, range(10)))
117 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
118 return d
119
120 def test_map_noblock(self):
121 self.addEngine(1)
122 m = self.tc.mapper(block=False)
123 d = m.map(lambda x: 2*x, range(10))
124 d.addCallback(lambda r: self.assertEquals(r,[x for x in range(10)]))
125 return d
126
127 def test_mapper_fail(self):
128 self.addEngine(1)
129 m = self.tc.mapper()
130 d = m.map(lambda x: 1/0, range(10))
131 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
132 return d
133
134 def test_parallel(self):
135 self.addEngine(1)
136 p = self.tc.parallel()
137 self.assert_(isinstance(p, ParallelFunction))
138 @p
139 def f(x): return 2*x
140 d = f(range(10))
141 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
142 return d
81 143
82 def handle_tc_client(self, client):
83 self.tc = client
144 def test_parallel_noblock(self):
145 self.addEngine(1)
146 p = self.tc.parallel(block=False)
147 self.assert_(isinstance(p, ParallelFunction))
148 @p
149 def f(x): return 2*x
150 d = f(range(10))
151 d.addCallback(lambda r: self.assertEquals(r,[x for x in range(10)]))
152 return d
84 153
85 def tearDown(self):
86 dlist = []
87 # Shut down the multiengine client
88 d = self.client_tub.tub.stopService()
89 dlist.append(d)
90 # Shut down the engines
91 for e in self.engines:
92 e.stopService()
93 # Shut down the controller
94 d = self.controller_tub.stopService()
95 d.addBoth(lambda _: self.controller.stopService())
96 dlist.append(d)
97 return defer.DeferredList(dlist)
98
99 def test_mapper(self):
100 self.addEngine(1)
101 m = self.tc.mapper()
102 self.assertEquals(m.task_controller,self.tc)
103 self.assertEquals(m.clear_before,False)
104 self.assertEquals(m.clear_after,False)
105 self.assertEquals(m.retries,0)
106 self.assertEquals(m.recovery_task,None)
107 self.assertEquals(m.depend,None)
108 self.assertEquals(m.block,True)
109
110 def test_map_default(self):
111 self.addEngine(1)
112 m = self.tc.mapper()
113 d = m.map(lambda x: 2*x, range(10))
114 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
115 d.addCallback(lambda _: self.tc.map(lambda x: 2*x, range(10)))
116 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
117 return d
118
119 def test_map_noblock(self):
120 self.addEngine(1)
121 m = self.tc.mapper(block=False)
122 d = m.map(lambda x: 2*x, range(10))
123 d.addCallback(lambda r: self.assertEquals(r,[x for x in range(10)]))
124 return d
125
126 def test_mapper_fail(self):
127 self.addEngine(1)
128 m = self.tc.mapper()
129 d = m.map(lambda x: 1/0, range(10))
130 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
131 return d
132
133 def test_parallel(self):
134 self.addEngine(1)
135 p = self.tc.parallel()
136 self.assert_(isinstance(p, ParallelFunction))
137 @p
138 def f(x): return 2*x
139 d = f(range(10))
140 d.addCallback(lambda r: self.assertEquals(r,[2*x for x in range(10)]))
141 return d
142
143 def test_parallel_noblock(self):
144 self.addEngine(1)
145 p = self.tc.parallel(block=False)
146 self.assert_(isinstance(p, ParallelFunction))
147 @p
148 def f(x): return 2*x
149 d = f(range(10))
150 d.addCallback(lambda r: self.assertEquals(r,[x for x in range(10)]))
151 return d
152
153 def test_parallel_fail(self):
154 self.addEngine(1)
155 p = self.tc.parallel()
156 self.assert_(isinstance(p, ParallelFunction))
157 @p
158 def f(x): return 1/0
159 d = f(range(10))
160 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
161 return d No newline at end of file
154 def test_parallel_fail(self):
155 self.addEngine(1)
156 p = self.tc.parallel()
157 self.assert_(isinstance(p, ParallelFunction))
158 @p
159 def f(x): return 1/0
160 d = f(range(10))
161 d.addBoth(lambda f: self.assertRaises(ZeroDivisionError, _raise_it, f))
162 return d No newline at end of file
1 NO CONTENT: modified file chmod 100755 => 100644
@@ -93,28 +93,28 b' Specific subpackages'
93 93 --------------------
94 94
95 95 ``core``
96 This is the core functionality of IPython that is independent of the
97 terminal, network and GUIs. Most of the code that is in the current
98 IPython trunk will be refactored, cleaned up and moved here.
96 This is the core functionality of IPython that is independent of the
97 terminal, network and GUIs. Most of the code that is in the current
98 IPython trunk will be refactored, cleaned up and moved here.
99 99
100 100 ``kernel``
101 The enables the IPython core to be expose to a the network. This is
102 also where all of the parallel computing capabilities are to be found.
103
101 The enables the IPython core to be expose to a the network. This is
102 also where all of the parallel computing capabilities are to be found.
103
104 104 ``config``
105 The configuration package used by IPython.
105 The configuration package used by IPython.
106 106
107 107 ``frontends``
108 The various frontends for IPython. A frontend is the end-user application
109 that exposes the capabilities of IPython to the user. The most basic frontend
110 will simply be a terminal based application that looks just like today 's
111 IPython. Other frontends will likely be more powerful and based on GUI toolkits.
108 The various frontends for IPython. A frontend is the end-user application
109 that exposes the capabilities of IPython to the user. The most basic frontend
110 will simply be a terminal based application that looks just like today 's
111 IPython. Other frontends will likely be more powerful and based on GUI toolkits.
112 112
113 113 ``notebook``
114 An application that allows users to work with IPython notebooks.
114 An application that allows users to work with IPython notebooks.
115 115
116 116 ``tools``
117 This is where general utilities go.
117 This is where general utilities go.
118 118
119 119
120 120 Version control
@@ -125,17 +125,17 b' to contribute code to IPython. Here is a sketch of how to use Bazaar for IPytho'
125 125 development. First, you should install Bazaar. After you have done that, make
126 126 sure that it is working by getting the latest main branch of IPython::
127 127
128 $ bzr branch lp:ipython
128 $ bzr branch lp:ipython
129 129
130 130 Now you can create a new branch for you to do your work in::
131 131
132 $ bzr branch ipython ipython-mybranch
132 $ bzr branch ipython ipython-mybranch
133 133
134 134 The typical work cycle in this branch will be to make changes in `ipython-mybranch`
135 135 and then commit those changes using the commit command::
136 136
137 $ ...do work in ipython-mybranch...
138 $ bzr ci -m "the commit message goes here"
137 $ ...do work in ipython-mybranch...
138 $ bzr ci -m "the commit message goes here"
139 139
140 140 Please note that since we now don't use an old-style linear ChangeLog
141 141 (that tends to cause problems with distributed version control
@@ -156,26 +156,26 b' the project, and the `--short` log option becomes a nice summary.'
156 156 While working with this branch, it is a good idea to merge in changes that have been
157 157 made upstream in the parent branch. This can be done by doing::
158 158
159 $ bzr pull
160
159 $ bzr pull
160
161 161 If this command shows that the branches have diverged, then you should do a merge
162 162 instead::
163 163
164 $ bzr merge lp:ipython
164 $ bzr merge lp:ipython
165 165
166 166 If you want others to be able to see your branch, you can create an account with
167 167 launchpad and push the branch to your own workspace::
168 168
169 $ bzr push bzr+ssh://<me>@bazaar.launchpad.net/~<me>/+junk/ipython-mybranch
169 $ bzr push bzr+ssh://<me>@bazaar.launchpad.net/~<me>/+junk/ipython-mybranch
170 170
171 171 Finally, once the work in your branch is done, you can merge your changes back into
172 172 the `ipython` branch by using merge::
173 173
174 $ cd ipython
175 $ merge ../ipython-mybranch
176 [resolve any conflicts]
177 $ bzr ci -m "Fixing that bug"
178 $ bzr push
174 $ cd ipython
175 $ merge ../ipython-mybranch
176 [resolve any conflicts]
177 $ bzr ci -m "Fixing that bug"
178 $ bzr push
179 179
180 180 But this will require you to have write permissions to the `ipython` branch. It you don't
181 181 you can tell one of the IPython devs about your branch and they can do the merge for you.
@@ -349,6 +349,47 b' IPython. The current prototype of ``tconfig`` is located in the IPython sandbox.'
349 349 .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html
350 350 .. _Traits: http://code.enthought.com/traits/
351 351
352 Installation and testing scenarios
353 ==================================
354
355 This section outlines the various scenarios that we need to test before we release an IPython version. These scenarios represent different ways of installing IPython and its dependencies.
356
357 Installation scenarios
358 ----------------------
359
360 1. Install from tarball using `python setup.py install`.
361 a. With only readline+nose dependencies installed (test1)
362
363 virtualenv --no-site-packages test1
364 # Activate it
365 easy_install nose
366 easy_install readline # On OS X or pyreadline on win32
367 cd ipython-0.9.beta3
368 python setup.py install
369
370 b. With all dependencies installed (readline, zope.interface,
371 Twisted, foolscap, Sphinx, nose, pyOpenSSL) (test2)
372 2. Install using easy_install.
373 a. With only readline+nose dependencies installed (test3)
374 i. Default dependencies.
375 ii. Optional dependency sets (kernel, doc, test, security)
376 easy_install -f ipython-0.9.beta3-py2.5.egg IPython[kernel,doc,test,security]
377
378 b. With all dependencies already installed (test2)
379
380
381 Tests to run for these scenarios
382 --------------------------------
383
384 1. Run the full test suite.
385 2. Start a controller and engines and try a few things by hand.
386 a. Using ipcluster.
387 b. Using ipcontroller/ipengine by hand.
388 3. Run a few of the parallel examples.
389 4. Try the kernel with and without security with and without PyOpenSSL
390 installed.
391 5. Beat on the IPython terminal a bunch.
392 6. Make sure that furl files are being put in proper locations.
352 393
353 394
354 395
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now