##// END OF EJS Templates
fixed ipython1->IPython in cocoa/tests/test_cocoa_frontend.py
Barry Wark -
Show More
@@ -1,97 +1,97 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """This file contains unittests for the ipython1.frontend.cocoa.cocoa_frontend module.
2 """This file contains unittests for the ipython1.frontend.cocoa.cocoa_frontend module.
3
3
4 Things that should be tested:
4 Things that should be tested:
5
5
6 - IPythonCocoaController instantiates an IEngineInteractive
6 - IPythonCocoaController instantiates an IEngineInteractive
7 - IPythonCocoaController executes code on the engine
7 - IPythonCocoaController executes code on the engine
8 - IPythonCocoaController returns continuation for incomplete code
8 - IPythonCocoaController returns continuation for incomplete code
9 - IPythonCocoaController returns failure for exceptions raised in executed code
9 - IPythonCocoaController returns failure for exceptions raised in executed code
10 - IPythonCocoaController mirrors engine's user_ns
10 - IPythonCocoaController mirrors engine's user_ns
11 """
11 """
12 __docformat__ = "restructuredtext en"
12 __docformat__ = "restructuredtext en"
13
13
14 #-------------------------------------------------------------------------------
14 #-------------------------------------------------------------------------------
15 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
15 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
16 # Brian E Granger <ellisonbg@gmail.com>
16 # Brian E Granger <ellisonbg@gmail.com>
17 # Benjamin Ragan-Kelley <benjaminrk@gmail.com>
17 # Benjamin Ragan-Kelley <benjaminrk@gmail.com>
18 #
18 #
19 # Distributed under the terms of the BSD License. The full license is in
19 # Distributed under the terms of the BSD License. The full license is in
20 # the file COPYING, distributed as part of this software.
20 # the file COPYING, distributed as part of this software.
21 #-------------------------------------------------------------------------------
21 #-------------------------------------------------------------------------------
22
22
23 #-------------------------------------------------------------------------------
23 #-------------------------------------------------------------------------------
24 # Imports
24 # Imports
25 #-------------------------------------------------------------------------------
25 #-------------------------------------------------------------------------------
26 from ipython1.core.interpreter import Interpreter
26 from IPython.kernel.core.interpreter import Interpreter
27 from ipython1.testutils.parametric import Parametric, parametric
27 from IPython.testutils.parametric import Parametric, parametric
28 from ipython1.core.interpreter import COMPILER_ERROR, INCOMPLETE_INPUT,\
28 from IPython.kernel.core.interpreter import COMPILER_ERROR, INCOMPLETE_INPUT,\
29 COMPLETE_INPUT
29 COMPLETE_INPUT
30 import ipython1.kernel.engineservice as es
30 import IPython.kernel.engineservice as es
31 from ipython1.testutils.util import DeferredTestCase
31 from IPython.testutils.util import DeferredTestCase
32 from twisted.internet.defer import succeed
32 from twisted.internet.defer import succeed
33 from ipython1.frontend.cocoa.cocoa_frontend import IPythonCocoaController,\
33 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController,\
34 IPythonCLITextViewDelegate,\
34 IPythonCLITextViewDelegate,\
35 CompilerError
35 CompilerError
36
36
37
37
38 class TestIPythonCocoaControler(DeferredTestCase):
38 class TestIPythonCocoaControler(DeferredTestCase):
39 """Tests for IPythonCocoaController"""
39 """Tests for IPythonCocoaController"""
40
40
41 def setUp(self):
41 def setUp(self):
42 self.controller = IPythonCocoaController.alloc().init()
42 self.controller = IPythonCocoaController.alloc().init()
43 self.controller.awakeFromNib()
43 self.controller.awakeFromNib()
44 self.engine = es.EngineService()
44 self.engine = es.EngineService()
45 self.engine.startService()
45 self.engine.startService()
46
46
47
47
48 def tearDown(self):
48 def tearDown(self):
49 self.controller = None
49 self.controller = None
50 self.engine.stopService()
50 self.engine.stopService()
51
51
52 def testControllerExecutesCode(self):
52 def testControllerExecutesCode(self):
53 code ="""5+5"""
53 code ="""5+5"""
54 expected = Interpreter().execute(code)
54 expected = Interpreter().execute(code)
55 del expected['number']
55 del expected['number']
56 def removeNumberAndID(result):
56 def removeNumberAndID(result):
57 del result['number']
57 del result['number']
58 del result['id']
58 del result['id']
59 return result
59 return result
60 self.assertDeferredEquals(self.controller.executeRequest([code]).addCallback(removeNumberAndID), expected)
60 self.assertDeferredEquals(self.controller.executeRequest([code]).addCallback(removeNumberAndID), expected)
61
61
62 def testControllerReturnsNoneForIncompleteCode(self):
62 def testControllerReturnsNoneForIncompleteCode(self):
63 code = """def test(a):"""
63 code = """def test(a):"""
64 expected = None
64 expected = None
65 self.assertDeferredEquals(self.controller.executeRequest([code]), expected)
65 self.assertDeferredEquals(self.controller.executeRequest([code]), expected)
66
66
67
67
68 def testControllerRaisesCompilerErrorForIllegalCode(self):
68 def testControllerRaisesCompilerErrorForIllegalCode(self):
69 """testControllerRaisesCompilerErrorForIllegalCode"""
69 """testControllerRaisesCompilerErrorForIllegalCode"""
70
70
71 code = """def test() pass"""
71 code = """def test() pass"""
72 self.assertDeferredRaises(self.controller.executeRequest([code]), CompilerError)
72 self.assertDeferredRaises(self.controller.executeRequest([code]), CompilerError)
73
73
74 def testControllerMirrorsUserNSWithValuesAsStrings(self):
74 def testControllerMirrorsUserNSWithValuesAsStrings(self):
75 code = """userns1=1;userns2=2"""
75 code = """userns1=1;userns2=2"""
76 def testControllerUserNS(result):
76 def testControllerUserNS(result):
77 self.assertEquals(self.controller.userNS['userns1'], str(1))
77 self.assertEquals(self.controller.userNS['userns1'], str(1))
78 self.assertEquals(self.controller.userNS['userns2'], str(2))
78 self.assertEquals(self.controller.userNS['userns2'], str(2))
79
79
80 self.controller.executeRequest([code]).addCallback(testControllerUserNS)
80 self.controller.executeRequest([code]).addCallback(testControllerUserNS)
81
81
82
82
83 def testControllerInstantiatesIEngine(self):
83 def testControllerInstantiatesIEngine(self):
84 self.assert_(es.IEngine.providedBy(self.controller.engine))
84 self.assert_(es.IEngine.providedBy(self.controller.engine))
85
85
86 def testControllerCompletesToken(self):
86 def testControllerCompletesToken(self):
87 code = """longNameVariable=10"""
87 code = """longNameVariable=10"""
88 def testCompletes(result):
88 def testCompletes(result):
89 self.assert_("longNameVariable" in result)
89 self.assert_("longNameVariable" in result)
90
90
91 def testCompleteToken(result):
91 def testCompleteToken(result):
92 self.controller.complete("longNa").addCallback(testCompletes)
92 self.controller.complete("longNa").addCallback(testCompletes)
93
93
94 self.controller.executeRequest([code]).addCallback(testCompletes)
94 self.controller.executeRequest([code]).addCallback(testCompletes)
95
95
96
96
97 Parametric(TestIPythonCocoaControler) No newline at end of file
97 Parametric(TestIPythonCocoaControler)
General Comments 0
You need to be logged in to leave comments. Login now