def test_insert_disp_lines2(self): raw_cell1 = """\ y = x ##:S z = 0 """ eres1 = """\ y = x ##:S custom_display("y.shape", y.shape); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ y = x ##:i z = 0 """ eres1 = """\ y = x ##:i custom_display("info(y)", _ipydex__info(y)); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1)
def test_demo2(self): raw_cell1 = """\ if 1: # van-der-Pol-Oszillator f = sp.Matrix([x2, (1-x1**2)*x2 - x1]) y = h = x1 selector ##: n = len(f) f ##: y ##: """ eres1 = """\ if 1: # van-der-Pol-Oszillator f = sp.Matrix([x2, (1-x1**2)*x2 - x1]) y = h = x1 custom_display("(selector)", (selector)); display({"text/plain": "---"}, raw=True) n = len(f) custom_display("(f)", (f)); display({"text/plain": "---"}, raw=True) custom_display("(y)", (y)); display({"text/plain": "---"}, raw=True) """ ll = dt.get_logical_lines_of_cell(raw_cell1) res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(res1, eres1)
def test_demo1(self): raw_cell1 = """\ # numpy arrays and matrices are indented to take left-hand-side into account np.random.seed(0) A = np.random.random((5, 4)) ##: np.matrix(A) ##: # heuristic to insert a newline if indentation would be too long A_with_long_name = A ##: """ eres1 = """\ # numpy arrays and matrices are indented to take left-hand-side into account np.random.seed(0) A = np.random.random((5, 4)) ##: custom_display("A", A); display({"text/plain": "---"}, raw=True) custom_display("(np.matrix(A))", (np.matrix(A))); display({"text/plain": "---"}, raw=True) # heuristic to insert a newline if indentation would be too long A_with_long_name = A ##: custom_display("A_with_long_name", A_with_long_name); display({"text/plain": "---"}, raw=True) """ ll = dt.get_logical_lines_of_cell(raw_cell1) res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(res1, eres1)
def test_insert_disp_lines2(self): raw_cell1 = """\ y = x ##:S z = 0 """ eres1 = """\ y = x ##:S custom_display("y.shape", y.shape); print("---") z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1)
def testLL3(self): raw_cell1 = """\ xx = sp.Matrix(sp.symbols('x1:11')) yy = sp.Matrix(sp.symbols('y1:11')) xx.shape, yy.shape ##: """ eres1 = """\ xx = sp.Matrix(sp.symbols('x1:11')) yy = sp.Matrix(sp.symbols('y1:11')) custom_display("(xx.shape, yy.shape)", (xx.shape, yy.shape)); display({"text/plain": "---"}, raw=True) """ ll = dt.get_logical_lines_of_cell(raw_cell1) res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(res1, eres1)
def test_demo4(self): # tag_issue_comment_at_end_of_indented_blocks raw_cell1 = """\ if 0: pass # some comment 1 == 1 """ eres1 = """\ if 0: pass # some comment 1 == 1 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(res1, eres1)
def test_demo3(self): raw_cell1 = """\ if 1: # van-der-Pol-Oszillator f = sp.Matrix([x2, (1-x1**2)*x2 - x1]) y = h = x1 ##: a = 0 """ eres1 = """\ if 1: # van-der-Pol-Oszillator f = sp.Matrix([x2, (1-x1**2)*x2 - x1]) y = h = x1 ##: custom_display("h", h); display({"text/plain": "---"}, raw=True) a = 0 """ ll = dt.get_logical_lines_of_cell(raw_cell1) res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(res1, eres1)
def test_insert_disp_lines1(self): raw_cell1 = """\ x = 0 y = 1 ##: z = 0 """ eres1 = """\ x = 0 y = 1 ##: custom_display("y", y); print("---") z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 y = 1 # more comments ##: more comments z = 0 """ eres1 = """\ x = 0 y = 1 # more comments ##: more comments custom_display("y", y); print("---") z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 # y = 1 ##: z = 0 """ eres1 = raw_cell1 res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y = 1 ##: z = 0 """ eres1 = """\ x = 0 if 1: y = 1 ##: custom_display("y", y); print("---") z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y ##: C.xyz ##: """ eres1 = """\ x = 0 if 1: custom_display("(y)", (y)); print("---") custom_display("(C.xyz)", (C.xyz)); print("---") """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y1, y2 = 1, 2 ##: y1, y2 = yy = 1, 2 ##: yy = y1, y2 = 1, 2 ##: y1, y2 = yy = 1, 2 ##:T z = 0 """ eres1 = """\ x = 0 if 1: y1, y2 = 1, 2 ##: custom_display("(y1, y2)", (y1, y2)); print("---") y1, y2 = yy = 1, 2 ##: custom_display("yy", yy); print("---") yy = y1, y2 = 1, 2 ##: custom_display("(y1, y2)", (y1, y2)); print("---") y1, y2 = yy = 1, 2 ##:T custom_display("yy.T", yy.T); print("---") z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ def func(a, b): ''' some docstring ''' pass """ eres1 = raw_cell1 res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = func1(a=a, b = b) ##: if 1: y = func2(a=a, b = b) ##:T """ eres1 = """\ x = func1(a=a, b = b) ##: custom_display("x", x); print("---") if 1: y = func2(a=a, b = b) ##:T custom_display("y.T", y.T); print("---") """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1)
def test_insert_disp_lines1(self): raw_cell1 = """\ x = 0 y = 1 ##: z = 0 """ eres1 = """\ x = 0 y = 1 ##: custom_display("y", y); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 y = 1 # more comments ##: more comments z = 0 """ eres1 = """\ x = 0 y = 1 # more comments ##: more comments custom_display("y", y); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 # y = 1 ##: ZZ = 0 """ eres1 = raw_cell1 res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y = 1 ##: z = 0 """ eres1 = """\ x = 0 if 1: y = 1 ##: custom_display("y", y); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y ##: C.xyz ##: """ eres1 = """\ x = 0 if 1: custom_display("(y)", (y)); display({"text/plain": "---"}, raw=True) custom_display("(C.xyz)", (C.xyz)); display({"text/plain": "---"}, raw=True) """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = 0 if 1: y1, y2 = 1, 2 ##: y1, y2 = yy = 1, 2 ##: yy = y1, y2 = 1, 2 ##: y1, y2 = yy = 1, 2 ##:T z = 0 """ eres1 = """\ x = 0 if 1: y1, y2 = 1, 2 ##: custom_display("(y1, y2)", (y1, y2)); display({"text/plain": "---"}, raw=True) y1, y2 = yy = 1, 2 ##: custom_display("yy", yy); display({"text/plain": "---"}, raw=True) yy = y1, y2 = 1, 2 ##: custom_display("(y1, y2)", (y1, y2)); display({"text/plain": "---"}, raw=True) y1, y2 = yy = 1, 2 ##:T custom_display("yy.T", yy.T); display({"text/plain": "---"}, raw=True) z = 0 """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ def func(a, b): ''' some docstring ''' pass """ eres1 = raw_cell1 res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1) # -------------------- raw_cell1 = """\ x = func1(a=a, b = b) ##: if 1: y = func2(a=a, b = b) ##:T """ eres1 = """\ x = func1(a=a, b = b) ##: custom_display("x", x); display({"text/plain": "---"}, raw=True) if 1: y = func2(a=a, b = b) ##:T custom_display("y.T", y.T); display({"text/plain": "---"}, raw=True) """ res1 = dt.insert_disp_lines(raw_cell1) self.assertEqual(eres1, res1)