Commit 4d7150a0 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Remove restriction of equal lines before and after editing

There was a restriction in place that a file should contain the same
number of todo items before and after an edit. This is now removed.

Reason for change is that I lost a lot of edits to a long list of items
and removing one single item from the list. The editor exits and as a
result topydo refused to process it, losing all the changes.

Another reason is that we have `revert` now. In case you severely mess
up, you can always revert.
parent 4e9f2e08
...@@ -96,24 +96,7 @@ class EditCommandTest(CommandTest): ...@@ -96,24 +96,7 @@ class EditCommandTest(CommandTest):
self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.todolist.is_dirty())
self.assertEqual(self.errors, "Invalid todo number given: 5.\n") self.assertEqual(self.errors, "Invalid todo number given: 5.\n")
@mock.patch('topydo.commands.EditCommand._is_edited') def test_edit05(self):
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
def test_edit05(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
""" Don't let to delete todos acidentally while editing. """
mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Only one line')]
mock_is_edited.return_value = True
command = EditCommand(["1", "Bar"], self.todolist, self.out,
self.error, None)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEqual(self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n")
self.assertEqual(self.todolist.print_todos(), u("Foo id:1\nBar p:1 @test\nBaz @test\nFo\u00f3B\u0105\u017a"))
def test_edit06(self):
""" """
Throw an error with invalid argument containing special characters. Throw an error with invalid argument containing special characters.
""" """
...@@ -128,7 +111,7 @@ class EditCommandTest(CommandTest): ...@@ -128,7 +111,7 @@ class EditCommandTest(CommandTest):
@mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand._is_edited')
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
def test_edit07(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): def test_edit06(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
""" Edit todo with special characters. """ """ Edit todo with special characters. """
mock_open_in_editor.return_value = 0 mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Lazy Cat')] mock_todos_from_temp.return_value = [Todo('Lazy Cat')]
...@@ -146,7 +129,7 @@ class EditCommandTest(CommandTest): ...@@ -146,7 +129,7 @@ class EditCommandTest(CommandTest):
@mock.patch('topydo.commands.EditCommand._is_edited') @mock.patch('topydo.commands.EditCommand._is_edited')
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp') @mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor') @mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
def test_edit08(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited): def test_edit07(self, mock_open_in_editor, mock_todos_from_temp, mock_is_edited):
""" Don't perform write if tempfile is unchanged """ """ Don't perform write if tempfile is unchanged """
mock_open_in_editor.return_value = 0 mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Only one line')] mock_todos_from_temp.return_value = [Todo('Only one line')]
......
...@@ -116,16 +116,12 @@ class EditCommand(MultiCommand): ...@@ -116,16 +116,12 @@ class EditCommand(MultiCommand):
new_todos = self._todos_from_temp(temp_todos) new_todos = self._todos_from_temp(temp_todos)
if _is_edited(orig_mtime, temp_todos): if _is_edited(orig_mtime, temp_todos):
if len(new_todos) == len(self.todos): for todo in self.todos:
for todo in self.todos: BASE_TODOLIST(self.todolist).delete(todo)
BASE_TODOLIST(self.todolist).delete(todo)
for todo in new_todos:
for todo in new_todos: self.todolist.add_todo(todo)
self.todolist.add_todo(todo) self.out(self.printer.print_todo(todo))
self.out(self.printer.print_todo(todo))
else:
self.error('Number of edited todos is not equal to '
'number of supplied todo IDs.')
else: else:
self.error('Editing aborted. Nothing to do.') self.error('Editing aborted. Nothing to do.')
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment