Commit e22b40a8 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Merge branch 'master' into prompt

The idea is that we can focus on Unicode issues in this branch, getting
both the CLI and the Prompt mode properly in shape having Python 3
support.

Conflicts:
	test/AddCommandTest.py
	test/AppendCommandTest.py
	test/ArchiveCommandTest.py
	test/DepCommandTest.py
	test/DepriCommandTest.py
	test/DoCommandTest.py
	test/EditCommandTest.py
	test/IcalCommandTest.py
	test/ListCommandTest.py
	test/ListContextCommandTest.py
	test/ListProjectCommandTest.py
	test/PostponeCommandTest.py
	test/PriorityCommandTest.py
	test/SortCommandTest.py
	test/TagCommandTest.py
	topydo/cli/CLIApplicationBase.py
parents 2d1015e4 a4266ce0
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
install:
- "pip install ."
- "pip install icalendar"
script: python setup.py test
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/b7a69031304c472294ac
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: false # default: false
......@@ -8,6 +8,9 @@ setup(
author = "Bram Schoenmakers",
author_email = "me@bramschoenmakers.nl",
url = "https://github.com/bram85/topydo",
install_requires = [
'six',
],
extras_require = {
'ical': ['icalendar'],
'prompt-toolkit': ['prompt-toolkit >= 0.37'],
......@@ -22,7 +25,10 @@ setup(
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Natural Language :: English",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Utilities",
],
long_description = """\
......
This diff is collapsed.
......@@ -17,10 +17,10 @@
import unittest
from topydo.commands.AppendCommand import AppendCommand
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList
class AppendCommandTest(CommandTest.CommandTest):
class AppendCommandTest(CommandTest):
def setUp(self):
super(AppendCommandTest, self).setUp()
self.todolist = TodoList([])
......@@ -79,8 +79,8 @@ class AppendCommandTest(CommandTest.CommandTest):
command = AppendCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -17,13 +17,13 @@
import unittest
from topydo.commands.ArchiveCommand import ArchiveCommand
import CommandTest
import TestFacilities
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
from topydo.lib.TodoList import TodoList
class ArchiveCommandTest(CommandTest.CommandTest):
class ArchiveCommandTest(CommandTest):
def test_archive(self):
todolist = TestFacilities.load_file_to_todolist("test/data/ArchiveCommandTest.txt")
todolist = load_file_to_todolist("test/data/ArchiveCommandTest.txt")
archive = TodoList([])
command = ArchiveCommand(todolist, archive)
......@@ -31,8 +31,8 @@ class ArchiveCommandTest(CommandTest.CommandTest):
self.assertTrue(todolist.is_dirty())
self.assertTrue(archive.is_dirty())
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.assertEqual(str(todolist), "x Not complete\n(C) Active")
self.assertEqual(str(archive), "x 2014-10-19 Complete\nx 2014-10-20 Another one complete")
if __name__ == '__main__':
unittest.main()
......
......@@ -21,7 +21,7 @@ from test.TopydoTest import TopydoTest
class ConfigTest(TopydoTest):
def test_config1(self):
self.assertEquals(config("test/data/config1").default_command(), 'do')
self.assertEqual(config("test/data/config1").default_command(), 'do')
def test_config2(self):
self.assertNotEquals(config("").default_command(), 'do')
......
......@@ -16,7 +16,7 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.Config import config
from topydo.commands.DeleteCommand import DeleteCommand
from topydo.lib.TodoList import TodoList
......@@ -28,7 +28,7 @@ def _yes_prompt(self):
def _no_prompt(self):
return "n"
class DeleteCommandTest(CommandTest.CommandTest):
class DeleteCommandTest(CommandTest):
def setUp(self):
super(DeleteCommandTest, self).setUp()
todos = [
......@@ -43,79 +43,79 @@ class DeleteCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).source(), "Bar")
self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).source(), "Bar")
self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEqual(self.errors, "")
def test_del1_regex(self):
command = DeleteCommand(["Foo"], self.todolist, self.out, self.error, _no_prompt)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).source(), "Bar")
self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).source(), "Bar")
self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEqual(self.errors, "")
def test_del2(self):
command = DeleteCommand(["1"], self.todolist, self.out, self.error, _yes_prompt)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.count(), 0)
self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.count(), 0)
self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Bar\nRemoved: Foo\n")
self.assertEqual(self.errors, "")
def test_del3(self):
command = DeleteCommand(["-f", "1"], self.todolist, self.out, self.error, _yes_prompt)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.count(), 1) # force won't delete subtasks
self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.count(), 1) # force won't delete subtasks
self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEqual(self.errors, "")
def test_del4(self):
command = DeleteCommand(["--force", "1"], self.todolist, self.out, self.error, _yes_prompt)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.count(), 1) # force won't delete subtasks
self.assertEquals(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.count(), 1) # force won't delete subtasks
self.assertEqual(self.output, "| 2| Bar p:1\nRemoved: Foo id:1\n")
self.assertEqual(self.errors, "")
def test_del5(self):
command = DeleteCommand(["2"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).source(), "Foo")
self.assertEquals(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n| 1| Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).source(), "Foo")
self.assertEqual(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\n| 1| Foo\n")
self.assertEqual(self.errors, "")
def test_del7(self):
command = DeleteCommand(["99"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_del8(self):
command = DeleteCommand(["A"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_del9(self):
""" Test deletion with textual IDs. """
config("test/data/todolist-uid.conf")
command = DeleteCommand(["b0n"], self.todolist, self.out, self.error)
command = DeleteCommand(["8to"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(str(self.todolist), "Foo")
self.assertEqual(str(self.todolist), "Foo")
self.assertRaises(InvalidTodoException, self.todolist.todo, 'b0n')
def test_multi_del1(self):
......@@ -123,14 +123,14 @@ class DeleteCommandTest(CommandTest.CommandTest):
command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _no_prompt)
command.execute()
self.assertEquals(self.todolist.count(), 0)
self.assertEqual(self.todolist.count(), 0)
def test_multi_del2(self):
""" Test deletion of multiple items. """
command = DeleteCommand(["1", "2"], self.todolist, self.out, self.error, _yes_prompt)
command.execute()
self.assertEquals(self.todolist.count(), 0)
self.assertEqual(self.todolist.count(), 0)
def test_multi_del3(self):
""" Fail if any of supplied todo numbers is invalid. """
......@@ -138,8 +138,8 @@ class DeleteCommandTest(CommandTest.CommandTest):
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given: 99.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given: 99.\n")
def test_multi_del4(self):
""" Check output when all supplied todo numbers are invalid. """
......@@ -147,8 +147,8 @@ class DeleteCommandTest(CommandTest.CommandTest):
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: A.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: A.\n")
def test_empty(self):
command = DeleteCommand([], self.todolist, self.out, self.error)
......@@ -156,14 +156,14 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def test_help(self):
command = DeleteCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from topydo.commands.DepCommand import DepCommand
from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList
class DepCommandTest(CommandTest.CommandTest):
class DepCommandTest(CommandTest):
def setUp(self):
super(DepCommandTest, self).setUp()
todos = [
......@@ -40,8 +40,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(4).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_add2(self):
command = DepCommand(["add", "1", "4"], self.todolist, self.out, self.error)
......@@ -49,32 +49,32 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(4).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_add3(self):
command = DepCommand(["add", "99", "3"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_add4(self):
command = DepCommand(["add", "A", "3"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_add5(self):
command = DepCommand(["add", "1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n")
def test_add6(self):
command = DepCommand(["add", "1", "after", "4"], self.todolist, self.out, self.error)
......@@ -82,8 +82,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(4).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_add7(self):
command = DepCommand(["add", "1", "before", "4"], self.todolist, self.out, self.error)
......@@ -91,8 +91,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).has_tag('p', '2'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_add8(self):
command = DepCommand(["add", "1", "partof", "4"], self.todolist, self.out, self.error)
......@@ -100,8 +100,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).has_tag('p', '2'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_add9(self):
command = DepCommand(["add", "Foo", "to", "4"], self.todolist, self.out, self.error)
......@@ -109,8 +109,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(4).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def rm_helper(self, p_args):
"""
......@@ -124,8 +124,8 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).has_tag('id', '1'))
self.assertFalse(self.todolist.todo(3).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_rm1(self):
self.rm_helper(["rm", "1", "to", "3"])
......@@ -144,64 +144,64 @@ class DepCommandTest(CommandTest.CommandTest):
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_rm4(self):
command = DepCommand(["rm", "A", "3"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_rm5(self):
command = DepCommand(["rm", "1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n")
def test_ls1(self):
command = DepCommand(["ls", "1", "to"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "| 2| Bar p:1\n| 3| Baz p:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\n")
self.assertEqual(self.errors, "")
def test_ls2(self):
command = DepCommand(["ls", "99", "to"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_ls3(self):
command = DepCommand(["ls", "to", "3"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "| 1| Foo id:1\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "| 1| Foo id:1\n")
self.assertEqual(self.errors, "")
def test_ls4(self):
command = DepCommand(["ls", "to", "99"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_ls5(self):
command = DepCommand(["ls", "1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n")
def test_ls6(self):
command = DepCommand(["ls"], self.todolist, self.out, self.error)
......@@ -209,7 +209,7 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def gc_helper(self, p_subcommand):
command = DepCommand([p_subcommand], self.todolist, self.out, self.error)
......@@ -246,8 +246,8 @@ class DepCommandTest(CommandTest.CommandTest):
command = DepCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from topydo.commands.DepriCommand import DepriCommand
from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList
class DepriCommandTest(CommandTest.CommandTest):
class DepriCommandTest(CommandTest):
def setUp(self):
super(DepriCommandTest, self).setUp()
todos = [
......@@ -36,37 +36,37 @@ class DepriCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).priority(), None)
self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEqual(self.errors, "")
def test_depri2(self):
command = DepriCommand(["2"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(2).priority(), None)
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(2).priority(), None)
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "")
def test_depri3(self):
command = DepriCommand(["Foo"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).priority(), None)
self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n")
self.assertEqual(self.errors, "")
def test_depri4(self):
command = DepriCommand(["1","Baz"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.todo(1).priority(), None)
self.assertEquals(self.todolist.todo(3).priority(), None)
self.assertEquals(self.output, "Priority removed.\n| 1| Foo\nPriority removed.\n| 3| Baz\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.todolist.todo(1).priority(), None)
self.assertEqual(self.todolist.todo(3).priority(), None)
self.assertEqual(self.output, "Priority removed.\n| 1| Foo\nPriority removed.\n| 3| Baz\n")
self.assertEqual(self.errors, "")
def test_invalid1(self):
......@@ -75,7 +75,7 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_invalid2(self):
command = DepriCommand(["99", "1"], self.todolist, self.out, self.error)
......@@ -83,7 +83,7 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given: 99.\n")
self.assertEqual(self.errors, "Invalid todo number given: 99.\n")
def test_invalid3(self):
command = DepriCommand(["99", "FooBar"], self.todolist, self.out, self.error)
......@@ -91,7 +91,7 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: FooBar.\n")
self.assertEqual(self.errors, "Invalid todo number given: 99.\nInvalid todo number given: FooBar.\n")
def test_empty(self):
command = DepriCommand([], self.todolist, self.out, self.error)
......@@ -99,14 +99,14 @@ class DepriCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def test_help(self):
command = DepriCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
......@@ -17,12 +17,12 @@
import unittest
import mock
import CommandTest
from topydo.commands.EditCommand import EditCommand
from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList
from topydo.lib.Todo import Todo
class EditCommandTest(CommandTest.CommandTest):
class EditCommandTest(CommandTest):
def setUp(self):
super(EditCommandTest, self).setUp()
todos = [
......@@ -43,8 +43,8 @@ class EditCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.errors, "")
self.assertEquals(str(self.todolist), "Bar p:1 @test\nBaz @test\nFoo id:1")
self.assertEqual(self.errors, "")
self.assertEqual(str(self.todolist), "Bar p:1 @test\nBaz @test\nFoo id:1")
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
......@@ -57,8 +57,8 @@ class EditCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.errors, "")
self.assertEquals(str(self.todolist), "Foo id:1\nBaz @test\nLazy Cat")
self.assertEqual(self.errors, "")
self.assertEqual(str(self.todolist), "Foo id:1\nBaz @test\nLazy Cat")
def test_edit3(self):
""" Throw an error after invalid todo number given as argument. """
......@@ -66,15 +66,15 @@ class EditCommandTest(CommandTest.CommandTest):
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_edit4(self):
""" Throw an error with pointing invalid argument. """
command = EditCommand(["Bar","4"], self.todolist, self.out, self.error, None)
command = EditCommand(["Bar", "4"], self.todolist, self.out, self.error, None)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.errors, "Invalid todo number given: 4.\n")
self.assertEqual(self.errors, "Invalid todo number given: 4.\n")
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
......@@ -83,12 +83,12 @@ class EditCommandTest(CommandTest.CommandTest):
mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Only one line')]
command = EditCommand(["1","Bar"], self.todolist, self.out, self.error, None)
command = EditCommand(["1", "Bar"], self.todolist, self.out, self.error, None)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n")
self.assertEquals(str(self.todolist), "Foo id:1\nBar p:1 @test\nBaz @test")
self.assertEqual(self.errors, "Number of edited todos is not equal to number of supplied todo IDs.\n")
self.assertEqual(str(self.todolist), "Foo id:1\nBar p:1 @test\nBaz @test")
@mock.patch('topydo.commands.EditCommand.EditCommand._todos_from_temp')
@mock.patch('topydo.commands.EditCommand.EditCommand._open_in_editor')
......@@ -97,12 +97,12 @@ class EditCommandTest(CommandTest.CommandTest):
mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Lazy Cat'), Todo('Lazy Dog')]
command = EditCommand(["-e","@test"], self.todolist, self.out, self.error, None)
command = EditCommand(["-e", "@test"], self.todolist, self.out, self.error, None)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.errors, "")
self.assertEquals(str(self.todolist), "Foo id:1\nLazy Cat\nLazy Dog")
self.assertEqual(self.errors, "")
self.assertEqual(str(self.todolist), "Foo id:1\nLazy Cat\nLazy Dog")
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
......@@ -51,34 +51,34 @@ class GraphTest(TopydoTest):
self.assertFalse(self.graph.has_edge_id("1"))
def test_incoming_neighbors1(self):
self.assertEquals(self.graph.incoming_neighbors(1), set())
self.assertEqual(self.graph.incoming_neighbors(1), set())
def test_edge_id_of_nonexistent_edge(self):
self.assertFalse(self.graph.edge_id(1, 6))
def test_incoming_neighbors2(self):
self.assertEquals(self.graph.incoming_neighbors(2), set([1, 6]))
self.assertEqual(self.graph.incoming_neighbors(2), set([1, 6]))
def test_incoming_neighbors3(self):
self.assertEquals(self.graph.incoming_neighbors(1, True), set())
self.assertEqual(self.graph.incoming_neighbors(1, True), set())
def test_incoming_neighbors4(self):
self.assertEquals(self.graph.incoming_neighbors(5, True), set([1, 2, 3, 4, 6]))
self.assertEqual(self.graph.incoming_neighbors(5, True), set([1, 2, 3, 4, 6]))
def test_outgoing_neighbors1(self):
self.assertEquals(self.graph.outgoing_neighbors(1), set([2, 3]))
self.assertEqual(self.graph.outgoing_neighbors(1), set([2, 3]))
def test_outgoing_neighbors2(self):
self.assertEquals(self.graph.outgoing_neighbors(2), set([4]))
self.assertEqual(self.graph.outgoing_neighbors(2), set([4]))
def test_outgoing_neighbors3(self):
self.assertEquals(self.graph.outgoing_neighbors(1, True), set([2, 3, 4, 5, 6]))
self.assertEqual(self.graph.outgoing_neighbors(1, True), set([2, 3, 4, 5, 6]))
def test_outgoing_neighbors4(self):
self.assertEquals(self.graph.outgoing_neighbors(3), set([5]))
self.assertEqual(self.graph.outgoing_neighbors(3), set([5]))
def test_outgoing_neighbors5(self):
self.assertEquals(self.graph.outgoing_neighbors(5), set([]))
self.assertEqual(self.graph.outgoing_neighbors(5), set([]))
def test_remove_edge1(self):
self.graph.remove_edge(1, 2)
......@@ -165,11 +165,11 @@ class GraphTest(TopydoTest):
def test_str_output(self):
out = 'digraph g {\n 1\n 1 -> 2 [label="1"]\n 1 -> 3\n 2\n 2 -> 4 [label="Test"]\n 3\n 3 -> 5\n 4\n 4 -> 3\n 4 -> 6\n 5\n 6\n 6 -> 2\n}\n'
self.assertEquals(str(self.graph), out)
self.assertEqual(str(self.graph), out)
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'
self.assertEquals(self.graph.dot(False), out)
self.assertEqual(self.graph.dot(False), out)
if __name__ == '__main__':
unittest.main()
......@@ -14,19 +14,24 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import codecs
import re
import sys
import unittest
from topydo.lib.Config import config
import CommandTest
from topydo.commands.IcalCommand import IcalCommand
import TestFacilities
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
class IcalCommandTest(CommandTest.CommandTest):
IS_PYTHON_32 = (sys.version_info.major, sys.version_info.minor) == (3, 2)
class IcalCommandTest(CommandTest):
def setUp(self):
super(IcalCommandTest, self).setUp()
self.todolist = TestFacilities.load_file_to_todolist("test/data/ListCommandTest.txt")
self.todolist = load_file_to_todolist("test/data/ListCommandTest.txt")
@unittest.skipIf(IS_PYTHON_32, "icalendar is not supported for Python 3.2")
def test_ical(self):
def replace_ical_tags(p_text):
# replace identifiers with dots, since they're random.
......@@ -41,18 +46,39 @@ class IcalCommandTest(CommandTest.CommandTest):
self.assertTrue(self.todolist.is_dirty())
icaltext = ""
with open('test/data/ListCommandTest.ics', 'r') as ical:
icaltext = "".join(ical.readlines())
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, "")
@unittest.skipUnless(IS_PYTHON_32, "icalendar is not supported for Python 3.2")
def test_ical_python32(self):
"""
Test case for Python 3.2 where icalendar is not supported.
"""
command = IcalCommand([""], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(replace_ical_tags(self.output), replace_ical_tags(icaltext))
self.assertEquals(self.errors, "")
self.assertFalse(self.todolist.is_dirty())
self.assertEqual(self.output, '')
self.assertEqual(self.errors, "icalendar is not supported in this Python version.\n")
@unittest.skipIf(IS_PYTHON_32, "icalendar is not supported for Python 3.2")
def test_help(self):
command = IcalCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
@unittest.skipUnless(IS_PYTHON_32, "icalendar is not supported for Python 3.2")
def test_help_python32(self):
command = IcalCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "icalendar is not supported in this Python version.\n")
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
......@@ -16,33 +16,33 @@
import unittest
import CommandTest
import TestFacilities
from topydo.commands.ListContextCommand import ListContextCommand
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
class ListContextCommandTest(CommandTest.CommandTest):
class ListContextCommandTest(CommandTest):
def test_contexts1(self):
todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
command = ListContextCommand([""], todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output,"Context1\nContext2\n")
self.assertEqual(self.output,"Context1\nContext2\n")
self.assertFalse(self.errors)
def test_contexts2(self):
todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
command = ListContextCommand(["aaa"], todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output,"Context1\nContext2\n")
self.assertEqual(self.output,"Context1\nContext2\n")
self.assertFalse(self.errors)
def test_help(self):
command = ListContextCommand(["help"], None, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -16,33 +16,33 @@
import unittest
import CommandTest
import TestFacilities
from topydo.commands.ListProjectCommand import ListProjectCommand
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
class ListProjectCommandTest(CommandTest.CommandTest):
class ListProjectCommandTest(CommandTest):
def test_projects1(self):
todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
command = ListProjectCommand([""], todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output,"Project1\nProject2\n")
self.assertEqual(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors)
def test_projects2(self):
todolist = TestFacilities.load_file_to_todolist("test/data/TodoListTest.txt")
todolist = load_file_to_todolist("test/data/TodoListTest.txt")
command = ListProjectCommand(["aaa"], todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output,"Project1\nProject2\n")
self.assertEqual(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors)
def test_help(self):
command = ListProjectCommand(["help"], None, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from topydo.commands.PriorityCommand import PriorityCommand
from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList
class PriorityCommandTest(CommandTest.CommandTest):
class PriorityCommandTest(CommandTest):
def setUp(self):
super(PriorityCommandTest, self).setUp()
todos = [
......@@ -35,40 +35,40 @@ class PriorityCommandTest(CommandTest.CommandTest):
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Priority changed from A to B\n| 1| (B) Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n")
self.assertEqual(self.errors, "")
def test_set_prio2(self):
command = PriorityCommand(["2", "Z"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Priority set to Z.\n| 2| (Z) Bar\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "Priority set to Z.\n| 2| (Z) Bar\n")
self.assertEqual(self.errors, "")
def test_set_prio3(self):
command = PriorityCommand(["Foo", "B"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Priority changed from A to B\n| 1| (B) Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "Priority changed from A to B\n| 1| (B) Foo\n")
self.assertEqual(self.errors, "")
def test_set_prio4(self):
command = PriorityCommand(["1", "A"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "| 1| (A) Foo\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "| 1| (A) Foo\n")
self.assertEqual(self.errors, "")
def test_set_prio5(self):
command = PriorityCommand(["Foo", "2", "C"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n")
self.assertEquals(self.errors, "")
self.assertEqual(self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n")
self.assertEqual(self.errors, "")
def test_invalid1(self):
command = PriorityCommand(["99", "A"], self.todolist, self.out, self.error)
......@@ -76,7 +76,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given.\n")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_invalid2(self):
command = PriorityCommand(["1", "99", "A"], self.todolist, self.out, self.error)
......@@ -84,7 +84,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given: 99.\n")
self.assertEqual(self.errors, "Invalid todo number given: 99.\n")
def test_invalid3(self):
command = PriorityCommand(["98", "99", "A"], self.todolist, self.out, self.error)
......@@ -92,7 +92,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid todo number given: 98.\nInvalid todo number given: 99.\n")
self.assertEqual(self.errors, "Invalid todo number given: 98.\nInvalid todo number given: 99.\n")
def test_invalid4(self):
command = PriorityCommand(["1", "ZZ"], self.todolist, self.out, self.error)
......@@ -100,7 +100,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, "Invalid priority given.\n")
self.assertEqual(self.errors, "Invalid priority given.\n")
def test_invalid5(self):
command = PriorityCommand(["A"], self.todolist, self.out, self.error)
......@@ -108,7 +108,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def test_invalid6(self):
command = PriorityCommand(["1"], self.todolist, self.out, self.error)
......@@ -116,7 +116,7 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def test_empty(self):
command = PriorityCommand([], self.todolist, self.out, self.error)
......@@ -124,14 +124,14 @@ class PriorityCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertFalse(self.output)
self.assertEquals(self.errors, command.usage() + "\n")
self.assertEqual(self.errors, command.usage() + "\n")
def test_help(self):
command = PriorityCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -35,7 +35,7 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), future.isoformat())
new_todo = advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_duedate2(self):
""" Where due date is today. """
......@@ -45,7 +45,7 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), today.isoformat())
new_todo = advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_duedate3(self):
""" Where due date is in the past. """
......@@ -55,7 +55,7 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), past.isoformat())
new_todo = advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_duedate4(self):
""" Where due date is in the past. """
......@@ -65,7 +65,7 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), past.isoformat())
new_todo = strict_advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_duedate5(self):
""" Where due date is in the future. """
......@@ -75,7 +75,7 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), future.isoformat())
new_todo = strict_advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_duedate6(self):
""" Where due date is today. """
......@@ -85,21 +85,21 @@ class RecurrenceTest(TopydoTest):
self.todo.set_tag(config().tag_due(), today.isoformat())
new_todo = strict_advance_recurring_todo(self.todo)
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_noduedate1(self):
new_due = date.today() + timedelta(7)
new_todo = advance_recurring_todo(self.todo)
self.assertTrue(new_todo.has_tag(config().tag_due()))
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_noduedate2(self):
new_due = date.today() + timedelta(7)
new_todo = strict_advance_recurring_todo(self.todo)
self.assertTrue(new_todo.has_tag(config().tag_due()))
self.assertEquals(new_todo.due_date(), new_due)
self.assertEqual(new_todo.due_date(), new_due)
def test_startdate1(self):
""" Start date is before due date. """
......@@ -110,7 +110,7 @@ class RecurrenceTest(TopydoTest):
new_start = date.today() + timedelta(6)
new_todo = advance_recurring_todo(self.todo)
self.assertEquals(new_todo.start_date(), new_start)
self.assertEqual(new_todo.start_date(), new_start)
def test_startdate2(self):
""" Strict recurrence. Start date is before due date. """
......@@ -122,7 +122,7 @@ class RecurrenceTest(TopydoTest):
new_start = date.today() + timedelta(5)
new_todo = strict_advance_recurring_todo(self.todo)
self.assertEquals(new_todo.start_date(), new_start)
self.assertEqual(new_todo.start_date(), new_start)
def test_startdate3(self):
""" Start date equals due date. """
......@@ -132,7 +132,7 @@ class RecurrenceTest(TopydoTest):
new_start = date.today() + timedelta(7)
new_todo = advance_recurring_todo(self.todo)
self.assertEquals(new_todo.start_date(), new_start)
self.assertEqual(new_todo.start_date(), new_start)
def test_no_recurrence(self):
self.todo.remove_tag('rec')
......
......@@ -18,9 +18,9 @@ from datetime import date, timedelta
import unittest
from topydo.lib.RelativeDate import relative_date_to_date
import TopydoTest
from test.TopydoTest import TopydoTest
class RelativeDateTester(TopydoTest.TopydoTest):
class RelativeDateTester(TopydoTest):
def setUp(self):
super(RelativeDateTester, self).setUp()
self.today = date.today()
......@@ -32,20 +32,20 @@ class RelativeDateTester(TopydoTest.TopydoTest):
def test_zero_days(self):
result = relative_date_to_date('0d')
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_one_day(self):
result = relative_date_to_date('1d')
self.assertEquals(result, self.tomorrow)
self.assertEqual(result, self.tomorrow)
def test_one_week(self):
result = relative_date_to_date('1w')
self.assertEquals(result, date.today() + timedelta(weeks=1))
self.assertEqual(result, date.today() + timedelta(weeks=1))
def test_one_month(self):
test_date = date(2015, 1, 10)
result = relative_date_to_date('1m', test_date)
self.assertEquals(result, date(2015, 2, 10))
self.assertEqual(result, date(2015, 2, 10))
def test_one_month_ext(self):
test_date1 = date(2015, 1, 29)
......@@ -60,31 +60,31 @@ class RelativeDateTester(TopydoTest.TopydoTest):
result4 = relative_date_to_date('1m', test_date4)
result5 = relative_date_to_date('1m', test_date5)
self.assertEquals(result1, date(2015, 2, 28))
self.assertEquals(result2, date(2016, 2, 29))
self.assertEquals(result3, date(2016, 1, 31))
self.assertEquals(result4, date(2015, 8, 31))
self.assertEquals(result5, date(2015, 11, 30))
self.assertEqual(result1, date(2015, 2, 28))
self.assertEqual(result2, date(2016, 2, 29))
self.assertEqual(result3, date(2016, 1, 31))
self.assertEqual(result4, date(2015, 8, 31))
self.assertEqual(result5, date(2015, 11, 30))
def test_one_year(self):
test_date = date(2015, 1, 10)
result = relative_date_to_date('1y', test_date)
self.assertEquals(result, date(2016, 1, 10))
self.assertEqual(result, date(2016, 1, 10))
def test_leap_year(self):
test_date = date(2016, 2, 29)
result1 = relative_date_to_date('1y', test_date)
result2 = relative_date_to_date('4y', test_date)
self.assertEquals(result1, date(2017, 2, 28))
self.assertEquals(result2, date(2020, 2, 29))
self.assertEqual(result1, date(2017, 2, 28))
self.assertEqual(result2, date(2020, 2, 29))
def test_zero_months(self):
result = relative_date_to_date('0m')
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_zero_years(self):
result = relative_date_to_date('0y')
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_garbage1(self):
result = relative_date_to_date('0dd')
......@@ -92,40 +92,40 @@ class RelativeDateTester(TopydoTest.TopydoTest):
def test_one_day_capital(self):
result = relative_date_to_date('1D')
self.assertEquals(result, self.tomorrow)
self.assertEqual(result, self.tomorrow)
def test_today1(self):
result = relative_date_to_date('today')
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_today2(self):
result = relative_date_to_date('tod')
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_today3(self):
result = relative_date_to_date('today', \
date.today() + timedelta(1))
self.assertEquals(result, self.today)
self.assertEqual(result, self.today)
def test_tomorrow1(self):
result = relative_date_to_date('Tomorrow')
self.assertEquals(result, self.tomorrow)
self.assertEqual(result, self.tomorrow)
def test_tomorrow2(self):
result = relative_date_to_date('tom')
self.assertEquals(result, self.tomorrow)
self.assertEqual(result, self.tomorrow)
def test_monday1(self):
result = relative_date_to_date('monday')
self.assertEquals(result, self.monday)
self.assertEqual(result, self.monday)
def test_monday2(self):
result = relative_date_to_date('mo')
self.assertEquals(result, self.monday)
self.assertEqual(result, self.monday)
def test_monday3(self):
result = relative_date_to_date('mon')
self.assertEquals(result, self.monday)
self.assertEqual(result, self.monday)
def test_monday4(self):
result = relative_date_to_date('mondayy')
......@@ -133,11 +133,11 @@ class RelativeDateTester(TopydoTest.TopydoTest):
def test_offset1(self):
result = relative_date_to_date('1d', self.tomorrow)
self.assertEquals(result, date.today() + timedelta(2))
self.assertEqual(result, date.today() + timedelta(2))
def test_negative_period1(self):
result = relative_date_to_date('-1d')
self.assertEquals(result, date.today() - timedelta(1))
self.assertEqual(result, date.today() - timedelta(1))
def test_negative_period2(self):
result = relative_date_to_date('-0d')
......
......@@ -16,46 +16,46 @@
import unittest
import CommandTest
from topydo.lib.Config import config
from topydo.commands.SortCommand import SortCommand
import TestFacilities
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
class SortCommandTest(CommandTest.CommandTest):
class SortCommandTest(CommandTest):
def setUp(self):
super(SortCommandTest, self).setUp()
self.todolist = TestFacilities.load_file_to_todolist("test/data/SorterTest1.txt")
self.todolist = load_file_to_todolist("test/data/SorterTest1.txt")
def test_sort1(self):
""" Alphabetically sorted """
command = SortCommand(["text"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(str(self.todolist), "First\n(A) Foo\n2014-06-14 Last")
self.assertEqual(str(self.todolist), "First\n(A) Foo\n2014-06-14 Last")
def test_sort2(self):
command = SortCommand([], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(str(self.todolist), "(A) Foo\n2014-06-14 Last\nFirst")
self.assertEqual(str(self.todolist), "(A) Foo\n2014-06-14 Last\nFirst")
def test_sort3(self):
""" Check that order does not influence the UID of a todo. """
config("test/data/todolist-uid.conf")
todo1 = self.todolist.todo('tpi')
todo1 = self.todolist.todo('7ui')
command = SortCommand(["text"], self.todolist, self.out, self.error)
command.execute()
todo2 = self.todolist.todo('tpi')
todo2 = self.todolist.todo('7ui')
self.assertEquals(todo1.source(), todo2.source())
self.assertEqual(todo1.source(), todo2.source())
def test_help(self):
command = SortCommand(["help"], self.todolist, self.out, self.error)
command.execute()
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n\n" + command.help() + "\n")
self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
if __name__ == '__main__':
unittest.main()
......@@ -33,8 +33,8 @@ class SorterTest(TopydoTest):
todos_sorted = todolist_to_string(p_sorter.sort(todos))
todos_ref = todolist_to_string(load_file(p_filename_ref))
self.assertEquals(todos_sorted, todos_ref)
self.assertEquals(todolist_to_string(todos), text_before)
self.assertEqual(todos_sorted, todos_ref)
self.assertEqual(todolist_to_string(todos), text_before)
def test_sort1(self):
""" Alphabetically sorted """
......@@ -128,7 +128,7 @@ class SorterTest(TopydoTest):
view = todolist.view(sorter, [])
result = load_file('test/data/SorterTest10-result.txt')
self.assertEquals(str(view), todolist_to_string(result))
self.assertEqual(str(view), todolist_to_string(result))
def test_sort15(self):
"""
......@@ -141,7 +141,7 @@ class SorterTest(TopydoTest):
view = todolist.view(sorter, [])
result = load_file('test/data/SorterTest11-result.txt')
self.assertEquals(str(view), todolist_to_string(result))
self.assertEqual(str(view), todolist_to_string(result))
def test_sort16(self):
"""
......@@ -153,7 +153,7 @@ class SorterTest(TopydoTest):
view = todolist.view(sorter, [])
result = load_file('test/data/SorterTest12-result.txt')
self.assertEquals(str(view), todolist_to_string(result))
self.assertEqual(str(view), todolist_to_string(result))
if __name__ == '__main__':
unittest.main()
This diff is collapsed.
......@@ -48,7 +48,7 @@ class TodoBaseTester(TopydoTest):
todo = TodoBase("(C) Foo id:1")
todo.add_tag('id', '2')
self.assertEquals(todo.source(), '(C) Foo id:1 id:2')
self.assertEqual(todo.source(), '(C) Foo id:1 id:2')
def test_set_tag1(self):
todo = TodoBase("(C) Foo foo:bar")
......@@ -146,7 +146,7 @@ class TodoBaseTester(TopydoTest):
todo = TodoBase("(A) Foo")
todo.set_priority('B')
self.assertEquals(todo.priority(), 'B')
self.assertEqual(todo.priority(), 'B')
self.assertTrue(re.match(r'^\(B\) Foo$', todo.src))
def test_set_priority2(self):
......@@ -154,7 +154,7 @@ class TodoBaseTester(TopydoTest):
todo = TodoBase("Foo")
todo.set_priority('B')
self.assertEquals(todo.priority(), 'B')
self.assertEqual(todo.priority(), 'B')
self.assertTrue(re.match(r'^\(B\) Foo$', todo.src))
def test_set_priority3(self):
......@@ -162,7 +162,7 @@ class TodoBaseTester(TopydoTest):
todo = TodoBase("(A) Foo")
todo.set_priority('AB')
self.assertEquals(todo.priority(), 'A')
self.assertEqual(todo.priority(), 'A')
self.assertTrue(re.match(r'^\(A\) Foo$', todo.src))
def test_set_priority4(self):
......@@ -173,7 +173,7 @@ class TodoBaseTester(TopydoTest):
todo.set_priority('B')
self.assertEquals(todo.priority(), 'B')
self.assertEqual(todo.priority(), 'B')
self.assertTrue(re.match(r'^\(B\) \(A\)Foo$', todo.src))
def test_set_priority5(self):
......@@ -181,7 +181,7 @@ class TodoBaseTester(TopydoTest):
todo = TodoBase("(A) Foo")
todo.set_priority(None)
self.assertEquals(todo.priority(), None)
self.assertEqual(todo.priority(), None)
self.assertTrue(re.match(r'^Foo$', todo.src))
def test_set_priority6(self):
......@@ -190,32 +190,32 @@ class TodoBaseTester(TopydoTest):
todo.set_priority('A')
self.assertFalse(todo.priority())
self.assertEquals(todo.src, "x 2014-06-13 Foo")
self.assertEqual(todo.src, "x 2014-06-13 Foo")
def test_project1(self):
todo = TodoBase("(C) Foo +Bar +Baz +Bar:")
self.assertEquals(len(todo.projects()), 2)
self.assertEqual(len(todo.projects()), 2)
self.assertIn('Bar', todo.projects())
self.assertIn('Baz', todo.projects())
def test_project2(self):
todo = TodoBase("(C) Foo +Bar+Baz")
self.assertEquals(len(todo.projects()), 1)
self.assertEqual(len(todo.projects()), 1)
self.assertIn('Bar+Baz', todo.projects())
def test_context1(self):
todo = TodoBase("(C) Foo @Bar @Baz @Bar:")
self.assertEquals(len(todo.contexts()), 2)
self.assertEqual(len(todo.contexts()), 2)
self.assertIn('Bar', todo.contexts())
self.assertIn('Baz', todo.contexts())
def test_context2(self):
todo = TodoBase("(C) Foo @Bar+Baz")
self.assertEquals(len(todo.contexts()), 1)
self.assertEqual(len(todo.contexts()), 1)
self.assertIn('Bar+Baz', todo.contexts())
def test_completion1(self):
......@@ -248,7 +248,7 @@ class TodoBaseTester(TopydoTest):
today_str = today.isoformat()
self.assertFalse(todo.priority())
self.assertEquals(todo.fields['completionDate'], today)
self.assertEqual(todo.fields['completionDate'], today)
self.assertTrue(re.match('^x ' + today_str + ' Foo', todo.src))
def test_set_complete2(self):
......@@ -258,7 +258,7 @@ class TodoBaseTester(TopydoTest):
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
self.assertEqual(todo.fields['completionDate'], today)
self.assertTrue(re.match('^x ' + today_str + ' 2014-06-12 Foo', \
todo.src))
......@@ -269,7 +269,7 @@ class TodoBaseTester(TopydoTest):
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
self.assertEqual(todo.fields['completionDate'], today)
self.assertTrue(re.match('^x ' + today_str + ' Foo', todo.src))
def test_set_complete4(self):
......@@ -279,21 +279,21 @@ class TodoBaseTester(TopydoTest):
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
self.assertEqual(todo.fields['completionDate'], today)
self.assertTrue(re.match('^x ' + today_str + ' 2014-06-12 Foo', todo.src))
def test_set_complete5(self):
todo = TodoBase("x 2014-06-13 Foo")
todo.set_completed()
self.assertEquals(todo.src, "x 2014-06-13 Foo")
self.assertEqual(todo.src, "x 2014-06-13 Foo")
def test_set_complete6(self):
todo = TodoBase("Foo")
yesterday = date.today() - timedelta(1)
todo.set_completed(yesterday)
self.assertEquals(todo.src, "x {} Foo".format(yesterday.isoformat()))
self.assertEqual(todo.src, "x {} Foo".format(yesterday.isoformat()))
def test_set_source_text(self):
todo = TodoBase("(B) Foo")
......@@ -301,8 +301,8 @@ class TodoBaseTester(TopydoTest):
new_text = "(C) Foo"
todo.set_source_text(new_text)
self.assertEquals(todo.src, new_text)
self.assertEquals(todo.priority(),'C')
self.assertEqual(todo.src, new_text)
self.assertEqual(todo.priority(),'C')
def test_set_creation_date1(self):
todo = TodoBase("Foo")
......@@ -310,8 +310,8 @@ class TodoBaseTester(TopydoTest):
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "2014-07-24 Foo")
self.assertEqual(todo.creation_date(), creation_date)
self.assertEqual(todo.src, "2014-07-24 Foo")
def test_set_creation_date2(self):
todo = TodoBase("(A) Foo")
......@@ -319,8 +319,8 @@ class TodoBaseTester(TopydoTest):
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "(A) 2014-07-24 Foo")
self.assertEqual(todo.creation_date(), creation_date)
self.assertEqual(todo.src, "(A) 2014-07-24 Foo")
def test_set_creation_date3(self):
todo = TodoBase("(A) 2014-07-23 Foo")
......@@ -328,8 +328,8 @@ class TodoBaseTester(TopydoTest):
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "(A) 2014-07-24 Foo")
self.assertEqual(todo.creation_date(), creation_date)
self.assertEqual(todo.src, "(A) 2014-07-24 Foo")
def test_set_creation_date4(self):
todo = TodoBase("2014-07-23 Foo")
......@@ -337,8 +337,8 @@ class TodoBaseTester(TopydoTest):
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "2014-07-24 Foo")
self.assertEqual(todo.creation_date(), creation_date)
self.assertEqual(todo.src, "2014-07-24 Foo")
def test_set_creation_date5(self):
todo = TodoBase("x 2014-07-25 2014-07-23 Foo")
......@@ -346,8 +346,8 @@ class TodoBaseTester(TopydoTest):
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "x 2014-07-25 2014-07-24 Foo")
self.assertEqual(todo.creation_date(), creation_date)
self.assertEqual(todo.src, "x 2014-07-25 2014-07-24 Foo")
if __name__ == '__main__':
unittest.main()
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from six import u
import unittest
from test.TestFacilities import load_file
......@@ -23,7 +24,12 @@ class TodoFileTest(TopydoTest):
def test_empty_file(self):
todofile = load_file('test/data/TodoFileTest1.txt')
self.assertEquals(len(todofile), 0)
self.assertEqual(len(todofile), 0)
def test_utf_8(self):
todofile = load_file('test/data/utf-8.txt')
self.assertEqual(todofile[0].source(), u('(C) \u25ba UTF-8 test \u25c4'))
if __name__ == '__main__':
unittest.main()
......@@ -37,12 +37,12 @@ class TodoListTester(TopydoTest):
self.todolist = TodoList(lines)
def test_contexts(self):
self.assertEquals(set(['Context1', 'Context2']), \
self.assertEqual(set(['Context1', 'Context2']), \
self.todolist.contexts())
self.assertFalse(self.todolist.is_dirty())
def test_projects(self):
self.assertEquals(set(['Project1', 'Project2']), \
self.assertEqual(set(['Project1', 'Project2']), \
self.todolist.projects())
self.assertFalse(self.todolist.is_dirty())
......@@ -51,18 +51,18 @@ class TodoListTester(TopydoTest):
count = self.todolist.count()
todo = self.todolist.add(text)
self.assertEquals(self.todolist.todo(count+1).source(), text)
self.assertEquals(set(['Project1', 'Project2', 'Project3']), \
self.assertEqual(self.todolist.todo(count+1).source(), text)
self.assertEqual(set(['Project1', 'Project2', 'Project3']), \
self.todolist.projects())
self.assertEquals(set(['Context1', 'Context2', 'Context3']), \
self.assertEqual(set(['Context1', 'Context2', 'Context3']), \
self.todolist.contexts())
self.assertEquals(self.todolist.number(todo), 6)
self.assertEqual(self.todolist.number(todo), 6)
self.assertTrue(self.todolist.is_dirty())
def test_add2(self):
text = str(self.todolist)
self.todolist.add('')
self.assertEquals(str(self.todolist), text)
self.assertEqual(str(self.todolist), text)
def test_add3a(self):
count = self.todolist.count()
......@@ -83,21 +83,21 @@ class TodoListTester(TopydoTest):
def test_add4(self):
text = str(self.todolist)
self.todolist.add(' ')
self.assertEquals(str(self.todolist), text)
self.assertEqual(str(self.todolist), text)
def test_add5(self):
text = str(self.todolist)
self.todolist.add("\n")
self.assertEquals(str(self.todolist), text)
self.assertEqual(str(self.todolist), text)
def test_delete1(self):
count = self.todolist.count()
todo = self.todolist.todo(2)
self.todolist.delete(todo)
self.assertEquals(self.todolist.todo(2).source(), \
self.assertEqual(self.todolist.todo(2).source(), \
"(C) Baz @Context1 +Project1 key:value")
self.assertEquals(self.todolist.count(), count - 1)
self.assertEqual(self.todolist.count(), count - 1)
self.assertTrue(self.todolist.is_dirty())
self.assertRaises(InvalidTodoException, self.todolist.number, todo)
......@@ -105,9 +105,9 @@ class TodoListTester(TopydoTest):
todo = self.todolist.todo(3)
self.todolist.append(todo, "@Context3")
self.assertEquals(todo.source(), \
self.assertEqual(todo.source(), \
"(C) Baz @Context1 +Project1 key:value @Context3")
self.assertEquals(set(['Context1', 'Context2', 'Context3']), \
self.assertEqual(set(['Context1', 'Context2', 'Context3']), \
self.todolist.contexts())
self.assertTrue(self.todolist.is_dirty())
......@@ -116,8 +116,8 @@ class TodoListTester(TopydoTest):
text = todo.text()
self.todolist.append(todo, "foo:bar")
self.assertEquals(todo.text(), text)
self.assertEquals(todo.source(), \
self.assertEqual(todo.text(), text)
self.assertEqual(todo.source(), \
"(C) Baz @Context1 +Project1 key:value foo:bar")
def test_append3(self):
......@@ -125,7 +125,7 @@ class TodoListTester(TopydoTest):
text = todo.text()
self.todolist.append(todo, '')
self.assertEquals(todo.text(), text)
self.assertEqual(todo.text(), text)
def test_todo(self):
count = self.todolist.count()
......@@ -136,11 +136,11 @@ class TodoListTester(TopydoTest):
def test_string(self):
# readlines() always ends a string with \n, but join() in str(todolist)
# doesn't necessarily.
self.assertEquals(str(self.todolist) + '\n', self.text)
self.assertEqual(str(self.todolist) + '\n', self.text)
def test_count(self):
""" Test that empty lines are not counted. """
self.assertEquals(self.todolist.count(), 5)
self.assertEqual(self.todolist.count(), 5)
def test_todo_by_dep_id(self):
""" Tests that todos can be retrieved by their id tag. """
......@@ -155,7 +155,7 @@ class TodoListTester(TopydoTest):
todo = self.todolist.todo(6)
self.assertIsInstance(todo, Todo)
self.assertEquals(todo.text(), "No number")
self.assertEqual(todo.text(), "No number")
def test_todo_number2(self):
todo = Todo("Non-existent")
......@@ -171,7 +171,7 @@ class TodoListTester(TopydoTest):
todo = self.todolist.todo(1)
self.todolist.set_priority(todo, 'F')
self.assertEquals(self.todolist.todo(1).priority(), 'F')
self.assertEqual(self.todolist.todo(1).priority(), 'F')
self.assertTrue(self.todolist.is_dirty())
def test_todo_priority2(self):
......@@ -183,7 +183,7 @@ class TodoListTester(TopydoTest):
def test_erase(self):
self.todolist.erase()
self.assertEquals(self.todolist.count(), 0)
self.assertEqual(self.todolist.count(), 0)
self.assertTrue(self.todolist.is_dirty())
def test_regex1(self):
......@@ -193,20 +193,20 @@ class TodoListTester(TopydoTest):
def test_regex3(self):
todo = self.todolist.todo("project2")
self.assertTrue(todo)
self.assertEquals(todo.source(), "(D) Bar @Context1 +Project2")
self.assertEqual(todo.source(), "(D) Bar @Context1 +Project2")
def test_uid1(self):
config("test/data/todolist-uid.conf")
self.assertEquals(self.todolist.todo('6iu').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project")
self.assertEqual(self.todolist.todo('t5c').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project")
def test_uid2(self):
""" Changing the priority should not change the identifier. """
config("test/data/todolist-uid.conf")
todo = self.todolist.todo('6iu')
todo = self.todolist.todo('t5c')
self.todolist.set_priority(todo, 'B')
self.assertEquals(self.todolist.todo('6iu').source(), "(B) Foo @Context2 Not@Context +Project1 Not+Project")
self.assertEqual(self.todolist.todo('t5c').source(), "(B) Foo @Context2 Not@Context +Project1 Not+Project")
def test_uid3(self):
"""
......@@ -220,10 +220,10 @@ class TodoListTester(TopydoTest):
""" Make sure that item has new text ID after append. """
config("test/data/todolist-uid.conf")
todo = self.todolist.todo('6iu')
todo = self.todolist.todo('t5c')
self.todolist.append(todo, "A")
self.assertNotEquals(self.todolist.number(todo), '6iu')
self.assertNotEquals(self.todolist.number(todo), 't5c')
class TodoListDependencyTester(TopydoTest):
def setUp(self):
......@@ -299,7 +299,7 @@ class TodoListDependencyTester(TopydoTest):
self.todolist.add_dependency(todo6, todo7)
self.assertEquals(projects, todo7.projects())
self.assertEqual(projects, todo7.projects())
def test_add_dep4(self):
"""
......@@ -312,7 +312,7 @@ class TodoListDependencyTester(TopydoTest):
self.todolist.add_dependency(todo6, todo8)
self.assertEquals(set(["Project", "AnotherProject"]), todo8.projects())
self.assertEqual(set(["Project", "AnotherProject"]), todo8.projects())
def test_remove_dep1(self):
from_todo = self.todolist.todo(3)
......@@ -328,7 +328,7 @@ class TodoListDependencyTester(TopydoTest):
to_todo = self.todolist.todo(4)
self.todolist.remove_dependency(from_todo, to_todo)
self.assertEquals(str(self.todolist), old)
self.assertEqual(str(self.todolist), old)
def test_remove_todo_check_children(self):
todo = self.todolist.todo(2)
......
......@@ -34,7 +34,7 @@ class ViewTest(TopydoTest):
todofilter = Filter.GrepFilter('+Project')
view = todolist.view(sorter, [todofilter])
self.assertEquals(str(view), todolist_to_string(ref))
self.assertEqual(str(view), todolist_to_string(ref))
if __name__ == '__main__':
unittest.main()
......
(C) ► UTF-8 test ◄
......@@ -18,8 +18,12 @@
import getopt
import sys
from six.moves import input
USAGE = """\
def usage():
""" Prints the command-line usage of topydo. """
print("""\
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
topydo -h
topydo -v
......@@ -49,7 +53,7 @@ Available commands:
* tag
Run `topydo help <subcommand>` for command-specific help.
"""
""")
def write(p_file, p_string):
"""
......@@ -71,8 +75,8 @@ def error(p_string):
def version():
""" Print the current version and exit. """
from topydo.lib.Version import VERSION, LICENSE
print "topydo {}\n".format(VERSION)
print LICENSE
print("topydo {}\n".format(VERSION))
print(LICENSE)
sys.exit(0)
from topydo.lib.Config import config, ConfigError
......
......@@ -50,14 +50,14 @@ class EditCommand(MultiCommand, ListCommand):
def _todos_to_temp(self):
f = tempfile.NamedTemporaryFile()
for todo in self.todos:
f.write("%s\n" % todo.__str__())
f.write((str(todo) + "\n").encode('utf-8'))
f.seek(0)
return f
def _todos_from_temp(self, temp_file):
temp_file.seek(0)
todos = temp_file.read().splitlines()
def _todos_from_temp(self, p_temp_file):
p_temp_file.seek(0)
todos = p_temp_file.read().decode('utf-8').splitlines()
todo_objs = []
for todo in todos:
......@@ -65,10 +65,10 @@ class EditCommand(MultiCommand, ListCommand):
return todo_objs
def _open_in_editor(self, temp_file, editor):
def _open_in_editor(self, p_temp_file, p_editor):
try:
return check_call([editor, temp_file.name])
except(CalledProcessError):
return check_call([p_editor, p_temp_file.name])
except CalledProcessError:
self.error('Something went wrong in the editor...')
return 1
......
......@@ -40,6 +40,9 @@ class IcalCommand(ListCommand):
except ImportError:
self.error("icalendar package is not installed.")
return False
except SyntaxError:
self.error("icalendar is not supported in this Python version.")
return False
return super(IcalCommand, self).execute()
......@@ -60,11 +63,13 @@ For the supported options, please refer to the help text of 'ls'
While specifying the sort order is supported (-s flag), like in 'ls', this is
not meaningful in the context of an iCalendar file.
Note: be aware that this is not necessarily a read-only operation. This
Note 1 : be aware that this is not necessarily a read-only operation. This
subcommand may add ical tags to the printed todo items containing a unique ID.
Completed todo items may be archived.
Note: topydo does not support reading iCal files, this is merely a dump.
Note 2: topydo does not support reading iCal files, this is merely a dump.
Changes made with other iCalendar enabled applications will not be processed.
Suggested usage is to use the output as a read-only calendar.
Note 3: The ical subcommand only works for Python 2.7 and 3.3+.
"""
......@@ -28,7 +28,7 @@ class ListContextCommand(Command):
if not super(ListContextCommand, self).execute():
return False
for context in sorted(self.todolist.contexts(), key=str.lower):
for context in sorted(self.todolist.contexts(), key=lambda s: s.lower()):
self.out(context)
def usage(self):
......
......@@ -28,11 +28,11 @@ class ListProjectCommand(Command):
if not super(ListProjectCommand, self).execute():
return False
for project in sorted(self.todolist.projects(), key=str.lower):
for project in sorted(self.todolist.projects(), key=lambda s: s.lower()):
self.out(project)
def usage(self):
return """Synopsis: lscon"""
return """Synopsis: lsprj"""
def help(self):
return """Lists all projects in the todo list."""
......@@ -51,8 +51,10 @@ class TagCommand(Command):
self.todo = self.todolist.todo(self.argument(0))
self.tag = self.argument(1)
self.current_values = self.todo.tag_values(self.tag)
except (InvalidCommandArgument, InvalidTodoException):
except InvalidTodoException:
self.error("Invalid todo number.")
except InvalidCommandArgument:
self.error(self.usage())
try:
self.value = self.argument(2)
......
......@@ -16,7 +16,7 @@
import os
import ConfigParser
from six.moves import configparser
class ConfigError(Exception):
def __init__(self, p_text):
......@@ -66,7 +66,7 @@ class _Config:
self.config = {}
self.cp = ConfigParser.SafeConfigParser(self.defaults)
self.cp = configparser.ConfigParser(self.defaults)
files = [
"/etc/topydo.conf",
......@@ -90,7 +90,7 @@ class _Config:
self.cp.add_section(section)
def _home_config_path(self):
return os.path.join(os.getenv('HOME'), '.topydo')
return os.path.join(os.path.expanduser('~'), '.topydo')
def default_command(self):
return self.cp.get('topydo', 'default_command')
......@@ -188,7 +188,7 @@ def config(p_path=None):
if not config.instance or p_path != None:
try:
config.instance = _Config(p_path)
except ConfigParser.ParsingError as perr:
except configparser.ParsingError as perr:
raise ConfigError(str(perr))
return config.instance
......
......@@ -92,7 +92,7 @@ class DirectedGraph(object):
visited.add(current)
if p_reverse:
parents = [node for node, neighbors in self._edges.iteritems() \
parents = [node for node, neighbors in self._edges.items() \
if current in neighbors]
stack = stack + parents
......@@ -182,7 +182,7 @@ class DirectedGraph(object):
"""
removals = set()
for from_node, neighbors in self._edges.iteritems():
for from_node, neighbors in self._edges.items():
childpairs = \
[(c1, c2) for c1 in neighbors for c2 in neighbors if c1 != c2]
......@@ -198,7 +198,7 @@ class DirectedGraph(object):
""" Prints the graph in Dot format. """
out = 'digraph g {\n'
for from_node, neighbors in self._edges.iteritems():
for from_node, neighbors in self._edges.items():
out += " {}\n".format(from_node)
for neighbor in neighbors:
......
......@@ -19,8 +19,10 @@ Module that calculates identifiers for each item in a list, based on the hash
value of each item.
"""
from hashlib import sha1
_TABLE_SIZES = {
# we choose a large table size to reduce the change of collisions.
# we choose a large table size to reduce the chance of collisions.
3: 46649, # largest prime under zzz_36
4: 1679609 # largest prime under zzzz_36
}
......@@ -41,7 +43,7 @@ def _to_base36(p_value):
return base36 or alphabet[0]
def hash_list_values(p_list, p_hash=hash):
def hash_list_values(p_list, p_key=lambda i: i):
"""
Calculates a unique value for each item in the list, these can be used as
identifiers.
......@@ -61,8 +63,15 @@ def hash_list_values(p_list, p_hash=hash):
if len(p_list) < _TABLE_SIZES[3] * 0.01 else _TABLE_SIZES[4]
for item in p_list:
hash_value = p_hash(item) % size
# obtain the to-be-hashed value
raw_value = p_key(item)
# hash
hasher = sha1()
hasher.update(raw_value.encode('utf-8'))
hash_value = int(hasher.hexdigest(), 16) % size
# resolve possible collisions
while hash_value in used:
hash_value = (hash_value + 1) % size
......
......@@ -22,7 +22,10 @@ file according to RFC 2445.
try:
import icalendar as ical
ICAL_PRESENT = True
except ImportError:
except (SyntaxError, ImportError):
# icalendar does not support Python 3.2 resulting in a SyntaxError. Since
# this is an optional dependency, dropping Python 3.2 support altogether is
# too much. Therefore just disable the iCalendar functionality
ICAL_PRESENT = False
from datetime import datetime, time
......@@ -86,7 +89,7 @@ class IcalPrinter(Printer):
for todo in p_todos:
cal.add_component(self._convert_todo(todo))
result = cal.to_ical()
result = cal.to_ical().decode('utf-8')
return result
......@@ -105,7 +108,7 @@ class IcalPrinter(Printer):
"""
return ''.join(
random.choice(string.ascii_letters + string.digits)
for i in xrange(p_length))
for i in range(p_length))
uid = p_todo.tag_value('ical')
if not uid:
......
......@@ -29,7 +29,7 @@ def _add_months(p_sourcedate, p_months):
https://stackoverflow.com/questions/4130922/how-to-increment-datetime-month-in-python
"""
month = p_sourcedate.month - 1 + p_months
year = p_sourcedate.year + month / 12
year = p_sourcedate.year + month // 12
month = month % 12 + 1
day = min(p_sourcedate.day, calendar.monthrange(year, month)[1])
......
......@@ -100,7 +100,8 @@ class Sorter(object):
sorted_todos = p_todos
for function, order in reversed(self.functions):
sorted_todos = sorted(sorted_todos, None, function, order == 'desc')
sorted_todos = sorted(sorted_todos, key=function,
reverse=(order == 'desc'))
return sorted_todos
......
......@@ -18,6 +18,8 @@
This module deals with todo.txt files.
"""
import codecs
class TodoFile(object):
"""
This class represents a todo.txt file, which can be read from or written
......@@ -31,7 +33,7 @@ class TodoFile(object):
""" Reads the todo.txt file and returns a list of todo items. """
todos = []
try:
todofile = open(self.path, 'r')
todofile = codecs.open(self.path, 'r', encoding="utf-8")
todos = todofile.readlines()
todofile.close()
except IOError:
......
......@@ -249,7 +249,7 @@ class TodoListBase(object):
self._todo_id_map = {}
self._id_todo_map = {}
uids = hash_list_values(self._todos, lambda t: hash(t.text()))
uids = hash_list_values(self._todos, lambda t: t.text())
for (todo, uid) in uids:
self._todo_id_map[todo] = uid
......
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