Exemplo n.º 1
0
 def test_push_accepts_more2(self):
     isp = self.isp
     isp.push('if 1:')
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('  x=1')
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 2
0
 def test_push_accepts_more2(self):
     isp = self.isp
     isp.push('if 1:')
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('  x=1')
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 3
0
 def test_line_continuation(self):
     """ Test issue #2108."""
     isp = self.isp
     # A blank line after a line continuation should not accept more
     isp.push("1 \\\n\n")
     self.assertEqual(isp.push_accepts_more(), False)
     # Whitespace after a \ is a SyntaxError.  The only way to test that
     # here is to test that push doesn't accept more (as with
     # test_syntax_error() above).
     isp.push(r"1 \ ")
     self.assertEqual(isp.push_accepts_more(), False)
     # Even if the line is continuable (c.f. the regular Python
     # interpreter)
     isp.push(r"(1 \ ")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 4
0
 def test_line_continuation(self):
     """ Test issue #2108."""
     isp = self.isp
     # A blank line after a line continuation should not accept more
     isp.push("1 \\\n\n")
     self.assertEqual(isp.push_accepts_more(), False)
     # Whitespace after a \ is a SyntaxError.  The only way to test that
     # here is to test that push doesn't accept more (as with
     # test_syntax_error() above).
     isp.push(r"1 \ ")
     self.assertEqual(isp.push_accepts_more(), False)
     # Even if the line is continuable (c.f. the regular Python
     # interpreter)
     isp.push(r"(1 \ ")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 5
0
 def test_syntax_error(self):
     isp = self.isp
     # Syntax errors immediately produce a 'ready' block, so the invalid
     # Python can be sent to the kernel for evaluation with possible ipython
     # special-syntax conversion.
     isp.push('run foo')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 6
0
 def test_syntax_error(self):
     isp = self.isp
     # Syntax errors immediately produce a 'ready' block, so the invalid
     # Python can be sent to the kernel for evaluation with possible ipython
     # special-syntax conversion.
     isp.push('run foo')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 7
0
 def test_push_accepts_more4(self):
     isp = self.isp
     # When a multiline statement contains parens or multiline strings, we
     # shouldn't get confused.
     # FIXME: we should be able to better handle de-dents in statements like
     # multiline strings and multiline expressions (continued with \ or
     # parens).  Right now we aren't handling the indentation tracking quite
     # correctly with this, though in practice it may not be too much of a
     # problem.  We'll need to see.
     isp.push("if 1:")
     isp.push("    x = (2+")
     isp.push("    3)")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push("    y = 3")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 8
0
 def test_push_accepts_more4(self):
     isp = self.isp
     # When a multiline statement contains parens or multiline strings, we
     # shouldn't get confused.
     # FIXME: we should be able to better handle de-dents in statements like
     # multiline strings and multiline expressions (continued with \ or
     # parens).  Right now we aren't handling the indentation tracking quite
     # correctly with this, though in practice it may not be too much of a
     # problem.  We'll need to see.
     isp.push("if 1:")
     isp.push("    x = (2+")
     isp.push("    3)")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push("    y = 3")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push('')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 9
0
 def test_push_accepts_more5(self):
     isp = self.isp
     isp.push('try:')
     isp.push('    a = 5')
     isp.push('except:')
     isp.push('    raise')
     # We want to be able to add an else: block at this point, so it should
     # wait for a blank line.
     self.assertEqual(isp.push_accepts_more(), True)
Exemplo n.º 10
0
 def test_push_accepts_more5(self):
     isp = self.isp
     isp.push('try:')
     isp.push('    a = 5')
     isp.push('except:')
     isp.push('    raise')
     # We want to be able to add an else: block at this point, so it should
     # wait for a blank line.
     self.assertEqual(isp.push_accepts_more(), True)
Exemplo n.º 11
0
def mini_interactive_loop(input_func):
    """Minimal example of the logic of an interactive interpreter loop.

    This serves as an example, and it is used by the test system with a fake
    raw_input that simulates interactive input."""

    from yap_ipython.core.inputsplitter import InputSplitter

    isp = InputSplitter()
    # In practice, this input loop would be wrapped in an outside loop to read
    # input indefinitely, until some exit/quit command was issued.  Here we
    # only illustrate the basic inner loop.
    while isp.push_accepts_more():
        indent = ' ' * isp.get_indent_spaces()
        prompt = '>>> ' + indent
        line = indent + input_func(prompt)
        isp.push(line)

    # Here we just return input so we can use it in a test suite, but a real
    # interpreter would instead send it for execution somewhere.
    src = isp.source_reset()
    #print 'Input source was:\n', src  # dbg
    return src
Exemplo n.º 12
0
def mini_interactive_loop(input_func):
    """Minimal example of the logic of an interactive interpreter loop.

    This serves as an example, and it is used by the test system with a fake
    raw_input that simulates interactive input."""

    from yap_ipython.core.inputsplitter import InputSplitter

    isp = InputSplitter()
    # In practice, this input loop would be wrapped in an outside loop to read
    # input indefinitely, until some exit/quit command was issued.  Here we
    # only illustrate the basic inner loop.
    while isp.push_accepts_more():
        indent = ' '*isp.get_indent_spaces()
        prompt = '>>> ' + indent
        line = indent + input_func(prompt)
        isp.push(line)

    # Here we just return input so we can use it in a test suite, but a real
    # interpreter would instead send it for execution somewhere.
    src = isp.source_reset()
    #print 'Input source was:\n', src  # dbg
    return src
Exemplo n.º 13
0
 def test_continuation(self):
     isp = self.isp
     isp.push("import os, \\")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push("sys")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 14
0
 def test_push_accepts_more3(self):
     isp = self.isp
     isp.push("x = (2+\n3)")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 15
0
 def test_push_accepts_more(self):
     isp = self.isp
     isp.push('x=1')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 16
0
 def test_push_accepts_more(self):
     isp = self.isp
     isp.push('x=1')
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 17
0
 def test_continuation(self):
     isp = self.isp
     isp.push("import os, \\")
     self.assertEqual(isp.push_accepts_more(), True)
     isp.push("sys")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 18
0
 def test_push_accepts_more3(self):
     isp = self.isp
     isp.push("x = (2+\n3)")
     self.assertEqual(isp.push_accepts_more(), False)
Exemplo n.º 19
0
if __name__ == '__main__':
    # A simple demo for interactive experimentation.  This code will not get
    # picked up by any test suite.
    from yap_ipython.core.inputsplitter import IPythonInputSplitter

    # configure here the syntax to use, prompt and whether to autoindent
    #isp, start_prompt = InputSplitter(), '>>> '
    isp, start_prompt = IPythonInputSplitter(), 'In> '

    autoindent = True
    #autoindent = False

    try:
        while True:
            prompt = start_prompt
            while isp.push_accepts_more():
                indent = ' ' * isp.get_indent_spaces()
                if autoindent:
                    line = indent + input(prompt + indent)
                else:
                    line = input(prompt)
                isp.push(line)
                prompt = '... '

            # Here we just return input so we can use it in a test suite, but a
            # real interpreter would instead send it for execution somewhere.
            #src = isp.source; raise EOFError # dbg
            raw = isp.source_raw
            src = isp.source_reset()
            print('Input source was:\n', src)
            print('Raw source was:\n', raw)
Exemplo n.º 20
0
if __name__ == '__main__':
    # A simple demo for interactive experimentation.  This code will not get
    # picked up by any test suite.
    from yap_ipython.core.inputsplitter import IPythonInputSplitter

    # configure here the syntax to use, prompt and whether to autoindent
    #isp, start_prompt = InputSplitter(), '>>> '
    isp, start_prompt = IPythonInputSplitter(), 'In> '

    autoindent = True
    #autoindent = False

    try:
        while True:
            prompt = start_prompt
            while isp.push_accepts_more():
                indent = ' '*isp.get_indent_spaces()
                if autoindent:
                    line = indent + input(prompt+indent)
                else:
                    line = input(prompt)
                isp.push(line)
                prompt = '... '

            # Here we just return input so we can use it in a test suite, but a
            # real interpreter would instead send it for execution somewhere.
            #src = isp.source; raise EOFError # dbg
            raw = isp.source_raw
            src = isp.source_reset()
            print('Input source was:\n', src)
            print('Raw source was:\n', raw)