Commit ffdd292f authored by Jacek Sowiński's avatar Jacek Sowiński

Introduce new method for getting command shortname

parent 83d1005a
...@@ -405,6 +405,11 @@ class AddCommandTest(CommandTest): ...@@ -405,6 +405,11 @@ class AddCommandTest(CommandTest):
"| 1| x 2015-01-01 {} Already completed\n".format(self.today)) "| 1| x 2015-01-01 {} Already completed\n".format(self.today))
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_add_name(self):
name = AddCommand.AddCommand.name()
self.assertEqual(name, 'add')
def test_help(self): def test_help(self):
command = AddCommand.AddCommand(["help"], self.todolist, self.out, command = AddCommand.AddCommand(["help"], self.todolist, self.out,
self.error) self.error)
......
...@@ -102,6 +102,11 @@ class AppendCommandTest(CommandTest): ...@@ -102,6 +102,11 @@ class AppendCommandTest(CommandTest):
"| 2| Qux due:%s t:%s p:1 p:2\n" % (self.today, self.today)) "| 2| Qux due:%s t:%s p:1 p:2\n" % (self.today, self.today))
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_append_name(self):
name = AppendCommand.name()
self.assertEqual(name, 'append')
def test_help(self): def test_help(self):
command = AppendCommand(["help"], self.todolist, self.out, self.error) command = AppendCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -243,6 +243,11 @@ class DeleteCommandTest(CommandTest): ...@@ -243,6 +243,11 @@ class DeleteCommandTest(CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_delete_name(self):
name = DeleteCommand.name()
self.assertEqual(name, 'delete')
def test_help(self): def test_help(self):
command = DeleteCommand(["help"], self.todolist, self.out, self.error) command = DeleteCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -360,6 +360,11 @@ node [ shape="none" margin="0" fontsize="9" fontname="Helvetica" ] ...@@ -360,6 +360,11 @@ node [ shape="none" margin="0" fontsize="9" fontname="Helvetica" ]
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
self.assertFalse(self.todolist.dirty) self.assertFalse(self.todolist.dirty)
def test_dep_name(self):
name = DepCommand.name()
self.assertEqual(name, 'dep')
def test_help(self): def test_help(self):
command = DepCommand(["help"], self.todolist, self.out, self.error) command = DepCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -167,6 +167,11 @@ class DepriCommandTest(CommandTest): ...@@ -167,6 +167,11 @@ class DepriCommandTest(CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_depri_name(self):
name = DepriCommand.name()
self.assertEqual(name, 'depri')
def test_help(self): def test_help(self):
command = DepriCommand(["help"], self.todolist, self.out, self.error) command = DepriCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -454,6 +454,11 @@ class DoCommandTest(CommandTest): ...@@ -454,6 +454,11 @@ class DoCommandTest(CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_do_name(self):
name = DoCommand.name()
self.assertEqual(name, 'do')
def test_help(self): def test_help(self):
command = DoCommand(["help"], self.todolist, self.out, self.error) command = DoCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -196,6 +196,11 @@ class EditCommandTest(CommandTest): ...@@ -196,6 +196,11 @@ class EditCommandTest(CommandTest):
self.assertEqual(self.todolist.print_todos(), result) self.assertEqual(self.todolist.print_todos(), result)
mock_call.assert_called_once_with([editor, todotxt]) mock_call.assert_called_once_with([editor, todotxt])
def test_edit_name(self):
name = EditCommand.name()
self.assertEqual(name, 'edit')
def test_help(self): def test_help(self):
command = EditCommand(["help"], self.todolist, self.out, self.error, command = EditCommand(["help"], self.todolist, self.out, self.error,
None) None)
......
...@@ -420,6 +420,11 @@ class ListCommandTest(CommandTest): ...@@ -420,6 +420,11 @@ class ListCommandTest(CommandTest):
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n") self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_list_name(self):
name = ListCommand.name()
self.assertEqual(name, 'list')
def test_help(self): def test_help(self):
command = ListCommand(["help"], self.todolist, self.out, self.error) command = ListCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -38,6 +38,11 @@ class ListContextCommandTest(CommandTest): ...@@ -38,6 +38,11 @@ class ListContextCommandTest(CommandTest):
self.assertEqual(self.output, "Context1\nContext2\n") self.assertEqual(self.output, "Context1\nContext2\n")
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_listcontext_name(self):
name = ListContextCommand.name()
self.assertEqual(name, 'listcontext')
def test_help(self): def test_help(self):
command = ListContextCommand(["help"], None, self.out, self.error) command = ListContextCommand(["help"], None, self.out, self.error)
command.execute() command.execute()
......
...@@ -38,6 +38,11 @@ class ListProjectCommandTest(CommandTest): ...@@ -38,6 +38,11 @@ class ListProjectCommandTest(CommandTest):
self.assertEqual(self.output, "Project1\nProject2\n") self.assertEqual(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_listproject_name(self):
name = ListProjectCommand.name()
self.assertEqual(name, 'listproject')
def test_help(self): def test_help(self):
command = ListProjectCommand(["help"], None, self.out, self.error) command = ListProjectCommand(["help"], None, self.out, self.error)
command.execute() command.execute()
......
...@@ -314,6 +314,11 @@ class PostponeCommandTest(CommandTest): ...@@ -314,6 +314,11 @@ class PostponeCommandTest(CommandTest):
self.assertEqual(self.output, result) self.assertEqual(self.output, result)
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_postpone_name(self):
name = PostponeCommand.name()
self.assertEqual(name, 'postpone')
def test_help(self): def test_help(self):
command = PostponeCommand(["help"], self.todolist, self.out, command = PostponeCommand(["help"], self.todolist, self.out,
self.error) self.error)
......
...@@ -249,6 +249,11 @@ class PriorityCommandTest(CommandTest): ...@@ -249,6 +249,11 @@ class PriorityCommandTest(CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_priority_name(self):
name = PriorityCommand.name()
self.assertEqual(name, 'priority')
def test_help(self): def test_help(self):
command = PriorityCommand(["help"], self.todolist, self.out, command = PriorityCommand(["help"], self.todolist, self.out,
self.error) self.error)
......
...@@ -318,6 +318,11 @@ class RevertCommandTest(CommandTest): ...@@ -318,6 +318,11 @@ class RevertCommandTest(CommandTest):
self.assertEqual(config().backup_count(), 5) self.assertEqual(config().backup_count(), 5)
def test_revert_name(self):
name = RevertCommand.name()
self.assertEqual(name, 'revert')
def test_help(self): def test_help(self):
command = RevertCommand(["help"], self.todolist, self.out, self.error) command = RevertCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -53,6 +53,11 @@ class SortCommandTest(CommandTest): ...@@ -53,6 +53,11 @@ class SortCommandTest(CommandTest):
self.assertEqual(todo1.source(), todo2.source()) self.assertEqual(todo1.source(), todo2.source())
def test_sort_name(self):
name = SortCommand.name()
self.assertEqual(name, 'sort')
def test_help(self): def test_help(self):
command = SortCommand(["help"], self.todolist, self.out, self.error) command = SortCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -288,6 +288,11 @@ class TagCommandTest(CommandTest): ...@@ -288,6 +288,11 @@ class TagCommandTest(CommandTest):
self.assertEqual(self.output, "") self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_tag_name(self):
name = TagCommand.name()
self.assertEqual(name, 'tag')
def test_help(self): def test_help(self):
command = TagCommand(["help"], self.todolist, self.out, self.error) command = TagCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -85,6 +85,11 @@ class Command(object): ...@@ -85,6 +85,11 @@ class Command(object):
return result return result
@classmethod
def name(cls):
"""" Returns short-name of the command. """
return cls.__name__[:-7].lower() # strip 'Command'
def usage(self): def usage(self):
""" Returns a one-line synopsis for this command. """ """ Returns a one-line synopsis for this command. """
raise NotImplementedError raise NotImplementedError
......
...@@ -249,7 +249,7 @@ class CLIApplicationBase(object): ...@@ -249,7 +249,7 @@ class CLIApplicationBase(object):
def _backup(self, p_command, p_args=[], p_label=None): def _backup(self, p_command, p_args=[], p_label=None):
if config().backup_count() > 0 and p_command and not self.is_read_only(p_command): if config().backup_count() > 0 and p_command and not self.is_read_only(p_command):
call = [p_command.__module__.lower()[16:-7]] + p_args # strip "topydo.commands" and "Command" call = [p_command.name()]+ p_args
from topydo.lib.ChangeSet import ChangeSet from topydo.lib.ChangeSet import ChangeSet
label = p_label if p_label else call label = p_label if p_label else call
......
...@@ -27,7 +27,7 @@ class Transaction(object): ...@@ -27,7 +27,7 @@ class Transaction(object):
self._cmd = lambda op: p_subcommand(op, *p_env_args) self._cmd = lambda op: p_subcommand(op, *p_env_args)
self._todo_ids = p_todo_ids self._todo_ids = p_todo_ids
self._operations = [] self._operations = []
self._cmd_name = p_subcommand.__module__.lower()[16:-7] self._cmd_name = p_subcommand.name()
self.label = [] self.label = []
def prepare(self, p_args): def prepare(self, p_args):
......
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