test_dualmode_insertcell.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from selenium.webdriver.common.keys import Keys
  2. from .utils import shift
  3. def test_insert_cell(notebook):
  4. a = "print('a')"
  5. b = "print('b')"
  6. c = "print('c')"
  7. notebook.edit_cell(index=0, content=a)
  8. notebook.append(b, c)
  9. notebook.to_command_mode()
  10. assert notebook.get_cells_contents() == [a, b, c]
  11. notebook.to_command_mode()
  12. notebook.focus_cell(2)
  13. notebook.convert_cell_type(2, "markdown")
  14. # insert code cell above
  15. notebook.current_cell.send_keys("a")
  16. assert notebook.get_cell_contents(2) == ""
  17. assert notebook.get_cell_type(2) == "code"
  18. assert len(notebook.cells) == 4
  19. # insert code cell below
  20. notebook.current_cell.send_keys("b")
  21. assert notebook.get_cell_contents(2) == ""
  22. assert notebook.get_cell_contents(3) == ""
  23. assert notebook.get_cell_type(3) == "code"
  24. assert len(notebook.cells) == 5
  25. notebook.edit_cell(index=1, content="cell1")
  26. notebook.focus_cell(1)
  27. notebook.current_cell.send_keys("a")
  28. assert notebook.get_cell_contents(1) == ""
  29. assert notebook.get_cell_contents(2) == "cell1"
  30. notebook.edit_cell(index=1, content='cell1')
  31. notebook.edit_cell(index=2, content='cell2')
  32. notebook.edit_cell(index=3, content='cell3')
  33. notebook.focus_cell(2)
  34. notebook.current_cell.send_keys("b")
  35. assert notebook.get_cell_contents(1) == "cell1"
  36. assert notebook.get_cell_contents(2) == "cell2"
  37. assert notebook.get_cell_contents(3) == ""
  38. assert notebook.get_cell_contents(4) == "cell3"
  39. # insert above multiple selected cells
  40. notebook.focus_cell(1)
  41. shift(notebook.browser, Keys.DOWN)
  42. notebook.current_cell.send_keys('a')
  43. # insert below multiple selected cells
  44. notebook.focus_cell(2)
  45. shift(notebook.browser, Keys.DOWN)
  46. notebook.current_cell.send_keys('b')
  47. assert notebook.get_cells_contents()[1:5] == ["", "cell1", "cell2", ""]