Commit 941a8956 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Make padding of IDs dependent of todo list length

When using numerical IDs, the ID width is padded to the log10 of the
todo length.

When using textual IDs, todo lists of 466 items or shorter pad to 3
characters, otherwise 4 characters.
parent f57bbc0c
......@@ -48,7 +48,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list03(self):
......@@ -57,7 +57,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list04(self):
......@@ -66,7 +66,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 3| (C) Baz @Context1 +Project1 key:value\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|3| (C) Baz @Context1 +Project1 key:value\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list05(self):
......@@ -74,7 +74,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|3| (C) Baz @Context1 +Project1 key:value\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n|7| hidden item h:1\n|6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list06(self):
......@@ -92,7 +92,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 3| (C) Baz @Context1 +Project1 key:value\n| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.output, "|3| (C) Baz @Context1 +Project1 key:value\n|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.errors, "")
def test_list08(self):
......@@ -101,7 +101,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list09(self):
......@@ -110,7 +110,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list10(self):
......@@ -119,7 +119,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list11(self):
......@@ -129,7 +129,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
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, "")
def test_list12(self):
......@@ -140,7 +140,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|3| (C) Baz @Context1 +Project1 key:value\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list13(self):
......@@ -149,7 +149,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|3| (C) Baz @Context1 +Project1 key:value\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|7| hidden item h:1\n|6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list14(self):
......@@ -159,7 +159,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, " | 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n | 4| (C) Drink beer @ home\n | 5| (C) 13 + 29 = 42\n | 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, " |1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n |4| (C) Drink beer @ home\n |5| (C) 13 + 29 = 42\n |2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list15(self):
......@@ -167,7 +167,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list16(self):
......@@ -187,7 +187,7 @@ class ListCommandTest(CommandTest):
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output,
"| 3| (C) Baz @Context1 +Project1 key:value\n")
"|3| (C) Baz @Context1 +Project1 key:value\n")
self.assertEqual(self.errors, "")
def test_list18(self):
......@@ -196,7 +196,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "|6| x 2014-12-12 Completed but with date:2014-12-12\n")
def test_list19(self):
""" Force showing all tags. """
......@@ -207,7 +207,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 3| (C) Baz @Context1 +Project1 id:1 key:value\n| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.output, "|3| (C) Baz @Context1 +Project1 id:1 key:value\n|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n")
self.assertEqual(self.errors, "")
def test_list20(self):
......@@ -215,7 +215,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list21(self):
......@@ -224,7 +224,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list22(self):
......@@ -236,7 +236,7 @@ class ListCommandTest(CommandTest):
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, '| 1| Foo.\n')
self.assertEqual(self.output, '|1| Foo.\n')
def test_list31(self):
""" Don't show any todos with -n 0 """
......@@ -251,7 +251,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-n", "1"], self.todolist, self.out, self.error)
command.execute()
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, "")
def test_list33(self):
......@@ -259,7 +259,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-n", "-1"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list34(self):
......@@ -269,7 +269,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-n", "foo"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n")
self.assertEqual(self.errors, "")
def test_list35(self):
......@@ -277,21 +277,21 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-x", "-n", "foo"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n| 7| hidden item h:1\n| 6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|3| (C) Baz @Context1 +Project1 key:value\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n|7| hidden item h:1\n|6| x 2014-12-12 Completed but with date:2014-12-12\n")
self.assertEqual(self.errors, "")
def test_list36(self):
command = ListCommand(["-i", "1"], self.todolist, self.out, self.error)
command.execute()
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, "")
def test_list37(self):
command = ListCommand(["-i", "1,foo,3"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 3| (C) Baz @Context1 +Project1 key:value\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|3| (C) Baz @Context1 +Project1 key:value\n")
self.assertEqual(self.errors, "")
def test_list38(self):
......@@ -316,7 +316,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["(<C)"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
def test_list41(self):
......@@ -331,7 +331,7 @@ class ListCommandTest(CommandTest):
self.out, self.error)
command.execute()
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, "")
@mock.patch('topydo.commands.ListCommand.get_terminal_size')
......@@ -342,7 +342,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-N"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n| 4| (C) Drink beer @ home\n| 5| (C) 13 + 29 = 42\n| 2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.output, "|1| (C) 2015-11-05 Foo @Context2 Not@Context +Project1 Not+Project\n|4| (C) Drink beer @ home\n|5| (C) 13 + 29 = 42\n|2| (D) Bar @Context1 +Project2\n")
self.assertEqual(self.errors, "")
@mock.patch('topydo.commands.ListCommand.get_terminal_size')
......@@ -360,7 +360,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-N"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (A) item 1\n| 27| (A) item 27\n| 2| (B) item 2\n| 28| (B) item 28\n| 3| (C) item 3\n| 29| (C) item 29\n| 4| (D) item 4\n| 30| (D) item 30\n| 5| (E) item 5\n| 31| (E) item 31\n| 6| (F) item 6\n| 32| (F) item 32\n| 7| (G) item 7\n| 33| (G) item 33\n| 8| (H) item 8\n| 34| (H) item 34\n| 9| (I) item 9\n| 35| (I) item 35\n| 10| (J) item 10\n| 36| (J) item 36\n| 11| (K) item 11\n")
self.assertEqual(self.output, "| 1| (A) item 1\n|27| (A) item 27\n| 2| (B) item 2\n|28| (B) item 28\n| 3| (C) item 3\n|29| (C) item 29\n| 4| (D) item 4\n|30| (D) item 30\n| 5| (E) item 5\n|31| (E) item 31\n| 6| (F) item 6\n|32| (F) item 32\n| 7| (G) item 7\n|33| (G) item 33\n| 8| (H) item 8\n|34| (H) item 34\n| 9| (I) item 9\n|35| (I) item 35\n|10| (J) item 10\n|36| (J) item 36\n|11| (K) item 11\n")
self.assertEqual(self.errors, "")
@mock.patch('topydo.commands.ListCommand.get_terminal_size')
......@@ -378,7 +378,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-N"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (A) item 1\n| 27| (A) item 27\n| 2| (B) item 2\n| 28| (B) item 28\n| 3| (C) item 3\n| 29| (C) item 29\n| 4| (D) item 4\n")
self.assertEqual(self.output, "| 1| (A) item 1\n|27| (A) item 27\n| 2| (B) item 2\n|28| (B) item 28\n| 3| (C) item 3\n|29| (C) item 29\n| 4| (D) item 4\n")
self.assertEqual(self.errors, "")
@mock.patch('topydo.commands.ListCommand.get_terminal_size')
......@@ -392,7 +392,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-N"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (A) item 1\n")
self.assertEqual(self.output, "| 1| (A) item 1\n")
self.assertEqual(self.errors, "")
@mock.patch('topydo.commands.ListCommand.get_terminal_size')
......@@ -411,14 +411,14 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-N"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "| 1| (A) item 1\n| 27| (A) item 27\n| 2| (B) item 2\n| 28| (B) item 28\n| 3| (C) item 3\n| 29| (C) item 29\n| 4| (D) item 4\n| 30| (D) item 30\n| 5| (E) item 5\n| 31| (E) item 31\n| 6| (F) item 6\n| 32| (F) item 32\n| 7| (G) item 7\n| 33| (G) item 33\n| 8| (H) item 8\n| 34| (H) item 34\n| 9| (I) item 9\n| 35| (I) item 35\n| 10| (J) item 10\n| 36| (J) item 36\n")
self.assertEqual(self.output, "| 1| (A) item 1\n|27| (A) item 27\n| 2| (B) item 2\n|28| (B) item 28\n| 3| (C) item 3\n|29| (C) item 29\n| 4| (D) item 4\n|30| (D) item 30\n| 5| (E) item 5\n|31| (E) item 31\n| 6| (F) item 6\n|32| (F) item 32\n| 7| (G) item 7\n|33| (G) item 33\n| 8| (H) item 8\n|34| (H) item 34\n| 9| (I) item 9\n|35| (I) item 35\n|10| (J) item 10\n|36| (J) item 36\n")
self.assertEqual(self.errors, "")
def test_list48(self):
command = ListCommand(["created:2015-11-05"], self.todolist, self.out, self.error)
command.execute()
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, "")
def test_list49(self):
......@@ -431,7 +431,7 @@ class ListCommandTest(CommandTest):
command = ListCommand(["-n", "1"], todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, '| 2| This item is visible\n')
self.assertEqual(self.output, '|2| This item is visible\n')
self.assertEqual(self.errors, "")
def test_list_name(self):
......@@ -461,7 +461,7 @@ class ListCommandUnicodeTest(CommandTest):
self.assertFalse(self.todolist.dirty)
expected = u"| 1| (C) And some sp\u00e9cial tag:\u25c4\n"
expected = u"|1| (C) And some sp\u00e9cial tag:\u25c4\n"
self.assertEqual(self.output, expected)
......@@ -584,17 +584,17 @@ class ListCommandGroupTest(CommandTest):
self.assertEqual(self.output, """\
Project: A
==========
| 1| +A only test:test_group1
| 3| +A and +B test:test_group1
| 1| +A only test:test_group1
| 3| +A and +B test:test_group1
Project: B
==========
| 3| +A and +B test:test_group1
| 2| +B only test:test_group1
| 3| +A and +B test:test_group1
| 2| +B only test:test_group1
Project: None
=============
| 4| No project test:test_group1
| 4| No project test:test_group1
""")
def test_group2(self):
......@@ -608,11 +608,11 @@ Project: None
self.assertEqual(self.output, """\
l: 0
====
| 6| Another item l:0 test:test_group2
| 6| Another item l:0 test:test_group2
l: 1
====
| 5| Different item l:1 test:test_group2
| 5| Different item l:1 test:test_group2
""")
def test_group3(self):
......@@ -626,11 +626,11 @@ l: 1
self.assertEqual(self.output, """\
due: today
==========
| 7| Test 1 test:test_group3 due:2016-12-06
| 7| Test 1 test:test_group3 due:2016-12-06
due: in a day
=============
| 8| Test 2 test:test_group3 due:2016-12-07
| 8| Test 2 test:test_group3 due:2016-12-07
""")
def test_group4(self):
......@@ -644,7 +644,7 @@ due: in a day
self.assertEqual(self.output, """\
t: today
========
| 9| Test 1 test:test_group4 test:test_group5 t:2016-12-06
| 9| Test 1 test:test_group4 test:test_group5 t:2016-12-06
""")
def test_group5(self):
......@@ -658,11 +658,11 @@ t: today
self.assertEqual(self.output, """\
t: today
========
| 9| Test 1 test:test_group4 test:test_group5 t:2016-12-06
| 9| Test 1 test:test_group4 test:test_group5 t:2016-12-06
t: in a day
===========
| 10| Test 2 test:test_group4 test:test_group5 t:2016-12-07
|10| Test 2 test:test_group4 test:test_group5 t:2016-12-07
""")
def test_group6(self):
......@@ -676,7 +676,7 @@ t: in a day
self.assertEqual(self.output, """\
fake: No value
==============
| 11| Group by non-existing tag test:test_group6
|11| Group by non-existing tag test:test_group6
""")
def test_group7(self):
......@@ -690,11 +690,11 @@ fake: No value
self.assertEqual(self.output, """\
Project: B
==========
| 13| Sort descending +B test:test_group7
|13| Sort descending +B test:test_group7
Project: A
==========
| 12| Sort descending +A test:test_group7
|12| Sort descending +A test:test_group7
""")
def test_group8(self):
......@@ -708,19 +708,19 @@ Project: A
self.assertEqual(self.output, """\
Project: A, Context: B
======================
| 15| Inner sort 2 +A @B test:test_group8
|15| Inner sort 2 +A @B test:test_group8
Project: A, Context: A
======================
| 14| Inner sort 1 +A @A test:test_group8
|14| Inner sort 1 +A @A test:test_group8
Project: B, Context: B
======================
| 17| Inner sort 4 +B @B test:test_group8
|17| Inner sort 4 +B @B test:test_group8
Project: B, Context: A
======================
| 16| Inner sort 3 +B @A test:test_group8
|16| Inner sort 3 +B @A test:test_group8
""")
def test_group9(self):
......@@ -734,8 +734,8 @@ Project: B, Context: A
self.assertEqual(self.output, """\
Project: A
==========
| 19| Inner sort 2 +A test:test_group9
| 18| Inner sort 1 +A test:test_group9
|19| Inner sort 2 +A test:test_group9
|18| Inner sort 1 +A test:test_group9
""")
def test_group10(self):
......@@ -761,17 +761,17 @@ Project: A
self.assertEqual(self.output, """\
Project: A
==========
| 1| +A only test:test_group1
| 3| +A and +B test:test_group1
| 1| +A only test:test_group1
| 3| +A and +B test:test_group1
Project: B
==========
| 3| +A and +B test:test_group1
| 2| +B only test:test_group1
| 3| +A and +B test:test_group1
| 2| +B only test:test_group1
Project: None
=============
| 4| No project test:test_group1
| 4| No project test:test_group1
""")
self.assertEqual(self.errors, "")
......@@ -784,10 +784,10 @@ Project: None
self.assertFalse(todolist.dirty)
self.assertEqual(self.output, """\
| 1| +A only test:test_group1
| 2| +B only test:test_group1
| 3| +A and +B test:test_group1
| 4| No project test:test_group1
| 1| +A only test:test_group1
| 2| +B only test:test_group1
| 3| +A and +B test:test_group1
| 4| No project test:test_group1
""")
self.assertEqual(self.errors, "")
......
......@@ -37,6 +37,7 @@ except ImportError:
class ListFormatTest(CommandTest):
def setUp(self):
super().setUp()
self.maxDiff = None
self.todolist = load_file_to_todolist("test/data/ListFormat.txt")
self.terminal_size = namedtuple('terminal_size', ['columns', 'lines'])
......@@ -45,12 +46,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +jumped over the and jar due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +jumped over the and jar due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -62,12 +63,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolore... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem ... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -79,12 +80,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -96,12 +97,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -113,12 +114,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolore... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem ... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -131,12 +132,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| D Bar @Context1 +Project2 (3 months ago, due a month ago, started a month ago)
| 2| Z Lorem ipsum dolorem sit amet. Red @fox ... lazy:bar (today, due in 2 days, starts in a day)
| 3| C Foo @Context2 Not@Context +Project1 Not+Project (4 months ago)
| 4| C Baz @Context1 +Project1 key:value
| 5| Drink beer @ home
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| D Bar @Context1 +Project2 (3 months ago, due a month ago, started a month ago)
|2| Z Lorem ipsum dolorem sit amet. Red @fox +j... lazy:bar (today, due in 2 days, starts in a day)
|3| C Foo @Context2 Not@Context +Project1 Not+Project (4 months ago)
|4| C Baz @Context1 +Project1 key:value
|5| Drink beer @ home
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -148,12 +149,12 @@ class ListFormatTest(CommandTest):
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| D Bar @Context1 +Project2 (due a month ago, started a month ago)
| 2| Z Lorem ipsum dolorem sit amet. Red @fox +jumped... lazy:bar (due in 2 days, starts in a day)
| 3| C Foo @Context2 Not@Context +Project1 Not+Project
| 4| C Baz @Context1 +Project1 key:value
| 5| Drink beer @ home
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| D Bar @Context1 +Project2 (due a month ago, started a month ago)
|2| Z Lorem ipsum dolorem sit amet. Red @fox +jumped o... lazy:bar (due in 2 days, starts in a day)
|3| C Foo @Context2 Not@Context +Project1 Not+Project
|4| C Baz @Context1 +Project1 key:value
|5| Drink beer @ home
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -210,12 +211,12 @@ today | in 2 days | in a day |
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| due:2015-09-30 t:2015-09-29
| 2| due:2015-11-08 lazy:bar t:2015-11-07
| 3|
| 4| key:value
| 5| ical:foobar id:1 p:2
| 6| date:2014-12-12
result = """|1| due:2015-09-30 t:2015-09-29
|2| due:2015-11-08 lazy:bar t:2015-11-07
|3|
|4| key:value
|5| ical:foobar id:1 p:2
|6| date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -224,12 +225,12 @@ today | in 2 days | in a day |
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| %
| 2| %
| 3| %
| 4| %
| 5| %
| 6| %
result = """|1| %
|2| %
|3| %
|4| %
|5| %
|6| %
"""
self.assertEqual(self.output, result)
......@@ -238,12 +239,12 @@ today | in 2 days | in a day |
self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +jumped over the and jar due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +jumped over the and jar due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -254,8 +255,8 @@ today | in 2 days | in a day |
self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 4| (C) Baz @Context1 +Project1 key:value
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|4| (C) Baz @Context1 +Project1 key:value
"""
self.assertEqual(self.output, result)
......@@ -355,12 +356,12 @@ today, due in 2 days, starts in a day
command = ListCommand(["-x", "-F", "%I"], self.todolist, self.out, self.error)
command.execute()
result = """ 1
2
3
4
5
6
result = """1
2
3
4
5
6
"""
self.assertEqual(self.output, result)
......@@ -610,12 +611,12 @@ Z Z
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -626,12 +627,12 @@ Z Z
command = ListCommand(["-x", "-F", "|%I| %x %{(}p{)} %c %S\\t%K"], self.todolist, self.out, self.error)
command.execute()
result = """| 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """|1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fox +... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -643,12 +644,12 @@ Z Z
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = """ | 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = """ |1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
|2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @fo... due:2015-11-08 lazy:bar t:2015-11-07
|3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
|4| (C) Baz @Context1 +Project1 key:value
|5| Drink beer @ home ical:foobar id:1 p:2
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -681,19 +682,18 @@ C -
@mock.patch('topydo.lib.ListFormat.get_terminal_size')
def test_list_format45(self, mock_terminal_size):
""" Colorblocks should not affect truncating or right_alignment. """
self.maxDiff = None
mock_terminal_size.return_value = self.terminal_size(100, 25)
config(p_overrides={('ls', 'list_format'): '%z|%I| %x %p %S %k\\t%{(}h{)}'})
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = u""" | 1| D Bar @Context1 +Project2 (due a month ago, started a month ago)
| 2| Z Lorem ipsum dolorem sit amet. Red @fox +jumpe... lazy:bar (due in 2 days, starts in a day)
| 3| C Foo @Context2 Not@Context +Project1 Not+Project
| 4| C Baz @Context1 +Project1 key:value
| 5| Drink beer @ home
| 6| x 2014-12-12 Completed but with date:2014-12-12
result = u""" |1| D Bar @Context1 +Project2 (due a month ago, started a month ago)
|2| Z Lorem ipsum dolorem sit amet. Red @fox +jumped ... lazy:bar (due in 2 days, starts in a day)
|3| C Foo @Context2 Not@Context +Project1 Not+Project
|4| C Baz @Context1 +Project1 key:value
|5| Drink beer @ home
|6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......@@ -733,21 +733,6 @@ x 2014-12-12 Completed but with date:2014-12-12
self.assertEqual(self.output, result)
self.assertEqual(self.errors, "")
def test_list_format49(self):
"""
Test padded line numbers
"""
command = ListCommand(["-F %N"], self.todolist, self.out, self.error)
command.execute()
result = """ 1
3
4
5
"""
self.assertEqual(self.output, result)
self.assertEqual(self.errors, "")
def test_list_format50(self):
"""
Test line numbers
......
......@@ -162,9 +162,9 @@ class ListFormatParser(object):
# todo ID
'i': lambda t: str(self.todolist.number(t)),
# todo ID pre-filled with 1 or 2 spaces if its length is <3
'I': lambda t: _filler(str(self.todolist.number(t)), 3),
# todo ID, padded with spaces
'I': lambda t: _filler(str(self.todolist.number(t)),
self.todolist.max_id_length()),
# list of tags (spaces) without hidden ones and due: and t:
'k': lambda t: ' '.join([u'{}:{}'.format(tag, value)
......@@ -179,8 +179,9 @@ class ListFormatParser(object):
# line number
'n': lambda t: str(self.todolist.linenumber(t)),
# line number, pre-filled with 1 or 2 spaces if its length <3
'N': lambda t: _filler(str(self.todolist.linenumber(t)), 3),
# line number, padded with spaces
'N': lambda t: _filler(str(self.todolist.linenumber(t)),
self.todolist.max_id_length()),
# priority
'p': lambda t: t.priority() if t.priority() else '',
......@@ -206,8 +207,9 @@ class ListFormatParser(object):
# unique text ID
'u': lambda t: self.todolist.uid(t),
# unique text ID, pre-filled with 1 or 2 spaces if its length <3
'U': lambda t: _filler(self.todolist.uid(t), 3),
# unique text ID, padded with spaces
'U': lambda t: _filler(self.todolist.uid(t),
self.todolist.max_id_length()),
# absolute completion date
'x': lambda t: 'x ' + t.completion_date().isoformat() if t.is_completed() else '',
......
......@@ -18,12 +18,13 @@
A list of todo items.
"""
import math
import re
from datetime import date
from topydo.lib import Filter
from topydo.lib.Config import config
from topydo.lib.HashListValues import hash_list_values
from topydo.lib.HashListValues import hash_list_values, max_id_length
from topydo.lib.printers.PrettyPrinter import PrettyPrinter
from topydo.lib.Todo import Todo
from topydo.lib.View import View
......@@ -275,6 +276,19 @@ class TodoListBase(object):
else:
return self.linenumber(p_todo)
def max_id_length(self):
"""
Returns the maximum length of a todo ID, used for formatting purposes.
"""
if config().identifiers() == "text":
return max_id_length(len(self._todos))
else:
try:
return math.ceil(math.log(len(self._todos), 10))
except ValueError:
return 0
def _update_todo_ids(self):
# the idea is to have a hash that is independent of the position of the
# todo. Use the text (without tags) of the todo to keep the id as
......
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