def test_projects2(self): todolist = load_file_to_todolist("test/data/TodoListTest.txt") command = ListProjectCommand(["aaa"], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "Project1\nProject2\n") self.assertFalse(self.errors)
def test_group11(self): config(p_overrides={('sort', 'group_string'): 'project'}) todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["test:test_group1"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: A ========== | 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 Project: None ============= | 4| No project test:test_group1 """) self.assertEqual(self.errors, "")
def test_contexts2(self): todolist = load_file_to_todolist("test/data/TodoListTest.txt") command = ListContextCommand(["aaa"], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "Context1\nContext2\n") self.assertFalse(self.errors)
def test_contexts1(self): todolist = load_file_to_todolist("test/data/TodoListTest.txt") command = ListContextCommand([""], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "Context1\nContext2\n") self.assertFalse(self.errors)
def test_group8(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "project,desc:context", "test_group8"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: A, Context: B ====================== |15| Inner sort 2 +A @B test:test_group8 Project: A, Context: A ====================== |14| Inner sort 1 +A @A test:test_group8 Project: B, Context: B ====================== |17| Inner sort 4 +B @B test:test_group8 Project: B, Context: A ====================== |16| Inner sort 3 +B @A test:test_group8 """)
def test_group8(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "project,desc:context", "test_group8"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: A, Context: B ====================== | 15| Inner sort 2 +A @B test:test_group8 Project: A, Context: A ====================== | 14| Inner sort 1 +A @A test:test_group8 Project: B, Context: B ====================== | 17| Inner sort 4 +B @B test:test_group8 Project: B, Context: A ====================== | 16| Inner sort 3 +B @A test:test_group8 """)
def test_sort14(self): sorter = Sorter('desc:importance-average') todolist = load_file_to_todolist('test/data/SorterTest10.txt') view = todolist.view(sorter, []) result = load_file('test/data/SorterTest10-result.txt') self.assertEqual(print_view(view), todolist_to_string(result))
def test_projects2(self): todolist = load_file_to_todolist("test/data/TodoListTest.txt") command = ListProjectCommand(["aaa"], todolist, self.out, self.error) command.execute() command.execute_post_archive_actions() self.assertEqual(self.output, "Project1\nProject2\n") self.assertFalse(self.errors)
def test_projects1(self): todolist = load_file_to_todolist("test/data/TodoListTest.txt") command = ListProjectCommand([""], todolist, self.out, self.error) command.execute() command.execute_post_archive_actions() # test default implementation of post_archive self.assertEqual(self.output, "Project1\nProject2\n") self.assertFalse(self.errors)
def test_list22(self): """ Handle tag lists with spaces and punctuation.""" config(p_overrides={("ls", "hide_tags"): "p, id"}) self.todolist = load_file_to_todolist("test/data/ListCommandTagTest.txt") command = ListCommand(["-x"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.dirty) self.assertEqual(self.output, "| 1| Foo.\n")
def test_list22(self): """ Handle tag lists with spaces and punctuation.""" config(p_overrides={('ls', 'hide_tags'): 'p, id'}) self.todolist = load_file_to_todolist('test/data/ListCommandTagTest.txt') command = ListCommand(["-x"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.is_dirty()) self.assertEqual(self.output, '| 1| Foo.\n')
def test_filter07(self): """ Tests the dependency filter. """ todolist = load_file_to_todolist('test/data/FilterTest2.txt') depfilter = Filter.DependencyFilter(todolist) filtered_todos = depfilter.filter(todolist.todos()) reference = load_file('test/data/FilterTest2-result.txt') self.assertEqual(todolist_to_string(filtered_todos), todolist_to_string(reference))
def test_group10(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, "") self.assertEqual(self.errors, "option -g requires argument\n")
def test_list22(self): """ Handle tag lists with spaces and punctuation.""" config(p_overrides={('ls', 'hide_tags'): 'p, id'}) self.todolist = load_file_to_todolist('test/data/ListCommandTagTest.txt') command = ListCommand(["-x"], self.todolist, self.out, self.error) command.execute() self.assertFalse(self.todolist.dirty) self.assertEqual(self.output, '|1| Foo.\n')
def test_sort16(self): """ Check sort of low priority tasks (D or lower) with non-priority tasks. """ sorter = Sorter('desc:importance,desc:prio') todolist = load_file_to_todolist('test/data/SorterTest12.txt') view = todolist.view(sorter, []) result = load_file('test/data/SorterTest12-result.txt') self.assertEqual(print_view(view), todolist_to_string(result))
def test_list46(self, mock_terminal_size): """Test basic 'N' parameter with zero height terminal.""" # we still print at least 1 item mock_terminal_size.return_value = self.terminal_size(100, 0) self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") command = ListCommand(["-N"], self.todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "| 1| (A) item 1\n") self.assertEqual(self.errors, "")
def test_archive(self): todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt") archive = TodoList([]) command = ArchiveCommand(todolist, archive) command.execute() self.assertTrue(todolist.is_dirty()) self.assertTrue(archive.is_dirty()) self.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active") self.assertEqual(archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
def test_sort15(self): """ Test that own importance is used when average turns out to be lower. """ sorter = Sorter('desc:importance-average') todolist = load_file_to_todolist('test/data/SorterTest11.txt') view = todolist.view(sorter, []) result = load_file('test/data/SorterTest11-result.txt') self.assertEqual(print_view(view), todolist_to_string(result))
def test_list51(self): """ Test hexadecimal IDs """ config(p_overrides={('topydo', 'identifier_alphabet'): '0123456789abcdef', ('topydo', 'identifiers'): 'text'}) # self.todolist was loaded with old identifier settings todolist = load_file_to_todolist("test/data/ListCommandTest.txt") command = ListCommand(["-F", "%i", "Foo"], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, '2c8\n') self.assertEqual(self.errors, '')
def test_list44(self, mock_terminal_size): """ Test 'N' parameter with output longer than available terminal lines. """ self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") mock_terminal_size.return_value = self.terminal_size(80, 23) 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.errors, "")
def test_list45(self, mock_terminal_size): """Test basic 'N' parameter with nine line terminal.""" # have 9 lines on the terminal will print 7 items and leave 2 lines # for the next prompt mock_terminal_size.return_value = self.terminal_size(100, 9) self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") 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.errors, "")
def test_list52(self): """ Alphabet is too short due to duplicate characters """ config(p_overrides={('topydo', 'identifier_alphabet'): '0123456788', ('topydo', 'identifiers'): 'text'}) # self.todolist was loaded with old identifier settings todolist = load_file_to_todolist("test/data/ListCommandTest.txt") command = ListCommand(["-F", "%i", "Foo"], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, 't5c\n') self.assertEqual(self.errors, '')
def test_group6(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "fake", "test_group6"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ fake: No value ============== | 11| Group by non-existing tag test:test_group6 """)
def test_group4(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-g", "t", "test:test_group4"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ t: today ======== | 9| Test 1 test:test_group4 test:test_group5 t:2016-12-06 """)
def test_archive(self): todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt") archive = TodoList([]) command = ArchiveCommand(todolist, archive) command.execute() self.assertTrue(todolist.dirty) self.assertTrue(archive.dirty) self.assertEqual(todolist.print_todos(), "x Not complete\n(C) Active") self.assertEqual( archive.print_todos(), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
def test_group6(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "fake", "test_group6"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ fake: No value ============== |11| Group by non-existing tag test:test_group6 """)
def test_json_unicode(self): todolist = load_file_to_todolist("test/data/ListCommandUnicodeTest.txt") command = ListCommand(["-f", "json"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) jsontext = "" with codecs.open("test/data/ListCommandUnicodeTest.json", "r", encoding="utf-8") as json: jsontext = json.read() self.assertEqual(self.output, jsontext) self.assertEqual(self.errors, "")
def test_group9(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "project", "-s", "desc:text", "test_group9"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: A ========== | 19| Inner sort 2 +A test:test_group9 | 18| Inner sort 1 +A test:test_group9 """)
def test_group9(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "project", "-s", "desc:text", "test_group9"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: A ========== |19| Inner sort 2 +A test:test_group9 |18| Inner sort 1 +A test:test_group9 """)
def test_ical_unicode(self): todolist = load_file_to_todolist("test/data/ListCommandUnicodeTest.txt") command = ListCommand(["-f", "ical"], todolist, self.out, self.error) command.execute() self.assertTrue(todolist.dirty) icaltext = "" with codecs.open("test/data/ListCommandUnicodeTest.ics", "r", encoding="utf-8") as ical: icaltext = ical.read() self.assertEqual(replace_ical_tags(self.output), replace_ical_tags(icaltext)) self.assertEqual(self.errors, "")
def test_list47(self, mock_terminal_size): """ Test 'N' parameter with multiline prompt. """ self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") if "win32" in sys.platform: mock_terminal_size.return_value = self.terminal_size(80, 23) else: mock_terminal_size.return_value = self.terminal_size(80, 22) 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.errors, "")
def test_list45(self, mock_terminal_size): """Test basic 'N' parameter with nine line terminal.""" # have 9 lines on the terminal will print 7 items and leave 2 lines # for the next prompt if "win32" in sys.platform: mock_terminal_size.return_value = self.terminal_size(100, 9) else: mock_terminal_size.return_value = self.terminal_size(100, 8) self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") 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.errors, "")
def test_group12(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-g", ",", "test:test_group1"], todolist, self.out, self.error) command.execute() 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 """) self.assertEqual(self.errors, "")
def test_json(self): todolist = load_file_to_todolist("test/data/ListCommandTest.txt") command = ListCommand(["-f", "json"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.is_dirty()) jsontext = "" with codecs.open('test/data/ListCommandTest.json', 'r', encoding='utf-8') as json: jsontext = json.read() self.assertEqual(self.output, jsontext) self.assertEqual(self.errors, "")
def test_list50(self): """ Fallback to normal alphabet for too short alphabets, fallback on default alphabet. """ config(p_overrides={('topydo', 'identifier_alphabet'): 'a', ('topydo', 'identifiers'): 'text'}) # self.todolist was loaded with old identifier settings todolist = load_file_to_todolist("test/data/ListCommandTest.txt") command = ListCommand(["-F", "%I", "Foo"], todolist, self.out, self.error) command.execute() self.assertEqual(self.output, "t5c\n") self.assertEqual(self.errors, '')
def test_list47(self, mock_terminal_size): """ Test 'N' parameter with multiline prompt. """ self.todolist = load_file_to_todolist("test/data/ListCommand_50_items.txt") if "win32" in sys.platform: mock_terminal_size.return_value = self.terminal_size(80, 23) else: mock_terminal_size.return_value = self.terminal_size(80, 22) 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.errors, "")
def test_json_unicode(self): todolist = load_file_to_todolist("test/data/ListCommandUnicodeTest.txt") command = ListCommand(["-f", "json"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) jsontext = "" with codecs.open('test/data/ListCommandUnicodeTest.json', 'r', encoding='utf-8') as json: jsontext = json.read() self.assertEqual(self.output, jsontext) self.assertEqual(self.errors, "")
def test_dot(self): todolist = load_file_to_todolist("test/data/ListCommandDotTest.txt") command = ListCommand(["-x", "-f", "dot"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) dottext = "" with codecs.open('test/data/ListCommandTest.dot', 'r', encoding='utf-8') as dot: dottext = dot.read() self.assertEqual(self.output, dottext) self.assertEqual(self.errors, "")
def test_ical_unicode(self): todolist = load_file_to_todolist("test/data/ListCommandUnicodeTest.txt") command = ListCommand(["-f", "ical"], todolist, self.out, self.error) command.execute() self.assertTrue(todolist.dirty) icaltext = "" with codecs.open('test/data/ListCommandUnicodeTest.ics', 'r', encoding='utf-8') as ical: icaltext = ical.read() self.assertEqual(replace_ical_tags(self.output), replace_ical_tags(icaltext)) self.assertEqual(self.errors, "")
def test_group7(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "desc:project", "test_group7"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: B ========== |13| Sort descending +B test:test_group7 Project: A ========== |12| Sort descending +A test:test_group7 """)
def test_ical(self): todolist = load_file_to_todolist("test/data/ListCommandIcalTest.txt") command = ListCommand(["-x", "-f", "ical"], todolist, self.out, self.error) command.execute() self.assertTrue(todolist.is_dirty()) icaltext = "" with codecs.open('test/data/ListCommandTest.ics', 'r', encoding='utf-8') as ical: icaltext = ical.read() self.assertEqual(replace_ical_tags(self.output), replace_ical_tags(icaltext)) self.assertEqual(self.errors, "")
def test_group7(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-x", "-g", "desc:project", "test_group7"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ Project: B ========== | 13| Sort descending +B test:test_group7 Project: A ========== | 12| Sort descending +A test:test_group7 """)
def test_group3(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-g", "due", "test:test_group3"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ due: today ========== | 7| Test 1 test:test_group3 due:2016-12-06 due: in a day ============= | 8| Test 2 test:test_group3 due:2016-12-07 """)
def test_group2(self): todolist = load_file_to_todolist("test/data/ListCommandGroupTest.txt") command = ListCommand(["-g", "l", "test:test_group2"], todolist, self.out, self.error) command.execute() self.assertFalse(todolist.dirty) self.assertEqual(self.output, """\ l: 0 ==== | 6| Another item l:0 test:test_group2 l: 1 ==== | 5| Different item l:1 test:test_group2 """)
def setUp(self): super().setUp() self.todolist = load_file_to_todolist("test/data/ListCommandUnicodeTest.txt")
def setUp(self): super().setUp() self.todolist = load_file_to_todolist("test/data/SorterTest1.txt")
def setUp(self): super().setUp() self.todolist = load_file_to_todolist("test/data/ListCommandTest.txt") self.terminal_size = namedtuple('terminal_size', ['columns', 'lines'])