##// END OF EJS Templates
oops
Barry Wark -
Show More
@@ -1,79 +1,77 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
9 - IPythonCocoaController returns failure for exceptions raised in executed code
10 - IPythonCocoaController mirrors engine's user_ns
8 - IPythonCocoaController mirrors engine's user_ns
11 """
9 """
12 __docformat__ = "restructuredtext en"
10 __docformat__ = "restructuredtext en"
13
11
14 #-------------------------------------------------------------------------------
12 #-------------------------------------------------------------------------------
15 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
13 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
16 # Brian E Granger <ellisonbg@gmail.com>
14 # Brian E Granger <ellisonbg@gmail.com>
17 # Benjamin Ragan-Kelley <benjaminrk@gmail.com>
15 # Benjamin Ragan-Kelley <benjaminrk@gmail.com>
18 #
16 #
19 # Distributed under the terms of the BSD License. The full license is in
17 # Distributed under the terms of the BSD License. The full license is in
20 # the file COPYING, distributed as part of this software.
18 # the file COPYING, distributed as part of this software.
21 #-------------------------------------------------------------------------------
19 #-------------------------------------------------------------------------------
22
20
23 #-------------------------------------------------------------------------------
21 #-------------------------------------------------------------------------------
24 # Imports
22 # Imports
25 #-------------------------------------------------------------------------------
23 #-------------------------------------------------------------------------------
26 from IPython.kernel.core.interpreter import Interpreter
24 from IPython.kernel.core.interpreter import Interpreter
27 import IPython.kernel.engineservice as es
25 import IPython.kernel.engineservice as es
28 from IPython.testing.util import DeferredTestCase
26 from IPython.testing.util import DeferredTestCase
29 from twisted.internet.defer import succeed
27 from twisted.internet.defer import succeed
30 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController
28 from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController
31
29
32 from Foundation import NSMakeRect
30 from Foundation import NSMakeRect
33 from AppKit import NSTextView, NSScrollView
31 from AppKit import NSTextView, NSScrollView
34
32
35 class TestIPythonCocoaControler(DeferredTestCase):
33 class TestIPythonCocoaControler(DeferredTestCase):
36 """Tests for IPythonCocoaController"""
34 """Tests for IPythonCocoaController"""
37
35
38 def setUp(self):
36 def setUp(self):
39 self.controller = IPythonCocoaController.alloc().init()
37 self.controller = IPythonCocoaController.alloc().init()
40 self.engine = es.EngineService()
38 self.engine = es.EngineService()
41 self.engine.startService()
39 self.engine.startService()
42
40
43
41
44 def tearDown(self):
42 def tearDown(self):
45 self.controller = None
43 self.controller = None
46 self.engine.stopService()
44 self.engine.stopService()
47
45
48 def testControllerExecutesCode(self):
46 def testControllerExecutesCode(self):
49 code ="""5+5"""
47 code ="""5+5"""
50 expected = Interpreter().execute(code)
48 expected = Interpreter().execute(code)
51 del expected['number']
49 del expected['number']
52 def removeNumberAndID(result):
50 def removeNumberAndID(result):
53 del result['number']
51 del result['number']
54 del result['id']
52 del result['id']
55 return result
53 return result
56 self.assertDeferredEquals(self.controller.execute(code).addCallback(removeNumberAndID), expected)
54 self.assertDeferredEquals(self.controller.execute(code).addCallback(removeNumberAndID), expected)
57
55
58 def testControllerMirrorsUserNSWithValuesAsStrings(self):
56 def testControllerMirrorsUserNSWithValuesAsStrings(self):
59 code = """userns1=1;userns2=2"""
57 code = """userns1=1;userns2=2"""
60 def testControllerUserNS(result):
58 def testControllerUserNS(result):
61 self.assertEquals(self.controller.userNS['userns1'], 1)
59 self.assertEquals(self.controller.userNS['userns1'], 1)
62 self.assertEquals(self.controller.userNS['userns2'], 2)
60 self.assertEquals(self.controller.userNS['userns2'], 2)
63
61
64 self.controller.execute(code).addCallback(testControllerUserNS)
62 self.controller.execute(code).addCallback(testControllerUserNS)
65
63
66
64
67 def testControllerInstantiatesIEngine(self):
65 def testControllerInstantiatesIEngine(self):
68 self.assert_(es.IEngineBase.providedBy(self.controller.engine))
66 self.assert_(es.IEngineBase.providedBy(self.controller.engine))
69
67
70 def testControllerCompletesToken(self):
68 def testControllerCompletesToken(self):
71 code = """longNameVariable=10"""
69 code = """longNameVariable=10"""
72 def testCompletes(result):
70 def testCompletes(result):
73 self.assert_("longNameVariable" in result)
71 self.assert_("longNameVariable" in result)
74
72
75 def testCompleteToken(result):
73 def testCompleteToken(result):
76 self.controller.complete("longNa").addCallback(testCompletes)
74 self.controller.complete("longNa").addCallback(testCompletes)
77
75
78 self.controller.execute(code).addCallback(testCompletes)
76 self.controller.execute(code).addCallback(testCompletes)
79
77
General Comments 0
You need to be logged in to leave comments. Login now