test_find_and_replace.py 1021 B

123456789101112131415161718192021222324
  1. import pytest
  2. def test_find_and_replace(notebook):
  3. """ test find and replace on all the cells """
  4. cell_0, cell_1, cell_2, cell_3 = "hello", "hellohello", "abc", "ello"
  5. find_str = "ello" # string to replace
  6. replace_str = "foo" # string to replace to
  7. # set the contents of the cells
  8. notebook.add_cell(index=0, content=cell_0);
  9. notebook.add_cell(index=1, content=cell_1);
  10. notebook.add_cell(index=2, content=cell_2);
  11. notebook.add_cell(index=3, content=cell_3);
  12. # replace the strings
  13. notebook.find_and_replace(index=0, find_txt=find_str, replace_txt=replace_str)
  14. # check content of the cells
  15. assert notebook.get_cell_contents(0) == cell_0.replace(find_str, replace_str)
  16. assert notebook.get_cell_contents(1) == cell_1.replace(find_str, replace_str)
  17. assert notebook.get_cell_contents(2) == cell_2.replace(find_str, replace_str)
  18. assert notebook.get_cell_contents(3) == cell_3.replace(find_str, replace_str)