##// END OF EJS Templates
cocoa frontend tests
Barry Wark -
Show More
@@ -24,23 +24,19 b' __docformat__ = "restructuredtext en"'
24 # Imports
24 # Imports
25 #-------------------------------------------------------------------------------
25 #-------------------------------------------------------------------------------
26 from IPython.kernel.core.interpreter import Interpreter
26 from IPython.kernel.core.interpreter import Interpreter
27 from IPython.testutils.parametric import Parametric, parametric
28 from IPython.kernel.core.interpreter import COMPILER_ERROR, INCOMPLETE_INPUT,\
29 COMPLETE_INPUT
30 import IPython.kernel.engineservice as es
27 import IPython.kernel.engineservice as es
31 from IPython.testutils.util import DeferredTestCase
28 from IPython.testing.util import DeferredTestCase
32 from twisted.internet.defer import succeed
29 from twisted.internet.defer import succeed
33 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController,\
30 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController
34 IPythonCLITextViewDelegate,\
35 CompilerError
36
31
32 from Foundation import NSMakeRect
33 from AppKit import NSTextView, NSScrollView
37
34
38 class TestIPythonCocoaControler(DeferredTestCase):
35 class TestIPythonCocoaControler(DeferredTestCase):
39 """Tests for IPythonCocoaController"""
36 """Tests for IPythonCocoaController"""
40
37
41 def setUp(self):
38 def setUp(self):
42 self.controller = IPythonCocoaController.alloc().init()
39 self.controller = IPythonCocoaController.alloc().init()
43 self.controller.awakeFromNib()
44 self.engine = es.EngineService()
40 self.engine = es.EngineService()
45 self.engine.startService()
41 self.engine.startService()
46
42
@@ -57,31 +53,19 b' class TestIPythonCocoaControler(DeferredTestCase):'
57 del result['number']
53 del result['number']
58 del result['id']
54 del result['id']
59 return result
55 return result
60 self.assertDeferredEquals(self.controller.executeRequest([code]).addCallback(removeNumberAndID), expected)
56 self.assertDeferredEquals(self.controller.execute(code).addCallback(removeNumberAndID), expected)
61
62 def testControllerReturnsNoneForIncompleteCode(self):
63 code = """def test(a):"""
64 expected = None
65 self.assertDeferredEquals(self.controller.executeRequest([code]), expected)
66
67
68 def testControllerRaisesCompilerErrorForIllegalCode(self):
69 """testControllerRaisesCompilerErrorForIllegalCode"""
70
71 code = """def test() pass"""
72 self.assertDeferredRaises(self.controller.executeRequest([code]), CompilerError)
73
57
74 def testControllerMirrorsUserNSWithValuesAsStrings(self):
58 def testControllerMirrorsUserNSWithValuesAsStrings(self):
75 code = """userns1=1;userns2=2"""
59 code = """userns1=1;userns2=2"""
76 def testControllerUserNS(result):
60 def testControllerUserNS(result):
77 self.assertEquals(self.controller.userNS['userns1'], str(1))
61 self.assertEquals(self.controller.userNS['userns1'], 1)
78 self.assertEquals(self.controller.userNS['userns2'], str(2))
62 self.assertEquals(self.controller.userNS['userns2'], 2)
79
63
80 self.controller.executeRequest([code]).addCallback(testControllerUserNS)
64 self.controller.execute(code).addCallback(testControllerUserNS)
81
65
82
66
83 def testControllerInstantiatesIEngine(self):
67 def testControllerInstantiatesIEngine(self):
84 self.assert_(es.IEngine.providedBy(self.controller.engine))
68 self.assert_(es.IEngineBase.providedBy(self.controller.engine))
85
69
86 def testControllerCompletesToken(self):
70 def testControllerCompletesToken(self):
87 code = """longNameVariable=10"""
71 code = """longNameVariable=10"""
@@ -91,7 +75,5 b' class TestIPythonCocoaControler(DeferredTestCase):'
91 def testCompleteToken(result):
75 def testCompleteToken(result):
92 self.controller.complete("longNa").addCallback(testCompletes)
76 self.controller.complete("longNa").addCallback(testCompletes)
93
77
94 self.controller.executeRequest([code]).addCallback(testCompletes)
78 self.controller.execute(code).addCallback(testCompletes)
95
79
96
97 Parametric(TestIPythonCocoaControler) No newline at end of file
@@ -847,6 +847,13 b' class Command(object):'
847 self.deferred.errback(reason)
847 self.deferred.errback(reason)
848
848
849 class ThreadedEngineService(EngineService):
849 class ThreadedEngineService(EngineService):
850 """An EngineService subclass that defers execute commands to a separate thread.
851
852 ThreadedEngineService uses twisted.internet.threads.deferToThread to defer execute
853 requests to a separate thread. GUI frontends may want to use ThreadedEngineService as
854 the engine in an IPython.frontend.frontendbase.FrontEndBase subclass to prevent
855 block execution from blocking the GUI thread.
856 """
850
857
851 zi.implements(IEngineBase)
858 zi.implements(IEngineBase)
852
859
General Comments 0
You need to be logged in to leave comments. Login now