def test_syntax(self): """Call all single-line syntax tests from the main object""" isp = self.isp for example in syntax.itervalues(): for raw, out_t in example: if raw.startswith(' '): continue isp.push(raw) out = isp.source_reset().rstrip() self.assertEqual(out, out_t)
def test_syntax_multiline(self): isp = self.isp for example in syntax_ml.itervalues(): out_t_parts = [] for line_pairs in example: for raw, out_t_part in line_pairs: isp.push(raw) out_t_parts.append(out_t_part) out = isp.source_reset().rstrip() out_t = '\n'.join(out_t_parts).rstrip() self.assertEqual(out, out_t)
def test_syntax(self): """Call all single-line syntax tests from the main object""" isp = self.isp for example in syntax.values(): for raw, out_t in example: if raw.startswith(' '): continue isp.push(raw+'\n') out_raw = isp.source_raw out = isp.source_reset() self.assertEqual(out.rstrip(), out_t, tt.pair_fail_msg.format("inputsplitter",raw, out_t, out)) self.assertEqual(out_raw.rstrip(), raw.rstrip())
def test_syntax_multiline(self): isp = self.isp for example in syntax_ml.itervalues(): raw_parts = [] out_t_parts = [] for line_pairs in example: for raw, out_t_part in line_pairs: raw_parts.append(raw) out_t_parts.append(out_t_part) raw = '\n'.join(raw_parts) out_t = '\n'.join(out_t_parts) isp.push(raw) out = isp.source_reset() # Match ignoring trailing whitespace self.assertEqual(out.rstrip(), out_t.rstrip())
def test_syntax_multiline(self): isp = self.isp for example in syntax_ml.values(): for line_pairs in example: out_t_parts = [] raw_parts = [] for lraw, out_t_part in line_pairs: if out_t_part is not None: out_t_parts.append(out_t_part) if lraw is not None: isp.push(lraw) raw_parts.append(lraw) out_raw = isp.source_raw out = isp.source_reset() out_t = '\n'.join(out_t_parts).rstrip() raw = '\n'.join(raw_parts).rstrip() self.assertEqual(out.rstrip(), out_t) self.assertEqual(out_raw.rstrip(), raw)
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
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
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) except EOFError: print('Bye') # Tests for cell magics support def test_last_blank(): assert isp.last_blank("") is False assert isp.last_blank("abc") is False assert isp.last_blank("abc\n") is False assert isp.last_blank("abc\na") is False assert isp.last_blank("\n") is True
# 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'