def loadterm(self, code_str, **kwargs): splitter = inputsplitter.IPythonInputSplitter() code_lines = code_str.lstrip().splitlines() sources = [] outputs = [] for line in code_lines: if splitter.push_accepts_more(): splitter.push(line) else: code_str = splitter.source sources.append(code_str) out = self.loadstring(code_str) #print(out) outputs.append(out) splitter.reset() splitter.push(line) if splitter.source != "": code_str = splitter.source sources.append(code_str) out = self.loadstring(code_str) outputs.append(out) return ((sources, outputs))
class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(input_mode='line') def test_incremental(self): sp = self.sp sp.push('%%cellm line2\n') nt.assert_true(sp.push_accepts_more()) #1 sp.push('\n') nt.assert_false(sp.push_accepts_more()) #2
class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(line_input_checker=True) def test_incremental(self): sp = self.sp sp.push("%%cellm line2\n") assert sp.push_accepts_more() is True # 1 sp.push("\n") # In this case, a blank line should end the cell magic assert sp.push_accepts_more() is False # 2
class LineModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(line_input_checker=True) def test_incremental(self): sp = self.sp sp.push('%%cellm line2\n') nt.assert_true(sp.push_accepts_more()) #1 sp.push('\n') # In this case, a blank line should end the cell magic nt.assert_false(sp.push_accepts_more()) #2
class CellModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(line_input_checker=False) def test_incremental(self): sp = self.sp sp.push('%%cellm firstline\n') nt.assert_true(sp.push_accepts_more()) #1 sp.push('line2\n') nt.assert_true(sp.push_accepts_more()) #2 sp.push('\n') # This should accept a blank line and carry on until the cell is reset nt.assert_true(sp.push_accepts_more()) #3
class CellModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(line_input_checker=False) def test_incremental(self): sp = self.sp sp.push("%%cellm firstline\n") nt.assert_true(sp.push_accepts_more()) # 1 sp.push("line2\n") nt.assert_true(sp.push_accepts_more()) # 2 sp.push("\n") # This should accept a blank line and carry on until the cell is reset nt.assert_true(sp.push_accepts_more()) # 3 def test_no_strip_coding(self): src = "\n".join( ["%%writefile foo.py", "# coding: utf-8", 'print(u"üñîçø∂é")']) out = self.sp.transform_cell(src) nt.assert_in("# coding: utf-8", out)
class CellModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(input_mode='cell') def test_incremental(self): sp = self.sp src = '%%cellm line2\n' sp.push(src) nt.assert_true(sp.push_accepts_more()) #1 src += '\n' sp.push(src) # Note: if we ever change the logic to allow full blank lines (see # _handle_cell_magic), then the following test should change to true nt.assert_false(sp.push_accepts_more()) #2 # By now, even with full blanks allowed, a second blank should signal # the end. For now this test is only a redundancy safety, but don't # delete it in case we change our mind and the previous one goes to # true. src += '\n' sp.push(src) nt.assert_false(sp.push_accepts_more()) #3
class CellModeCellMagics(CellMagicsCommon, unittest.TestCase): sp = isp.IPythonInputSplitter(line_input_checker=False) def test_incremental(self): sp = self.sp sp.push("%%cellm firstline\n") assert sp.push_accepts_more() is True # 1 sp.push("line2\n") assert sp.push_accepts_more() is True # 2 sp.push("\n") # This should accept a blank line and carry on until the cell is reset assert sp.push_accepts_more() is True # 3 def test_no_strip_coding(self): src = '\n'.join([ '%%writefile foo.py', '# coding: utf-8', 'print(u"üñîçø∂é")', ]) out = self.sp.transform_cell(src) assert "# coding: utf-8" in out
def setUp(self): self.isp = isp.IPythonInputSplitter()
def setUp(self): self.isp = isp.IPythonInputSplitter(input_mode='cell')