Commit 355332f5 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Replace old-style string formatting with the new style.

parent 1012c07d
......@@ -168,7 +168,7 @@ class AddCommandTest(CommandTest.CommandTest):
command = AddCommand.AddCommand(["Foo t:today due:today"], self.todolist, self.out, self.error)
command.execute()
result = "| 1| %s Foo t:%s due:%s\n" % (self.today, self.today, self.today)
result = "| 1| {} Foo t:{} due:{}\n".format(self.today, self.today, self.today)
self.assertEquals(self.output, result)
self.assertEquals(self.errors, "")
......
......@@ -52,14 +52,15 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(3).is_completed())
self.assertEquals(self.output, "Completed: x %s Baz p:1\n" % self.today)
self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(
self.today))
self.assertEquals(self.errors, "")
def test_do_subtasks1(self):
command = DoCommand(["1"], self.todolist, self.out, self.error, _yes_prompt)
command.execute()
result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x %s Bar p:1\nCompleted: x %s Baz p:1\nCompleted: x %s Foo id:1\n" % (self.today, self.today, self.today)
result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {today} Bar p:1\nCompleted: x {today} Baz p:1\nCompleted: x {today} Foo id:1\n".format(today=self.today)
for number in [1, 2, 3]:
self.assertTrue(self.todolist.todo(number).is_completed())
......@@ -73,7 +74,7 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand(["1"], self.todolist, self.out, self.error, _no_prompt)
command.execute()
result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x %s Foo id:1\n" % self.today
result = "| 2| Bar p:1\n| 3| Baz p:1\nCompleted: x {} Foo id:1\n".format(self.today)
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).is_completed())
......@@ -124,7 +125,7 @@ class DoCommandTest(CommandTest.CommandTest):
self._recurrence_helper(["4"])
self.assertTrue(self.todolist.todo(4).is_completed())
result = "| 9| %s Recurring! rec:1d due:%s\nCompleted: x %s Recurring! rec:1d\n" % (self.today, self.tomorrow, self.today)
result = "| 9| {today} Recurring! rec:1d due:{tomorrow}\nCompleted: x {today} Recurring! rec:1d\n".format(today=self.today, tomorrow=self.tomorrow)
self.assertEquals(self.output, result)
todo = self.todolist.todo(8)
......@@ -133,13 +134,13 @@ class DoCommandTest(CommandTest.CommandTest):
def test_strict_recurrence1(self):
self._recurrence_helper(["-s", "8"])
result = "| 9| %s Strict due:2014-01-02 rec:1d\nCompleted: x %s Strict due:2014-01-01 rec:1d\n" % (self.today, self.today)
result = "| 9| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format(today=self.today)
self.assertEquals(self.output, result)
def test_strict_recurrence2(self):
self._recurrence_helper(["--strict", "8"])
result = "| 9| %s Strict due:2014-01-02 rec:1d\nCompleted: x %s Strict due:2014-01-01 rec:1d\n" % (self.today, self.today)
result = "| 9| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {today} Strict due:2014-01-01 rec:1d\n".format(today=self.today)
self.assertEquals(self.output, result)
def test_invalid1(self):
......@@ -170,7 +171,7 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand(["2"], self.todolist, self.out, self.error)
command.execute()
first_output = "Completed: x %s Bar p:1\n" % self.today
first_output = "Completed: x {} Bar p:1\n".format(self.today)
self.assertEquals(self.output, first_output)
self.assertEquals(self.errors, "")
......@@ -178,14 +179,14 @@ class DoCommandTest(CommandTest.CommandTest):
command = DoCommand(["3"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, first_output + "Completed: x %s Baz p:1\nThe following todo item(s) became active:\n| 1| Foo id:1\n" % self.today)
self.assertEquals(self.output, first_output + "Completed: x {} Baz p:1\nThe following todo item(s) became active:\n| 1| Foo id:1\n".format(self.today))
self.assertEquals(self.errors, "")
def test_activated_todos2(self):
command = DoCommand(["7"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "Completed: x %s Subtodo of inactive p:2\n" % self.today)
self.assertEquals(self.output, "Completed: x {} Subtodo of inactive p:2\n".format(self.today))
self.assertEquals(self.errors, "")
def test_already_complete(self):
......@@ -203,7 +204,7 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(3).is_completed())
self.assertEquals(self.output, "Completed: x %s Baz p:1\n" % self.today)
self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today))
self.assertEquals(self.errors, "")
def test_do_custom_date1(self):
......@@ -235,7 +236,7 @@ class DoCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Completed: x %s Baz p:1\n" % self.today)
self.assertEquals(self.output, "Completed: x {} Baz p:1\n".format(self.today))
self.assertEquals(self.errors, "")
def test_empty(self):
......
......@@ -312,11 +312,16 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
self.today = today.isoformat()
self.tomorrow = tomorrow.isoformat()
self.todo1 = "Foo due:{}".format(self.today)
self.todo2 = "Bar due:{}".format(self.tomorrow)
self.todo3 = "Baz due:nonsense"
self.todo4 = "Fnord due:2014-10-32"
self.todos = [
Todo("Foo due:%s" % self.today),
Todo("Bar due:%s" % self.tomorrow),
Todo("Baz due:nonsense"),
Todo("Fnord due:2014-10-32")
Todo(self.todo1),
Todo(self.todo2),
Todo(self.todo3),
Todo(self.todo4),
]
def test_filter1(self):
......@@ -325,7 +330,7 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
result = otf.filter(self.todos)
self.assertEquals(len(result), 1)
self.assertEquals(str(result[0]), "Foo due:%s" % self.today)
self.assertEquals(str(result[0]), self.todo1)
def test_filter2(self):
otf = Filter.OrdinalTagFilter('due:=today')
......@@ -333,7 +338,7 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
result = otf.filter(self.todos)
self.assertEquals(len(result), 1)
self.assertEquals(str(result[0]), "Foo due:%s" % self.today)
self.assertEquals(str(result[0]), self.todo1)
def test_filter3(self):
otf = Filter.OrdinalTagFilter('due:>today')
......@@ -341,7 +346,7 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
result = otf.filter(self.todos)
self.assertEquals(len(result), 1)
self.assertEquals(str(result[0]), "Bar due:%s" % self.tomorrow)
self.assertEquals(str(result[0]), self.todo2)
def test_filter4(self):
otf = Filter.OrdinalTagFilter('due:<1w')
......@@ -349,8 +354,8 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
result = otf.filter(self.todos)
self.assertEquals(len(result), 2)
self.assertEquals(str(result[0]), "Foo due:%s" % self.today)
self.assertEquals(str(result[1]), "Bar due:%s" % self.tomorrow)
self.assertEquals(str(result[0]), self.todo1)
self.assertEquals(str(result[1]), self.todo2)
def test_filter5(self):
otf = Filter.OrdinalTagFilter('due:!today')
......@@ -358,7 +363,7 @@ class OrdinalTagFilterTest(TopydoTest.TopydoTest):
result = otf.filter(self.todos)
self.assertEquals(len(result), 1)
self.assertEquals(str(result[0]), "Bar due:%s" % self.tomorrow)
self.assertEquals(str(result[0]), self.todo2)
if __name__ == '__main__':
unittest.main()
......
......@@ -31,10 +31,10 @@ class PostponeCommandTest(CommandTest.CommandTest):
todos = [
"Foo",
"Bar due:%s" % self.today.isoformat(),
"Baz due:%s t:%s" % (self.today.isoformat(), self.start.isoformat()),
"Past due:%s" % self.past.isoformat(),
"Future due:%s t:%s" % (self.future.isoformat(), self.future_start.isoformat()),
"Bar due:{}".format(self.today.isoformat()),
"Baz due:{} t:{}".format(self.today.isoformat(), self.start.isoformat()),
"Past due:{}".format(self.past.isoformat()),
"Future due:{} t:{}".format(self.future.isoformat(), self.future_start.isoformat()),
]
self.todolist = TodoList(todos)
......@@ -46,7 +46,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 1| Foo due:%s\n" % due.isoformat())
self.assertEquals(self.output, "| 1| Foo due:{}\n".format(due.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone2(self):
......@@ -56,7 +56,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 2| Bar due:%s\n" % due.isoformat())
self.assertEquals(self.output, "| 2| Bar due:{}\n".format(due.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone3(self):
......@@ -66,7 +66,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 2| Bar due:%s\n" % due.isoformat())
self.assertEquals(self.output, "| 2| Bar due:{}\n".format(due.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone4(self):
......@@ -76,7 +76,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 3| Baz due:%s t:%s\n" % (due.isoformat(), self.start.isoformat()))
self.assertEquals(self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), self.start.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone5(self):
......@@ -87,7 +87,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
start = self.start + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 3| Baz due:%s t:%s\n" % (due.isoformat(), start.isoformat()))
self.assertEquals(self.output, "| 3| Baz due:{} t:{}\n".format(due.isoformat(), start.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone6(self):
......@@ -97,7 +97,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 4| Past due:%s\n" % due.isoformat())
self.assertEquals(self.output, "| 4| Past due:{}\n".format(due.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone7(self):
......@@ -107,7 +107,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.future + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 5| Future due:%s t:%s\n" % (due.isoformat(), self.future_start.isoformat()))
self.assertEquals(self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), self.future_start.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone8(self):
......@@ -118,7 +118,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
start = self.future_start + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 5| Future due:%s t:%s\n" % (due.isoformat(), start.isoformat()))
self.assertEquals(self.output, "| 5| Future due:{} t:{}\n".format(due.isoformat(), start.isoformat()))
self.assertEquals(self.errors, "")
def test_postpone9(self):
......@@ -160,7 +160,7 @@ class PostponeCommandTest(CommandTest.CommandTest):
due = self.today + timedelta(7)
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "| 1| Foo due:%s\n" % due.isoformat())
self.assertEquals(self.output, "| 1| Foo due:{}\n".format(due.isoformat()))
self.assertEquals(self.errors, "")
def test_help(self):
......
......@@ -293,7 +293,7 @@ class TodoBaseTester(TopydoTest.TopydoTest):
yesterday = date.today() - timedelta(1)
todo.set_completed(yesterday)
self.assertEquals(todo.src, "x %s Foo" % yesterday.isoformat())
self.assertEquals(todo.src, "x {} Foo".format(yesterday.isoformat()))
def test_set_source_text(self):
todo = TodoBase("(B) Foo")
......
......@@ -52,7 +52,7 @@ def error(p_string):
def version():
""" Print the current version and exit. """
from topydo.lib.Version import VERSION, LICENSE
print "topydo %s\n" % (VERSION)
print "topydo {}\n".format(VERSION)
print LICENSE
exit(0)
......
......@@ -199,14 +199,14 @@ class DirectedGraph(object):
out = 'digraph g {\n'
for from_node, neighbors in self._edges.iteritems():
out += " %s\n" % from_node
out += " {}\n".format(from_node)
for neighbor in neighbors:
out += " %s -> %s" % (from_node, neighbor)
out += " {} -> {}".format(from_node, neighbor)
edge_id = self.edge_id(from_node, neighbor)
if edge_id and p_print_labels:
out += ' [label="%s"]' % edge_id
out += ' [label="{}"]'.format(edge_id)
out += "\n"
......
......@@ -43,7 +43,7 @@ def pp_color(p_todo_str, p_todo):
except KeyError:
pass
p_todo_str = '%s%s%s' % (color, p_todo_str, NEUTRAL_COLOR)
p_todo_str = color + p_todo_str + NEUTRAL_COLOR
if config().highlight_projects_contexts():
p_todo_str = re.sub(
......
......@@ -43,9 +43,10 @@ class PriorityCommand(Command):
self.todolist.set_priority(todo, priority)
if old_priority and priority and old_priority != priority:
self.out("Priority changed from %s to %s" % (old_priority, priority))
self.out("Priority changed from {} to {}".format(
old_priority, priority))
elif not old_priority:
self.out("Priority set to %s." % priority)
self.out("Priority set to {}.".format(priority))
self.out(pretty_print(todo))
else:
......
......@@ -70,7 +70,7 @@ class TagCommand(Command):
if not self.force:
for i, value in enumerate(self.current_values):
self.out("%2d. %s" % (i + 1, value))
self.out("{:>2d}. {}".format(i + 1, value))
answer = self.prompt(
'Which value to remove? Enter number or "all": ')
......
......@@ -209,9 +209,9 @@ class TodoBase(object):
# http://bugs.python.org/issue1519638 non-existent matches trigger
# exceptions, hence the lambda
self.src = re.sub(
r'^(x \d{4}-\d{2}-\d{2} |\([A-Z]\) )?(\d{4}-\d{2}-\d{2} )?(.*)$', \
r'^(x \d{4}-\d{2}-\d{2} |\([A-Z]\) )?(\d{4}-\d{2}-\d{2} )?(.*)$',
lambda m: \
"%s%s %s" % (m.group(1) or '', p_date.isoformat(), m.group(3)), \
"{}{} {}".format(m.group(1) or '', p_date.isoformat(), m.group(3)),
self.src)
def creation_date(self):
......
......@@ -111,10 +111,10 @@ class TodoList(TodoListBase):
"""
new_id = 1
while self._depgraph.has_edge_id('%d' % new_id):
while self._depgraph.has_edge_id(str(new_id)):
new_id += 1
return '%d' % new_id
return str(new_id)
if p_from_todo != p_to_todo and not self._depgraph.has_edge(hash(p_from_todo), hash(p_to_todo)):
dep_id = None
......
......@@ -236,10 +236,10 @@ class TodoListBase(object):
"""
if config().identifiers() == 'text':
return lambda p_todo_str, p_todo: \
"|%3s| %s" % (self._todo_id_map[p_todo], p_todo_str)
"|{:>3s}| {}".format(self._todo_id_map[p_todo], p_todo_str)
else:
return lambda p_todo_str, p_todo: \
"|%3d| %s" % (self.number(p_todo), p_todo_str)
"|{:>3}| {}".format(self.number(p_todo), p_todo_str)
def _update_todo_ids(self):
# the idea is to have a hash that is independent of the position of the
......
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