test_cocoa_frontend.py
77 lines
| 3.0 KiB
| text/x-python
|
PythonLexer
Barry Wark
|
r1263 | # encoding: utf-8 | ||
"""This file contains unittests for the ipython1.frontend.cocoa.cocoa_frontend module. | ||||
Things that should be tested: | ||||
- IPythonCocoaController instantiates an IEngineInteractive | ||||
- IPythonCocoaController executes code on the engine | ||||
- IPythonCocoaController mirrors engine's user_ns | ||||
""" | ||||
__docformat__ = "restructuredtext en" | ||||
#------------------------------------------------------------------------------- | ||||
# Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> | ||||
# Brian E Granger <ellisonbg@gmail.com> | ||||
# Benjamin Ragan-Kelley <benjaminrk@gmail.com> | ||||
# | ||||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#------------------------------------------------------------------------------- | ||||
#------------------------------------------------------------------------------- | ||||
# Imports | ||||
#------------------------------------------------------------------------------- | ||||
Barry Wark
|
r1264 | from IPython.kernel.core.interpreter import Interpreter | ||
import IPython.kernel.engineservice as es | ||||
Barry Wark
|
r1275 | from IPython.testing.util import DeferredTestCase | ||
Barry Wark
|
r1263 | from twisted.internet.defer import succeed | ||
Barry Wark
|
r1275 | from IPython.frontend.cocoa.cocoa_frontend import IPythonCocoaController | ||
Barry Wark
|
r1263 | |||
Barry Wark
|
r1275 | from Foundation import NSMakeRect | ||
from AppKit import NSTextView, NSScrollView | ||||
Barry Wark
|
r1263 | |||
class TestIPythonCocoaControler(DeferredTestCase): | ||||
"""Tests for IPythonCocoaController""" | ||||
def setUp(self): | ||||
self.controller = IPythonCocoaController.alloc().init() | ||||
self.engine = es.EngineService() | ||||
self.engine.startService() | ||||
def tearDown(self): | ||||
self.controller = None | ||||
self.engine.stopService() | ||||
def testControllerExecutesCode(self): | ||||
code ="""5+5""" | ||||
expected = Interpreter().execute(code) | ||||
del expected['number'] | ||||
def removeNumberAndID(result): | ||||
del result['number'] | ||||
del result['id'] | ||||
return result | ||||
Barry Wark
|
r1275 | self.assertDeferredEquals(self.controller.execute(code).addCallback(removeNumberAndID), expected) | ||
Barry Wark
|
r1263 | |||
def testControllerMirrorsUserNSWithValuesAsStrings(self): | ||||
code = """userns1=1;userns2=2""" | ||||
def testControllerUserNS(result): | ||||
Barry Wark
|
r1275 | self.assertEquals(self.controller.userNS['userns1'], 1) | ||
self.assertEquals(self.controller.userNS['userns2'], 2) | ||||
Barry Wark
|
r1263 | |||
Barry Wark
|
r1275 | self.controller.execute(code).addCallback(testControllerUserNS) | ||
Barry Wark
|
r1263 | |||
def testControllerInstantiatesIEngine(self): | ||||
Barry Wark
|
r1275 | self.assert_(es.IEngineBase.providedBy(self.controller.engine)) | ||
Barry Wark
|
r1263 | |||
def testControllerCompletesToken(self): | ||||
code = """longNameVariable=10""" | ||||
def testCompletes(result): | ||||
self.assert_("longNameVariable" in result) | ||||
def testCompleteToken(result): | ||||
self.controller.complete("longNa").addCallback(testCompletes) | ||||
Barry Wark
|
r1275 | self.controller.execute(code).addCallback(testCompletes) | ||
Barry Wark
|
r1263 | |||