def test_separator_added_if_needed(self, tasklist_file): new_tasks = "[ ] one more thing to do!\n" updated = add_to_section(tasklist_file, 'THIS WEEK', new_tasks, ensure_separator=True) expected = ("TOMORROW:\n" "[ ] a task\n" "Just some additional clarifications\n" "\n" "[\\] a WIP task\n" "[o] a scheduled task [$TOMORROW$]\n" "THIS WEEK:\n" "[ ] one more thing to do!\n" "[ ] a task with subtasks\n" "\t[\\] first thing\n" "\tclarification of first thing\n" "\t[ ] second thing\n" "\n" "THIS MONTH:\n" "THIS QUARTER:\n" "THIS YEAR:\n" "SOMEDAY:\n" "[ ] another task\n") assert updated.read() == expected
def test_file_containing_only_section(self): contents = "AGENDA:\n[ ] do this\n[\\] another thing\n" new_tasks = "[ ] one more thing to do!\n" file = make_file(contents) updated = add_to_section(file, 'AGENDA', new_tasks, above=False, ensure_separator=True) expected = contents + new_tasks assert updated.read() == expected
def test_existing_contents_are_preserved_below(self, tasklist_file): new_tasks = "[ ] one more thing to do!\n" updated = add_to_section(tasklist_file, 'THIS WEEK', new_tasks) expected = ("TOMORROW:\n" "[ ] a task\n" "Just some additional clarifications\n" "\n" "[\\] a WIP task\n" "[o] a scheduled task [$TOMORROW$]\n" "THIS WEEK:\n" "[ ] one more thing to do!\n" "[ ] a task with subtasks\n" "\t[\\] first thing\n" "\tclarification of first thing\n" "\t[ ] second thing\n" "THIS MONTH:\n" "THIS QUARTER:\n" "THIS YEAR:\n" "SOMEDAY:\n" "[ ] another task\n") assert updated.read() == expected
def test_add_to_bottom_of_file(self, tasklist_file): new_tasks = "[ ] one more thing to do!\n" updated = add_to_section(tasklist_file, 'SOMEDAY', new_tasks, above=False) expected = ("TOMORROW:\n" "[ ] a task\n" "Just some additional clarifications\n" "\n" "[\\] a WIP task\n" "[o] a scheduled task [$TOMORROW$]\n" "THIS WEEK:\n" "[ ] a task with subtasks\n" "\t[\\] first thing\n" "\tclarification of first thing\n" "\t[ ] second thing\n" "THIS MONTH:\n" "THIS QUARTER:\n" "THIS YEAR:\n" "SOMEDAY:\n" "[ ] another task\n" "[ ] one more thing to do!\n") assert updated.read() == expected
def test_section_missing(self, tasklist_file): new_tasks = "[ ] one more thing to do!\n" with pytest.raises(ValueError): add_to_section(tasklist_file, 'THIS DECADE', new_tasks)