Пример #1
0
 def test_push_accepts_more2(self):
     isp = self.isp
     isp.push('if 1:')
     self.assertTrue(isp.push_accepts_more())
     isp.push('  x=1')
     self.assertTrue(isp.push_accepts_more())
     isp.push('')
     self.assertFalse(isp.push_accepts_more())
Пример #2
0
 def test_push_accepts_more2(self):
     isp = self.isp
     isp.push('if 1:')
     self.assertTrue(isp.push_accepts_more())
     isp.push('  x=1')
     self.assertTrue(isp.push_accepts_more())
     isp.push('')
     self.assertFalse(isp.push_accepts_more())
Пример #3
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)
Пример #4
0
 def test_push_accepts_more2(self):
     isp = self.isp
     isp.push("if 1:")
     self.assertTrue(isp.push_accepts_more())
     isp.push("  x=1")
     self.assertTrue(isp.push_accepts_more())
     isp.push("")
     self.assertFalse(isp.push_accepts_more())
Пример #5
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)
Пример #6
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)
Пример #7
0
    def test_push_accepts_more2(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == 'cell': return

        isp = self.isp
        isp.push('if 1:')
        self.assertTrue(isp.push_accepts_more())
        isp.push('  x=1')
        self.assertTrue(isp.push_accepts_more())
        isp.push('')
        self.assertFalse(isp.push_accepts_more())
Пример #8
0
    def test_push_accepts_more2(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == 'cell': return

        isp = self.isp
        isp.push('if 1:')
        self.assertTrue(isp.push_accepts_more())
        isp.push('  x=1')
        self.assertTrue(isp.push_accepts_more())
        isp.push('')
        self.assertFalse(isp.push_accepts_more())
Пример #9
0
    def test_push_accepts_more2(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == "cell":
            return

        isp = self.isp
        isp.push("if 1:")
        self.assertTrue(isp.push_accepts_more())
        isp.push("  x=1")
        self.assertTrue(isp.push_accepts_more())
        isp.push("")
        self.assertFalse(isp.push_accepts_more())
Пример #10
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)
Пример #11
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.assertFalse(isp.push_accepts_more())
     # 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.assertFalse(isp.push_accepts_more())
     # Even if the line is continuable (c.f. the regular Python
     # interpreter)
     isp.push(r"(1 \ ")
     self.assertFalse(isp.push_accepts_more())
Пример #12
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)
Пример #13
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.assertFalse(isp.push_accepts_more())
Пример #14
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)
Пример #15
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.assertTrue(isp.push_accepts_more())
     isp.push("    y = 3")
     self.assertTrue(isp.push_accepts_more())
     isp.push('')
     self.assertFalse(isp.push_accepts_more())
Пример #16
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)
Пример #17
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.assertTrue(isp.push_accepts_more())
Пример #18
0
    def test_push_accepts_more5(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == 'cell': return

        isp = self.isp
        isp.push('try:')
        isp.push('    a = 5')
        isp.push('except:')
        isp.push('    raise')
        self.assertTrue(isp.push_accepts_more())
Пример #19
0
    def test_push_accepts_more5(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == 'cell': return

        isp = self.isp
        isp.push('try:')
        isp.push('    a = 5')
        isp.push('except:')
        isp.push('    raise')
        self.assertTrue(isp.push_accepts_more())
Пример #20
0
    def test_push_accepts_more4(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == 'cell': return

        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.assertTrue(isp.push_accepts_more())
        isp.push("    y = 3")
        self.assertTrue(isp.push_accepts_more())
        isp.push('')
        self.assertFalse(isp.push_accepts_more())
Пример #21
0
    def test_push_accepts_more5(self):
        # In cell mode, inputs must be fed in whole blocks, so skip this test
        if self.isp.input_mode == "cell":
            return

        isp = self.isp
        isp.push("try:")
        isp.push("    a = 5")
        isp.push("except:")
        isp.push("    raise")
        self.assertTrue(isp.push_accepts_more())
Пример #22
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 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
Пример #23
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 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.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
Пример #24
0
 def test_push_accepts_more(self):
     isp = self.isp
     isp.push('x=1')
     self.assertFalse(isp.push_accepts_more())
Пример #25
0
 def test_continuation(self):
     isp = self.isp
     isp.push("import os, \\")
     self.assertTrue(isp.push_accepts_more())
     isp.push("sys")
     self.assertFalse(isp.push_accepts_more())
Пример #26
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)
Пример #27
0
if __name__ == '__main__':
    # A simple demo for interactive experimentation.  This code will not get
    # picked up by any test suite.
    from IPython.core.inputsplitter import InputSplitter, 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.indent_spaces
                if autoindent:
                    line = indent + raw_input(prompt+indent)
                else:
                    line = raw_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
            src = isp.source_reset()
            print 'Input source was:\n', src
    except EOFError:
        print 'Bye'
Пример #28
0
 def test_push_accepts_more3(self):
     isp = self.isp
     isp.push("x = (2+\n3)")
     self.assertEqual(isp.push_accepts_more(), False)
Пример #29
0
 def test_push_accepts_more(self):
     isp = self.isp
     isp.push('x=1')
     self.assertEqual(isp.push_accepts_more(), False)
Пример #30
0
if __name__ == '__main__':
    # A simple demo for interactive experimentation.  This code will not get
    # picked up by any test suite.
    from 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)
Пример #31
0
 def test_continuation(self):
     isp = self.isp
     isp.push("import os, \\")
     self.assertTrue(isp.push_accepts_more())
     isp.push("sys")
     self.assertFalse(isp.push_accepts_more())
Пример #32
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)
Пример #33
0
 def test_push_accepts_more3(self):
     isp = self.isp
     isp.push("x = (2+\n3)")
     self.assertFalse(isp.push_accepts_more())