def setUp(self): return self.shell = Mock() self.config = default_config() self.shell.config = self.config self.plugin = SmashCompleter(self.shell) self.event = Mock()
def get_ipython(): from IPython.terminal.interactiveshell import TerminalInteractiveShell if TerminalInteractiveShell._instance: return TerminalInteractiveShell.instance() config = tools.default_config() config.TerminalInteractiveShell.simple_prompt = True # Create and initialize our test-friendly IPython instance. shell = TerminalInteractiveShell.instance(config=config) return shell
def setUp(self): super(WstlTest, self).setUp() self.config = tools.default_config() self.config.TerminalInteractiveShell.simple_prompt = True self.shell = interactiveshell.TerminalInteractiveShell.instance( config=self.config) self._time = grpc_testing.strict_real_time() self._channel = grpc_testing.channel( wstlservice_pb2.DESCRIPTOR.services_by_name.values(), self._time) self.sample_hl7v2 = json.dumps(""" {'ADT_A01': {'ACC': None, 'AL1': [{'0': 'AL1', '1': '0', '2': {'1': 'AA'}, '3': {'1': 'Z88.0', '2': 'Personal history of allergy to penicillin', '3': 'ZAL'}, '4': {'1': 'SEVERE'}, '5': ['Shortness of breath'], '6': None}], 'ARV_1': None, 'ARV_2': None, 'DB1': None, 'DRG': None}}""")
def ipython_interactive(): config = tools.default_config() config.TerminalInteractiveShell.simple_prompt = True shell = interactiveshell.TerminalInteractiveShell.instance(config=config) return shell
def ipython(): config = tools.default_config() config.TerminalInteractiveShell.simple_prompt = True shell = interactiveshell.TerminalInteractiveShell.instance(config=config) return shell
def ipython(ipython_dir): config = default_config() config.TerminalInteractiveShell.simple_prompt = True shell = TerminalInteractiveShell.instance(config=config) yield shell TerminalInteractiveShell.clear_instance()
def _start_ipython(): """Start a global IPython shell, which we need for IPython-specific syntax. """ def xsys(self, cmd): """Replace the default system call with a capturing one for doctest. """ # We use getoutput, but we need to strip it because pexpect captures # the trailing newline differently from commands.getoutput print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout) sys.stdout.flush() def _showtraceback(self, etype, evalue, stb): """Print the traceback purely on stdout for doctest to capture it. """ print(self.InteractiveTB.stb2text(stb), file=sys.stdout) global get_ipython # This function should only ever run once! if hasattr(_start_ipython, "already_called"): return _start_ipython.already_called = True # Store certain global objects that IPython modifies _displayhook = sys.displayhook _excepthook = sys.excepthook _main = sys.modules.get("__main__") # Create custom argv and namespaces for our IPython to be test-friendly config = tools.default_config() config.TerminalInteractiveShell.simple_prompt = True # Create and initialize our test-friendly IPython instance. shell = InteractiveShell.instance(config=config) # A few more tweaks needed for playing nicely with doctests... # remove history file shell.tempfiles.append(config.HistoryManager.hist_file) # These traps are normally only active for interactive use, set them # permanently since we'll be mocking interactive sessions. shell.builtin_trap.activate() # Modify the IPython system call with one that uses getoutput, so that we # can capture subcommands and print them to Python's stdout, otherwise the # doctest machinery would miss them. shell.system = types.MethodType(xsys, shell) shell._showtraceback = types.MethodType(_showtraceback, shell) # IPython is ready, now clean up some global state... # Deactivate the various python system hooks added by ipython for # interactive convenience so we don't confuse the doctest system sys.modules["__main__"] = _main sys.displayhook = _displayhook sys.excepthook = _excepthook # So that ipython magics and aliases can be doctested (they work by making # a call into a global _ip object). Also make the top-level get_ipython # now return this without recursively calling here again. _ip = shell get_ipython = _ip.get_ipython builtin_mod._ip = _ip builtin_mod.ip = _ip builtin_mod.get_ipython = get_ipython # Override paging, so we don't require user interaction during the tests. def nopage(strng, start=0, screen_lines=0, pager_cmd=None): if isinstance(strng, dict): strng = strng.get("text/plain", "") print(strng) page.orig_page = page.pager_page page.pager_page = nopage return _ip