Commit f0f319ea authored by Bram Schoenmakers's avatar Bram Schoenmakers

Make testcases runnable from unittest discover.

parent 6e02b2fd
...@@ -185,3 +185,6 @@ class AddCommandTest(CommandTest.CommandTest): ...@@ -185,3 +185,6 @@ class AddCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -79,3 +79,6 @@ class AppendCommandTest(CommandTest.CommandTest): ...@@ -79,3 +79,6 @@ class AppendCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -21,7 +21,7 @@ from topydo.lib.TodoList import TodoList ...@@ -21,7 +21,7 @@ from topydo.lib.TodoList import TodoList
class ArchiveCommandTest(CommandTest.CommandTest): class ArchiveCommandTest(CommandTest.CommandTest):
def test_archive(self): def test_archive(self):
todolist = TestFacilities.load_file_to_todolist("data/ArchiveCommandTest.txt") todolist = TestFacilities.load_file_to_todolist("test/data/ArchiveCommandTest.txt")
archive = TodoList([]) archive = TodoList([])
command = ArchiveCommand(todolist, archive) command = ArchiveCommand(todolist, archive)
...@@ -32,3 +32,6 @@ class ArchiveCommandTest(CommandTest.CommandTest): ...@@ -32,3 +32,6 @@ class ArchiveCommandTest(CommandTest.CommandTest):
self.assertEquals(str(todolist), "x Not complete\n(C) Active") self.assertEquals(str(todolist), "x Not complete\n(C) Active")
self.assertEquals(str(archive), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete") self.assertEquals(str(archive), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
if __name__ == '__main__':
unittest.main()
...@@ -35,3 +35,6 @@ class CommandTest(unittest.TestCase): ...@@ -35,3 +35,6 @@ class CommandTest(unittest.TestCase):
def error(self, p_error): def error(self, p_error):
if p_error: if p_error:
self.errors += escape_ansi(p_error + "\n") self.errors += escape_ansi(p_error + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -20,10 +20,13 @@ from topydo.lib.Config import config ...@@ -20,10 +20,13 @@ from topydo.lib.Config import config
class ConfigTest(unittest.TestCase): class ConfigTest(unittest.TestCase):
def test_config1(self): def test_config1(self):
self.assertEquals(config("data/config1").default_command(), 'do') self.assertEquals(config("test/data/config1").default_command(), 'do')
def test_config2(self): def test_config2(self):
self.assertNotEquals(config("").default_command(), 'do') self.assertNotEquals(config("").default_command(), 'do')
def test_config3(self): def test_config3(self):
self.assertTrue(config("data/config2").ignore_weekends()) self.assertTrue(config("test/data/config2").ignore_weekends())
if __name__ == '__main__':
unittest.main()
...@@ -112,3 +112,6 @@ class DeleteCommandTest(CommandTest.CommandTest): ...@@ -112,3 +112,6 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -246,3 +246,6 @@ class DepCommandTest(CommandTest.CommandTest): ...@@ -246,3 +246,6 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -77,3 +77,6 @@ class DepriCommandTest(CommandTest.CommandTest): ...@@ -77,3 +77,6 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -252,3 +252,6 @@ class DoCommandTest(CommandTest.CommandTest): ...@@ -252,3 +252,6 @@ class DoCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -33,62 +33,62 @@ class FilterTest(unittest.TestCase): ...@@ -33,62 +33,62 @@ class FilterTest(unittest.TestCase):
def test_filter4(self): def test_filter4(self):
""" Test case insensitive match. """ """ Test case insensitive match. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep = Filter.GrepFilter('+project') grep = Filter.GrepFilter('+project')
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest1a-result.txt') reference = load_file('test/data/FilterTest1a-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter5(self): def test_filter5(self):
""" Test case sensitive match. """ """ Test case sensitive match. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep = Filter.GrepFilter('+Project') grep = Filter.GrepFilter('+Project')
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest1b-result.txt') reference = load_file('test/data/FilterTest1b-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter6(self): def test_filter6(self):
""" Test case sensitive match (forced, with lowercase). """ """ Test case sensitive match (forced, with lowercase). """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep = Filter.GrepFilter('+project', True) grep = Filter.GrepFilter('+project', True)
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest1c-result.txt') reference = load_file('test/data/FilterTest1c-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter7(self): def test_filter7(self):
""" Tests the dependency filter. """ """ Tests the dependency filter. """
todolist = load_file_to_todolist('data/FilterTest2.txt') todolist = load_file_to_todolist('test/data/FilterTest2.txt')
depfilter = Filter.DependencyFilter(todolist) depfilter = Filter.DependencyFilter(todolist)
filtered_todos = depfilter.filter(todolist.todos()) filtered_todos = depfilter.filter(todolist.todos())
reference = load_file('data/FilterTest2-result.txt') reference = load_file('test/data/FilterTest2-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter8(self): def test_filter8(self):
""" Test case sensitive match (forced, with lowercase). """ """ Test case sensitive match (forced, with lowercase). """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep = Filter.GrepFilter('+Project', False) grep = Filter.GrepFilter('+Project', False)
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest1a-result.txt') reference = load_file('test/data/FilterTest1a-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter9(self): def test_filter9(self):
""" Test instance filter """ """ Test instance filter """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
instance_filter = Filter.InstanceFilter(todos[2:]) instance_filter = Filter.InstanceFilter(todos[2:])
filtered_todos = instance_filter.filter(todos) filtered_todos = instance_filter.filter(todos)
...@@ -97,7 +97,7 @@ class FilterTest(unittest.TestCase): ...@@ -97,7 +97,7 @@ class FilterTest(unittest.TestCase):
def test_filter10(self): def test_filter10(self):
""" Test instance filter """ """ Test instance filter """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
instance_filter = Filter.InstanceFilter([]) instance_filter = Filter.InstanceFilter([])
filtered_todos = instance_filter.filter(todos) filtered_todos = instance_filter.filter(todos)
...@@ -106,7 +106,7 @@ class FilterTest(unittest.TestCase): ...@@ -106,7 +106,7 @@ class FilterTest(unittest.TestCase):
def test_filter11(self): def test_filter11(self):
""" Test instance filter """ """ Test instance filter """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
instance_filter = Filter.InstanceFilter(todos[2:]) instance_filter = Filter.InstanceFilter(todos[2:])
filtered_todos = instance_filter.filter([]) filtered_todos = instance_filter.filter([])
...@@ -115,7 +115,7 @@ class FilterTest(unittest.TestCase): ...@@ -115,7 +115,7 @@ class FilterTest(unittest.TestCase):
def test_filter12(self): def test_filter12(self):
""" Test limit filter. """ """ Test limit filter. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
limit_filter = Filter.LimitFilter(0) limit_filter = Filter.LimitFilter(0)
filtered_todos = limit_filter.filter(todos) filtered_todos = limit_filter.filter(todos)
...@@ -124,7 +124,7 @@ class FilterTest(unittest.TestCase): ...@@ -124,7 +124,7 @@ class FilterTest(unittest.TestCase):
def test_filter13(self): def test_filter13(self):
""" Test limit filter. """ """ Test limit filter. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
limit_filter = Filter.LimitFilter(1) limit_filter = Filter.LimitFilter(1)
filtered_todos = limit_filter.filter(todos) filtered_todos = limit_filter.filter(todos)
...@@ -134,7 +134,7 @@ class FilterTest(unittest.TestCase): ...@@ -134,7 +134,7 @@ class FilterTest(unittest.TestCase):
def test_filter14(self): def test_filter14(self):
""" Test limit filter. """ """ Test limit filter. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
limit_filter = Filter.LimitFilter(-1) limit_filter = Filter.LimitFilter(-1)
filtered_todos = limit_filter.filter(todos) filtered_todos = limit_filter.filter(todos)
...@@ -143,7 +143,7 @@ class FilterTest(unittest.TestCase): ...@@ -143,7 +143,7 @@ class FilterTest(unittest.TestCase):
def test_filter15(self): def test_filter15(self):
""" Test limit filter. """ """ Test limit filter. """
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
limit_filter = Filter.LimitFilter(100) limit_filter = Filter.LimitFilter(100)
filtered_todos = limit_filter.filter(todos) filtered_todos = limit_filter.filter(todos)
...@@ -151,51 +151,51 @@ class FilterTest(unittest.TestCase): ...@@ -151,51 +151,51 @@ class FilterTest(unittest.TestCase):
self.assertEquals(len(filtered_todos), 4) self.assertEquals(len(filtered_todos), 4)
def test_filter16(self): def test_filter16(self):
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep = Filter.NegationFilter(Filter.GrepFilter('+project')) grep = Filter.NegationFilter(Filter.GrepFilter('+project'))
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest3-result.txt') reference = load_file('test/data/FilterTest3-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter17(self): def test_filter17(self):
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep1 = Filter.GrepFilter('task') grep1 = Filter.GrepFilter('task')
grep2 = Filter.GrepFilter('project') grep2 = Filter.GrepFilter('project')
andfilter = Filter.AndFilter(grep1, grep2) andfilter = Filter.AndFilter(grep1, grep2)
filtered_todos = andfilter.filter(todos) filtered_todos = andfilter.filter(todos)
reference = load_file('data/FilterTest4-result.txt') reference = load_file('test/data/FilterTest4-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter18(self): def test_filter18(self):
todos = load_file('data/FilterTest1.txt') todos = load_file('test/data/FilterTest1.txt')
grep1 = Filter.GrepFilter('part') grep1 = Filter.GrepFilter('part')
grep2 = Filter.GrepFilter('important') grep2 = Filter.GrepFilter('important')
grep = Filter.OrFilter(grep1, grep2) grep = Filter.OrFilter(grep1, grep2)
filtered_todos = grep.filter(todos) filtered_todos = grep.filter(todos)
reference = load_file('data/FilterTest5-result.txt') reference = load_file('test/data/FilterTest5-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter19(self): def test_filter19(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('due:<2014-11-10') otf = Filter.OrdinalTagFilter('due:<2014-11-10')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest6-result.txt') reference = load_file('test/data/FilterTest6-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), \ self.assertEquals(todolist_to_string(filtered_todos), \
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter20(self): def test_filter20(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('due:=2014-11-10') otf = Filter.OrdinalTagFilter('due:=2014-11-10')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
...@@ -203,7 +203,7 @@ class FilterTest(unittest.TestCase): ...@@ -203,7 +203,7 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), "") self.assertEquals(todolist_to_string(filtered_todos), "")
def test_filter21(self): def test_filter21(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('due:=2014-11-10') otf = Filter.OrdinalTagFilter('due:=2014-11-10')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
...@@ -211,7 +211,7 @@ class FilterTest(unittest.TestCase): ...@@ -211,7 +211,7 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), "") self.assertEquals(todolist_to_string(filtered_todos), "")
def test_filter22(self): def test_filter22(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('due:=2014-11-99') otf = Filter.OrdinalTagFilter('due:=2014-11-99')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
...@@ -219,7 +219,7 @@ class FilterTest(unittest.TestCase): ...@@ -219,7 +219,7 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), "") self.assertEquals(todolist_to_string(filtered_todos), "")
def test_filter23(self): def test_filter23(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('due:=garbage') otf = Filter.OrdinalTagFilter('due:=garbage')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
...@@ -227,37 +227,37 @@ class FilterTest(unittest.TestCase): ...@@ -227,37 +227,37 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), "") self.assertEquals(todolist_to_string(filtered_todos), "")
def test_filter24(self): def test_filter24(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:<10') otf = Filter.OrdinalTagFilter('value:<10')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest8-result.txt') reference = load_file('test/data/FilterTest8-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter25(self): def test_filter25(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:<=16') otf = Filter.OrdinalTagFilter('value:<=16')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest9-result.txt') reference = load_file('test/data/FilterTest9-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter26(self): def test_filter26(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:<16') otf = Filter.OrdinalTagFilter('value:<16')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest10-result.txt') reference = load_file('test/data/FilterTest10-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter27(self): def test_filter27(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:<16a') otf = Filter.OrdinalTagFilter('value:<16a')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
...@@ -265,31 +265,31 @@ class FilterTest(unittest.TestCase): ...@@ -265,31 +265,31 @@ class FilterTest(unittest.TestCase):
self.assertEquals(todolist_to_string(filtered_todos), "") self.assertEquals(todolist_to_string(filtered_todos), "")
def test_filter28(self): def test_filter28(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:>8') otf = Filter.OrdinalTagFilter('value:>8')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest11-result.txt') reference = load_file('test/data/FilterTest11-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter29(self): def test_filter29(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:>=8') otf = Filter.OrdinalTagFilter('value:>=8')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest12-result.txt') reference = load_file('test/data/FilterTest12-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
def test_filter30(self): def test_filter30(self):
todos = load_file('data/FilterTest3.txt') todos = load_file('test/data/FilterTest3.txt')
otf = Filter.OrdinalTagFilter('value:>-8') otf = Filter.OrdinalTagFilter('value:>-8')
filtered_todos = otf.filter(todos) filtered_todos = otf.filter(todos)
reference = load_file('data/FilterTest13-result.txt') reference = load_file('test/data/FilterTest13-result.txt')
self.assertEquals(todolist_to_string(filtered_todos), self.assertEquals(todolist_to_string(filtered_todos),
todolist_to_string(reference)) todolist_to_string(reference))
...@@ -350,3 +350,6 @@ class OrdinalTagFilterTest(unittest.TestCase): ...@@ -350,3 +350,6 @@ class OrdinalTagFilterTest(unittest.TestCase):
self.assertEquals(len(result), 1) self.assertEquals(len(result), 1)
self.assertEquals(str(result[0]), "Bar due:%s" % self.tomorrow) self.assertEquals(str(result[0]), "Bar due:%s" % self.tomorrow)
if __name__ == '__main__':
unittest.main()
...@@ -167,3 +167,6 @@ class GraphTest(unittest.TestCase): ...@@ -167,3 +167,6 @@ class GraphTest(unittest.TestCase):
def test_dot_output_without_labels(self): def test_dot_output_without_labels(self):
out = 'digraph g {\n 1\n 1 -> 2\n 1 -> 3\n 2\n 2 -> 4\n 3\n 3 -> 5\n 4\n 4 -> 3\n 4 -> 6\n 5\n 6\n 6 -> 2\n}\n' out = 'digraph g {\n 1\n 1 -> 2\n 1 -> 3\n 2\n 2 -> 4\n 3\n 3 -> 5\n 4\n 4 -> 3\n 4 -> 6\n 5\n 6\n 6 -> 2\n}\n'
self.assertEquals(self.graph.dot(False), out) self.assertEquals(self.graph.dot(False), out)
if __name__ == '__main__':
unittest.main()
...@@ -38,3 +38,6 @@ class ImportanceTest(unittest.TestCase): ...@@ -38,3 +38,6 @@ class ImportanceTest(unittest.TestCase):
today_str = date.today().isoformat() today_str = date.today().isoformat()
todo = Todo("(C) Foo " + config().tag_due() + ":" + today_str) todo = Todo("(C) Foo " + config().tag_due() + ":" + today_str)
self.assertEqual(importance(todo), 8) self.assertEqual(importance(todo), 8)
if __name__ == '__main__':
unittest.main()
...@@ -22,7 +22,7 @@ import TestFacilities ...@@ -22,7 +22,7 @@ import TestFacilities
class ListCommandTest(CommandTest.CommandTest): class ListCommandTest(CommandTest.CommandTest):
def setUp(self): def setUp(self):
super(ListCommandTest, self).setUp() super(ListCommandTest, self).setUp()
self.todolist = TestFacilities.load_file_to_todolist("data/ListCommandTest.txt") self.todolist = TestFacilities.load_file_to_todolist("test/data/ListCommandTest.txt")
def tearDown(self): def tearDown(self):
# restore to the default configuration in case a custom one was set # restore to the default configuration in case a custom one was set
...@@ -101,7 +101,7 @@ class ListCommandTest(CommandTest.CommandTest): ...@@ -101,7 +101,7 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
def test_list11(self): def test_list11(self):
config("data/listcommand.conf") config("test/data/listcommand.conf")
command = ListCommand(["project"], self.todolist, self.out, self.error) command = ListCommand(["project"], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -111,7 +111,7 @@ class ListCommandTest(CommandTest.CommandTest): ...@@ -111,7 +111,7 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
def test_list12(self): def test_list12(self):
config("data/listcommand.conf") config("test/data/listcommand.conf")
command = ListCommand(["-x", "project"], self.todolist, self.out, self.error) command = ListCommand(["-x", "project"], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -129,7 +129,7 @@ class ListCommandTest(CommandTest.CommandTest): ...@@ -129,7 +129,7 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
def test_list14(self): def test_list14(self):
config("data/listcommand2.conf") config("test/data/listcommand2.conf")
command = ListCommand([], self.todolist, self.out, self.error) command = ListCommand([], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -147,7 +147,7 @@ class ListCommandTest(CommandTest.CommandTest): ...@@ -147,7 +147,7 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "") self.assertEquals(self.errors, "")
def test_list16(self): def test_list16(self):
config("data/todolist-uid.conf") config("test/data/todolist-uid.conf")
command = ListCommand([], self.todolist, self.out, self.error) command = ListCommand([], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -170,3 +170,6 @@ class ListCommandTest(CommandTest.CommandTest): ...@@ -170,3 +170,6 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -20,7 +20,7 @@ from topydo.lib.ListContextCommand import ListContextCommand ...@@ -20,7 +20,7 @@ from topydo.lib.ListContextCommand import ListContextCommand
class ListContextCommandTest(CommandTest.CommandTest): class ListContextCommandTest(CommandTest.CommandTest):
def test_contexts1(self): def test_contexts1(self):
todolist = TestFacilities.load_file_to_todolist("data/TodoListTest.txt") todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
command = ListContextCommand([""], todolist, self.out, self.error) command = ListContextCommand([""], todolist, self.out, self.error)
command.execute() command.execute()
...@@ -28,7 +28,7 @@ class ListContextCommandTest(CommandTest.CommandTest): ...@@ -28,7 +28,7 @@ class ListContextCommandTest(CommandTest.CommandTest):
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_contexts2(self): def test_contexts2(self):
todolist = TestFacilities.load_file_to_todolist("data/TodoListTest.txt") todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
command = ListContextCommand(["aaa"], todolist, self.out, self.error) command = ListContextCommand(["aaa"], todolist, self.out, self.error)
command.execute() command.execute()
...@@ -41,3 +41,6 @@ class ListContextCommandTest(CommandTest.CommandTest): ...@@ -41,3 +41,6 @@ class ListContextCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -20,7 +20,7 @@ from topydo.lib.ListProjectCommand import ListProjectCommand ...@@ -20,7 +20,7 @@ from topydo.lib.ListProjectCommand import ListProjectCommand
class ListProjectCommandTest(CommandTest.CommandTest): class ListProjectCommandTest(CommandTest.CommandTest):
def test_projects1(self): def test_projects1(self):
todolist = TestFacilities.load_file_to_todolist("data/TodoListTest.txt") todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
command = ListProjectCommand([""], todolist, self.out, self.error) command = ListProjectCommand([""], todolist, self.out, self.error)
command.execute() command.execute()
...@@ -28,7 +28,7 @@ class ListProjectCommandTest(CommandTest.CommandTest): ...@@ -28,7 +28,7 @@ class ListProjectCommandTest(CommandTest.CommandTest):
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_projects2(self): def test_projects2(self):
todolist = TestFacilities.load_file_to_todolist("data/TodoListTest.txt") todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
command = ListProjectCommand(["aaa"], todolist, self.out, self.error) command = ListProjectCommand(["aaa"], todolist, self.out, self.error)
command.execute() command.execute()
...@@ -41,3 +41,6 @@ class ListProjectCommandTest(CommandTest.CommandTest): ...@@ -41,3 +41,6 @@ class ListProjectCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -170,3 +170,6 @@ class PostponeCommandTest(CommandTest.CommandTest): ...@@ -170,3 +170,6 @@ class PostponeCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -106,3 +106,6 @@ class PriorityCommandTest(CommandTest.CommandTest): ...@@ -106,3 +106,6 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -135,3 +135,6 @@ class RecurrenceTest(unittest.TestCase): ...@@ -135,3 +135,6 @@ class RecurrenceTest(unittest.TestCase):
def test_no_recurrence(self): def test_no_recurrence(self):
self.todo.remove_tag('rec') self.todo.remove_tag('rec')
self.assertRaises(NoRecurrenceException,advance_recurring_todo,self.todo) self.assertRaises(NoRecurrenceException,advance_recurring_todo,self.todo)
if __name__ == '__main__':
unittest.main()
...@@ -108,3 +108,6 @@ class RelativeDateTester(unittest.TestCase): ...@@ -108,3 +108,6 @@ class RelativeDateTester(unittest.TestCase):
def test_offset1(self): def test_offset1(self):
result = relative_date_to_date('1d', self.tomorrow) result = relative_date_to_date('1d', self.tomorrow)
self.assertEquals(result, date.today() + timedelta(2)) self.assertEquals(result, date.today() + timedelta(2))
if __name__ == '__main__':
unittest.main()
...@@ -22,7 +22,7 @@ import TestFacilities ...@@ -22,7 +22,7 @@ import TestFacilities
class SortCommandTest(CommandTest.CommandTest): class SortCommandTest(CommandTest.CommandTest):
def setUp(self): def setUp(self):
super(SortCommandTest, self).setUp() super(SortCommandTest, self).setUp()
self.todolist = TestFacilities.load_file_to_todolist("data/SorterTest1.txt") self.todolist = TestFacilities.load_file_to_todolist("test/data/SorterTest1.txt")
def tearDown(self): def tearDown(self):
# restore to the default configuration in case a custom one was set # restore to the default configuration in case a custom one was set
...@@ -43,7 +43,7 @@ class SortCommandTest(CommandTest.CommandTest): ...@@ -43,7 +43,7 @@ class SortCommandTest(CommandTest.CommandTest):
def test_sort3(self): def test_sort3(self):
""" Check that order does not influence the UID of a todo. """ """ Check that order does not influence the UID of a todo. """
config("data/todolist-uid.conf") config("test/data/todolist-uid.conf")
todo1 = self.todolist.todo('tpi') todo1 = self.todolist.todo('tpi')
command = SortCommand(["text"], self.todolist, self.out, self.error) command = SortCommand(["text"], self.todolist, self.out, self.error)
...@@ -58,3 +58,6 @@ class SortCommandTest(CommandTest.CommandTest): ...@@ -58,3 +58,6 @@ class SortCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -38,21 +38,21 @@ class SorterTest(unittest.TestCase): ...@@ -38,21 +38,21 @@ class SorterTest(unittest.TestCase):
def test_sort1(self): def test_sort1(self):
""" Alphabetically sorted """ """ Alphabetically sorted """
sorter = Sorter('text') sorter = Sorter('text')
self.sort_file('data/SorterTest1.txt', 'data/SorterTest1-result.txt', sorter) self.sort_file('test/data/SorterTest1.txt', 'test/data/SorterTest1-result.txt', sorter)
def test_sort2a(self): def test_sort2a(self):
""" """
Ascendingly sorted by priority. Also checks stableness of the sort. Ascendingly sorted by priority. Also checks stableness of the sort.
""" """
sorter = Sorter('prio') sorter = Sorter('prio')
self.sort_file('data/SorterTest2.txt', 'data/SorterTest2-result.txt', sorter) self.sort_file('test/data/SorterTest2.txt', 'test/data/SorterTest2-result.txt', sorter)
def test_sort2b(self): def test_sort2b(self):
""" """
Ascendingly sorted by priority. Also checks stableness of the sort. Ascendingly sorted by priority. Also checks stableness of the sort.
""" """
sorter = Sorter('asc:prio') sorter = Sorter('asc:prio')
self.sort_file('data/SorterTest2.txt', 'data/SorterTest2-result.txt', sorter) self.sort_file('test/data/SorterTest2.txt', 'test/data/SorterTest2-result.txt', sorter)
def test_sort3(self): def test_sort3(self):
""" """
...@@ -60,32 +60,32 @@ class SorterTest(unittest.TestCase): ...@@ -60,32 +60,32 @@ class SorterTest(unittest.TestCase):
sort. sort.
""" """
sorter = Sorter('desc:prio') sorter = Sorter('desc:prio')
self.sort_file('data/SorterTest3.txt', 'data/SorterTest3-result.txt', sorter) self.sort_file('test/data/SorterTest3.txt', 'test/data/SorterTest3-result.txt', sorter)
def test_sort4(self): def test_sort4(self):
""" Ascendingly sorted by due date """ """ Ascendingly sorted by due date """
sorter = Sorter(config().tag_due()) sorter = Sorter(config().tag_due())
self.sort_file('data/SorterTest4.txt', 'data/SorterTest4-result.txt', sorter) self.sort_file('test/data/SorterTest4.txt', 'test/data/SorterTest4-result.txt', sorter)
def test_sort5(self): def test_sort5(self):
""" Descendingly sorted by due date """ """ Descendingly sorted by due date """
sorter = Sorter('desc:due') sorter = Sorter('desc:due')
self.sort_file('data/SorterTest5.txt', 'data/SorterTest5-result.txt', sorter) self.sort_file('test/data/SorterTest5.txt', 'test/data/SorterTest5-result.txt', sorter)
def test_sort6(self): def test_sort6(self):
""" Ascendingly sorted by creation date """ """ Ascendingly sorted by creation date """
sorter = Sorter('creation') sorter = Sorter('creation')
self.sort_file('data/SorterTest6.txt', 'data/SorterTest6-result.txt', sorter) self.sort_file('test/data/SorterTest6.txt', 'test/data/SorterTest6-result.txt', sorter)
def test_sort7(self): def test_sort7(self):
""" Ascendingly sorted by completion date. """ """ Ascendingly sorted by completion date. """
sorter = Sorter('completion') sorter = Sorter('completion')
self.sort_file('data/SorterTest7.txt', 'data/SorterTest7-result.txt', sorter) self.sort_file('test/data/SorterTest7.txt', 'test/data/SorterTest7-result.txt', sorter)
def test_sort8(self): def test_sort8(self):
""" Descendingly sorted by importance """ """ Descendingly sorted by importance """
sorter = Sorter('desc:importance') sorter = Sorter('desc:importance')
self.sort_file('data/SorterTest8.txt', 'data/SorterTest8-result.txt', sorter) self.sort_file('test/data/SorterTest8.txt', 'test/data/SorterTest8-result.txt', sorter)
def test_sort9(self): def test_sort9(self):
""" """
...@@ -93,22 +93,22 @@ class SorterTest(unittest.TestCase): ...@@ -93,22 +93,22 @@ class SorterTest(unittest.TestCase):
ascending priority. ascending priority.
""" """
sorter = Sorter('desc:importance,priority') sorter = Sorter('desc:importance,priority')
self.sort_file('data/SorterTest9.txt', 'data/SorterTest9-result.txt', sorter) self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
def test_sort10(self): def test_sort10(self):
""" Deal with garbage input. """ """ Deal with garbage input. """
sorter = Sorter('') sorter = Sorter('')
self.sort_file('data/SorterTest9.txt', 'data/SorterTest9.txt', sorter) self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9.txt', sorter)
def test_sort11(self): def test_sort11(self):
""" Deal with garbage input. """ """ Deal with garbage input. """
sorter = Sorter('fnord') sorter = Sorter('fnord')
self.sort_file('data/SorterTest9.txt', 'data/SorterTest9.txt', sorter) self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9.txt', sorter)
def test_sort12(self): def test_sort12(self):
""" Deal with garbage input. """ """ Deal with garbage input. """
sorter = Sorter('desc:importance,,priority') sorter = Sorter('desc:importance,,priority')
self.sort_file('data/SorterTest9.txt', 'data/SorterTest9-result.txt', sorter) self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
def test_sort13(self): def test_sort13(self):
""" """
...@@ -118,14 +118,14 @@ class SorterTest(unittest.TestCase): ...@@ -118,14 +118,14 @@ class SorterTest(unittest.TestCase):
dependencies the average importance should be equal. dependencies the average importance should be equal.
""" """
sorter = Sorter('desc:importance-avg') sorter = Sorter('desc:importance-avg')
self.sort_file('data/SorterTest9.txt', 'data/SorterTest9-result.txt', sorter) self.sort_file('test/data/SorterTest9.txt', 'test/data/SorterTest9-result.txt', sorter)
def test_sort14(self): def test_sort14(self):
sorter = Sorter('desc:importance-average') sorter = Sorter('desc:importance-average')
todolist = load_file_to_todolist('data/SorterTest10.txt') todolist = load_file_to_todolist('test/data/SorterTest10.txt')
view = todolist.view(sorter, []) view = todolist.view(sorter, [])
result = load_file('data/SorterTest10-result.txt') result = load_file('test/data/SorterTest10-result.txt')
self.assertEquals(str(view), todolist_to_string(result)) self.assertEquals(str(view), todolist_to_string(result))
...@@ -136,9 +136,9 @@ class SorterTest(unittest.TestCase): ...@@ -136,9 +136,9 @@ class SorterTest(unittest.TestCase):
""" """
sorter = Sorter('desc:importance-average') sorter = Sorter('desc:importance-average')
todolist = load_file_to_todolist('data/SorterTest11.txt') todolist = load_file_to_todolist('test/data/SorterTest11.txt')
view = todolist.view(sorter, []) view = todolist.view(sorter, [])
result = load_file('data/SorterTest11-result.txt') result = load_file('test/data/SorterTest11-result.txt')
self.assertEquals(str(view), todolist_to_string(result)) self.assertEquals(str(view), todolist_to_string(result))
...@@ -148,8 +148,11 @@ class SorterTest(unittest.TestCase): ...@@ -148,8 +148,11 @@ class SorterTest(unittest.TestCase):
""" """
sorter = Sorter('desc:importance,desc:prio') sorter = Sorter('desc:importance,desc:prio')
todolist = load_file_to_todolist('data/SorterTest12.txt') todolist = load_file_to_todolist('test/data/SorterTest12.txt')
view = todolist.view(sorter, []) view = todolist.view(sorter, [])
result = load_file('data/SorterTest12-result.txt') result = load_file('test/data/SorterTest12-result.txt')
self.assertEquals(str(view), todolist_to_string(result)) self.assertEquals(str(view), todolist_to_string(result))
if __name__ == '__main__':
unittest.main()
...@@ -199,3 +199,6 @@ class TagCommandTest(CommandTest.CommandTest): ...@@ -199,3 +199,6 @@ class TagCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "") self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
...@@ -20,6 +20,9 @@ from TestFacilities import load_file ...@@ -20,6 +20,9 @@ from TestFacilities import load_file
class TodoFileTest(unittest.TestCase): class TodoFileTest(unittest.TestCase):
def test_empty_file(self): def test_empty_file(self):
todofile = load_file('data/TodoFileTest1.txt') todofile = load_file('test/data/TodoFileTest1.txt')
self.assertEquals(len(todofile), 0) self.assertEquals(len(todofile), 0)
if __name__ == '__main__':
unittest.main()
...@@ -27,7 +27,7 @@ from topydo.lib.TodoList import TodoList ...@@ -27,7 +27,7 @@ from topydo.lib.TodoList import TodoList
class TodoListTester(unittest.TestCase): class TodoListTester(unittest.TestCase):
def setUp(self): def setUp(self):
self.todofile = TodoFile('data/TodoListTest.txt') self.todofile = TodoFile('test/data/TodoListTest.txt')
lines = [line for line in self.todofile.read() \ lines = [line for line in self.todofile.read() \
if re.search(r'\S', line)] if re.search(r'\S', line)]
self.text = ''.join(lines) self.text = ''.join(lines)
...@@ -197,13 +197,13 @@ class TodoListTester(unittest.TestCase): ...@@ -197,13 +197,13 @@ class TodoListTester(unittest.TestCase):
self.assertEquals(todo.source(), "(D) Bar @Context1 +Project2") self.assertEquals(todo.source(), "(D) Bar @Context1 +Project2")
def test_uid1(self): def test_uid1(self):
config("data/todolist-uid.conf") config("test/data/todolist-uid.conf")
self.assertEquals(self.todolist.todo('6iu').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project") self.assertEquals(self.todolist.todo('6iu').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project")
def test_uid2(self): def test_uid2(self):
""" Changing the priority should not change the identifier. """ """ Changing the priority should not change the identifier. """
config("data/todolist-uid.conf") config("test/data/todolist-uid.conf")
todo = self.todolist.todo('6iu') todo = self.todolist.todo('6iu')
self.todolist.set_priority(todo, 'B') self.todolist.set_priority(todo, 'B')
...@@ -320,3 +320,6 @@ class TodoListCleanDependencyTester(unittest.TestCase): ...@@ -320,3 +320,6 @@ class TodoListCleanDependencyTester(unittest.TestCase):
self.assertFalse(self.todolist.todo(2).has_tag('p')) self.assertFalse(self.todolist.todo(2).has_tag('p'))
self.assertTrue(self.todolist.todo(2).has_tag('id', '2')) self.assertTrue(self.todolist.todo(2).has_tag('id', '2'))
self.assertTrue(self.todolist.todo(3).has_tag('p', '2')) self.assertTrue(self.todolist.todo(3).has_tag('p', '2'))
if __name__ == '__main__':
unittest.main()
...@@ -85,3 +85,6 @@ class TodoTest(unittest.TestCase): ...@@ -85,3 +85,6 @@ class TodoTest(unittest.TestCase):
def test_length3(self): def test_length3(self):
todo = Todo("(C) Foo t:2014-01-01 due:2014-01-02") todo = Todo("(C) Foo t:2014-01-01 due:2014-01-02")
self.assertEqual(todo.length(), 1) self.assertEqual(todo.length(), 1)
if __name__ == '__main__':
unittest.main()
...@@ -25,8 +25,8 @@ from topydo.lib.TodoList import TodoList ...@@ -25,8 +25,8 @@ from topydo.lib.TodoList import TodoList
class ViewTest(unittest.TestCase): class ViewTest(unittest.TestCase):
def test_view(self): def test_view(self):
""" Check filters and printer for views. """ """ Check filters and printer for views. """
todofile = TodoFile('data/FilterTest1.txt') todofile = TodoFile('test/data/FilterTest1.txt')
ref = load_file('data/ViewTest1-result.txt') ref = load_file('test/data/ViewTest1-result.txt')
todolist = TodoList(todofile.read()) todolist = TodoList(todofile.read())
sorter = Sorter('text') sorter = Sorter('text')
...@@ -35,3 +35,6 @@ class ViewTest(unittest.TestCase): ...@@ -35,3 +35,6 @@ class ViewTest(unittest.TestCase):
self.assertEquals(str(view), todolist_to_string(ref)) self.assertEquals(str(view), todolist_to_string(ref))
if __name__ == '__main__':
unittest.main()
#!/bin/bash
export PYTHONPATH=..
if [ -n "$1" ]; then
TESTS=$1
else
TESTS="*Test.py"
fi
for TEST in $TESTS; do
python -m unittest "${TEST%\.*}" # strip the .py extension
done
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