def test_transform(xession): @xession.builtins.events.on_transform_command def spam2egg(cmd, **_): if cmd == "spam": return "egg" else: return cmd assert transform_command("spam") == "egg" assert transform_command("egg") == "egg" assert transform_command("foo") == "foo"
def test_transform(xonsh_builtins): @xonsh_builtins.events.on_transform_command def spam2egg(cmd): if cmd == 'spam': return 'egg' else: return cmd assert transform_command('spam') == 'egg' assert transform_command('egg') == 'egg' assert transform_command('foo') == 'foo'
def test_transform(xonsh_builtins): @xonsh_builtins.events.on_transform_command def spam2egg(cmd, **_): if cmd == "spam": return "egg" else: return cmd assert transform_command("spam") == "egg" assert transform_command("egg") == "egg" assert transform_command("foo") == "foo"
def test_transform(xonsh_builtins): @xonsh_builtins.events.on_transform_command def spam2egg(cmd, **_): if cmd == 'spam': return 'egg' else: return cmd assert transform_command('spam') == 'egg' assert transform_command('egg') == 'egg' assert transform_command('foo') == 'foo'
def push(self, line): """Pushes a line onto the buffer and compiles the code in a way that enables multiline input. """ self.buffer.append(line) if self.need_more_lines: return None, None src = "".join(self.buffer) src = transform_command(src) return self.compile(src)
def can_compile(src): """Returns whether the code can be compiled, i.e. it is valid xonsh.""" src = src if src.endswith("\n") else src + "\n" src = transform_command(src, show_diff=False) src = src.lstrip() try: XSH.execer.compile(src, mode="single", glbs=None, locs=XSH.ctx) rtn = True except SyntaxError: rtn = False except Exception: rtn = True return rtn
def can_compile(src): """Returns whether the code can be compiled, i.e. it is valid xonsh.""" src = src if src.endswith('\n') else src + '\n' src = transform_command(src, show_diff=False) src = src.lstrip() try: builtins.__xonsh_execer__.compile(src, mode='single', glbs=None, locs=builtins.__xonsh_ctx__) rtn = True except SyntaxError: rtn = False except Exception: rtn = True return rtn
def _push(self, line): """Pushes a line onto the buffer and compiles the code in a way that enables multiline input. """ code = None self.buffer.append(line) if self.need_more_lines: return None, code src = "".join(self.buffer) src = transform_command(src) try: code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None) self.reset_buffer() except Exception: # pylint: disable=broad-except self.reset_buffer() print_exception() return src, None return src, code