Commit 2d3816bd authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add initial support for Python 3.

Still some test cases are failing, but the basic functionality seems to
werk.
parent 397bcd9d
language: python language: python
python: python:
- "2.7" - "2.7"
- "3.2"
- "3.3"
- "3.4"
install: install:
- "pip install ." - "pip install ."
- "pip install icalendar" - "pip install icalendar"
......
...@@ -8,6 +8,9 @@ setup( ...@@ -8,6 +8,9 @@ setup(
author = "Bram Schoenmakers", author = "Bram Schoenmakers",
author_email = "me@bramschoenmakers.nl", author_email = "me@bramschoenmakers.nl",
url = "https://github.com/bram85/topydo", url = "https://github.com/bram85/topydo",
install_requires = [
'six',
],
extras_require = { extras_require = {
'ical': ['icalendar'], 'ical': ['icalendar'],
'edit-cmd-tests': ['mock'], 'edit-cmd-tests': ['mock'],
......
...@@ -19,11 +19,11 @@ import unittest ...@@ -19,11 +19,11 @@ import unittest
from topydo.lib import AddCommand from topydo.lib import AddCommand
from topydo.lib import ListCommand from topydo.lib import ListCommand
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib import TodoList from topydo.lib import TodoList
class AddCommandTest(CommandTest.CommandTest): class AddCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(AddCommandTest, self).setUp() super(AddCommandTest, self).setUp()
self.todolist = TodoList.TodoList([]) self.todolist = TodoList.TodoList([])
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
import unittest import unittest
from topydo.lib.AppendCommand import AppendCommand from topydo.lib.AppendCommand import AppendCommand
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class AppendCommandTest(CommandTest.CommandTest): class AppendCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(AppendCommandTest, self).setUp() super(AppendCommandTest, self).setUp()
self.todolist = TodoList([]) self.todolist = TodoList([])
......
...@@ -17,13 +17,13 @@ ...@@ -17,13 +17,13 @@
import unittest import unittest
from topydo.lib.ArchiveCommand import ArchiveCommand from topydo.lib.ArchiveCommand import ArchiveCommand
import CommandTest from test.CommandTest import CommandTest
import TestFacilities from test.TestFacilities import load_file_to_todolist
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class ArchiveCommandTest(CommandTest.CommandTest): class ArchiveCommandTest(CommandTest):
def test_archive(self): 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([]) archive = TodoList([])
command = ArchiveCommand(todolist, archive) command = ArchiveCommand(todolist, archive)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.DeleteCommand import DeleteCommand from topydo.lib.DeleteCommand import DeleteCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
...@@ -28,7 +28,7 @@ def _yes_prompt(self): ...@@ -28,7 +28,7 @@ def _yes_prompt(self):
def _no_prompt(self): def _no_prompt(self):
return "n" return "n"
class DeleteCommandTest(CommandTest.CommandTest): class DeleteCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(DeleteCommandTest, self).setUp() super(DeleteCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.DepCommand import DepCommand from topydo.lib.DepCommand import DepCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class DepCommandTest(CommandTest.CommandTest): class DepCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(DepCommandTest, self).setUp() super(DepCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.DepriCommand import DepriCommand from topydo.lib.DepriCommand import DepriCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class DepriCommandTest(CommandTest.CommandTest): class DepriCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(DepriCommandTest, self).setUp() super(DepriCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
from datetime import date, timedelta from datetime import date, timedelta
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.DoCommand import DoCommand from topydo.lib.DoCommand import DoCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
...@@ -27,7 +27,7 @@ def _yes_prompt(self): ...@@ -27,7 +27,7 @@ def _yes_prompt(self):
def _no_prompt(self): def _no_prompt(self):
return "n" return "n"
class DoCommandTest(CommandTest.CommandTest): class DoCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(DoCommandTest, self).setUp() super(DoCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
import unittest import unittest
import mock import mock
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.EditCommand import EditCommand from topydo.lib.EditCommand import EditCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
from topydo.lib.Todo import Todo from topydo.lib.Todo import Todo
class EditCommandTest(CommandTest.CommandTest): class EditCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(EditCommandTest, self).setUp() super(EditCommandTest, self).setUp()
todos = [ todos = [
...@@ -70,7 +70,7 @@ class EditCommandTest(CommandTest.CommandTest): ...@@ -70,7 +70,7 @@ class EditCommandTest(CommandTest.CommandTest):
def test_edit4(self): def test_edit4(self):
""" Throw an error with pointing invalid argument. """ """ 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() command.execute()
self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.todolist.is_dirty())
...@@ -83,7 +83,7 @@ class EditCommandTest(CommandTest.CommandTest): ...@@ -83,7 +83,7 @@ class EditCommandTest(CommandTest.CommandTest):
mock_open_in_editor.return_value = 0 mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Only one line')] 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() command.execute()
self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.todolist.is_dirty())
...@@ -97,7 +97,7 @@ class EditCommandTest(CommandTest.CommandTest): ...@@ -97,7 +97,7 @@ class EditCommandTest(CommandTest.CommandTest):
mock_open_in_editor.return_value = 0 mock_open_in_editor.return_value = 0
mock_todos_from_temp.return_value = [Todo('Lazy Cat'), Todo('Lazy Dog')] 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() command.execute()
self.assertTrue(self.todolist.is_dirty()) self.assertTrue(self.todolist.is_dirty())
......
...@@ -18,14 +18,14 @@ import re ...@@ -18,14 +18,14 @@ import re
import unittest import unittest
from topydo.lib.Config import config from topydo.lib.Config import config
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.IcalCommand import IcalCommand from topydo.lib.IcalCommand import IcalCommand
import TestFacilities from test.TestFacilities import load_file_to_todolist
class IcalCommandTest(CommandTest.CommandTest): class IcalCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(IcalCommandTest, self).setUp() 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")
def test_ical(self): def test_ical(self):
def replace_ical_tags(p_text): def replace_ical_tags(p_text):
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
import unittest import unittest
from topydo.lib.Config import config from topydo.lib.Config import config
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.ListCommand import ListCommand from topydo.lib.ListCommand import ListCommand
import TestFacilities from test.TestFacilities import load_file_to_todolist
class ListCommandTest(CommandTest.CommandTest): class ListCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(ListCommandTest, self).setUp() super(ListCommandTest, self).setUp()
self.todolist = TestFacilities.load_file_to_todolist("test/data/ListCommandTest.txt") self.todolist = load_file_to_todolist("test/data/ListCommandTest.txt")
def test_list1(self): def test_list1(self):
command = ListCommand([""], self.todolist, self.out, self.error) command = ListCommand([""], self.todolist, self.out, self.error)
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
import TestFacilities from test.TestFacilities import load_file_to_todolist
from topydo.lib.ListContextCommand import ListContextCommand from topydo.lib.ListContextCommand import ListContextCommand
class ListContextCommandTest(CommandTest.CommandTest): class ListContextCommandTest(CommandTest):
def test_contexts1(self): 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 = ListContextCommand([""], todolist, self.out, self.error)
command.execute() command.execute()
...@@ -30,7 +30,7 @@ class ListContextCommandTest(CommandTest.CommandTest): ...@@ -30,7 +30,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("test/data/TodoListTest.txt") todolist = 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()
......
...@@ -16,25 +16,25 @@ ...@@ -16,25 +16,25 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
import TestFacilities from test.TestFacilities import load_file_to_todolist
from topydo.lib.ListProjectCommand import ListProjectCommand from topydo.lib.ListProjectCommand import ListProjectCommand
class ListProjectCommandTest(CommandTest.CommandTest): class ListProjectCommandTest(CommandTest):
def test_projects1(self): 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 = ListProjectCommand([""], todolist, self.out, self.error)
command.execute() command.execute()
self.assertEquals(self.output,"Project1\nProject2\n") self.assertEquals(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_projects2(self): 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 = ListProjectCommand(["aaa"], todolist, self.out, self.error)
command.execute() command.execute()
self.assertEquals(self.output,"Project1\nProject2\n") self.assertEquals(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors) self.assertFalse(self.errors)
def test_help(self): def test_help(self):
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
from datetime import date, timedelta from datetime import date, timedelta
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.PostponeCommand import PostponeCommand from topydo.lib.PostponeCommand import PostponeCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class PostponeCommandTest(CommandTest.CommandTest): class PostponeCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(PostponeCommandTest, self).setUp() super(PostponeCommandTest, self).setUp()
self.today = date.today() self.today = date.today()
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.PriorityCommand import PriorityCommand from topydo.lib.PriorityCommand import PriorityCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class PriorityCommandTest(CommandTest.CommandTest): class PriorityCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(PriorityCommandTest, self).setUp() super(PriorityCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -18,9 +18,9 @@ from datetime import date, timedelta ...@@ -18,9 +18,9 @@ from datetime import date, timedelta
import unittest import unittest
from topydo.lib.RelativeDate import relative_date_to_date 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): def setUp(self):
super(RelativeDateTester, self).setUp() super(RelativeDateTester, self).setUp()
self.today = date.today() self.today = date.today()
......
...@@ -16,15 +16,15 @@ ...@@ -16,15 +16,15 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.SortCommand import SortCommand from topydo.lib.SortCommand import SortCommand
import TestFacilities from test.TestFacilities import load_file_to_todolist
class SortCommandTest(CommandTest.CommandTest): class SortCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(SortCommandTest, self).setUp() 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): def test_sort1(self):
""" Alphabetically sorted """ """ Alphabetically sorted """
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
import unittest import unittest
import CommandTest from test.CommandTest import CommandTest
from topydo.lib.TagCommand import TagCommand from topydo.lib.TagCommand import TagCommand
from topydo.lib.TodoList import TodoList from topydo.lib.TodoList import TodoList
class TagCommandTest(CommandTest.CommandTest): class TagCommandTest(CommandTest):
def setUp(self): def setUp(self):
super(TagCommandTest, self).setUp() super(TagCommandTest, self).setUp()
todos = [ todos = [
......
...@@ -18,11 +18,12 @@ ...@@ -18,11 +18,12 @@
import getopt import getopt
import sys import sys
from six.moves import input
def usage(): def usage():
""" Prints the command-line usage of topydo. """ """ Prints the command-line usage of topydo. """
print """\ print("""\
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args] Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
topydo -h topydo -h
topydo -v topydo -v
...@@ -52,7 +53,7 @@ Available commands: ...@@ -52,7 +53,7 @@ Available commands:
* tag * tag
Run `topydo help <subcommand>` for command-specific help. Run `topydo help <subcommand>` for command-specific help.
""" """)
sys.exit(0) sys.exit(0)
...@@ -76,8 +77,8 @@ def error(p_string): ...@@ -76,8 +77,8 @@ def error(p_string):
def version(): def version():
""" Print the current version and exit. """ """ Print the current version and exit. """
from topydo.lib.Version import VERSION, LICENSE from topydo.lib.Version import VERSION, LICENSE
print "topydo {}\n".format(VERSION) print("topydo {}\n".format(VERSION))
print LICENSE print(LICENSE)
sys.exit(0) sys.exit(0)
from topydo.lib.Config import config, ConfigError from topydo.lib.Config import config, ConfigError
...@@ -173,7 +174,7 @@ class CLIApplication(object): ...@@ -173,7 +174,7 @@ class CLIApplication(object):
self.todolist, self.todolist,
lambda o: write(sys.stdout, o), lambda o: write(sys.stdout, o),
error, error,
raw_input) input)
return False if command.execute() == False else True return False if command.execute() == False else True
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import os import os
import ConfigParser from six.moves import configparser
class ConfigError(Exception): class ConfigError(Exception):
def __init__(self, p_text): def __init__(self, p_text):
...@@ -66,7 +66,7 @@ class _Config: ...@@ -66,7 +66,7 @@ class _Config:
self.config = {} self.config = {}
self.cp = ConfigParser.SafeConfigParser(self.defaults) self.cp = configparser.SafeConfigParser(self.defaults)
files = [ files = [
"/etc/topydo.conf", "/etc/topydo.conf",
...@@ -188,7 +188,7 @@ def config(p_path=None): ...@@ -188,7 +188,7 @@ def config(p_path=None):
if not config.instance or p_path != None: if not config.instance or p_path != None:
try: try:
config.instance = _Config(p_path) config.instance = _Config(p_path)
except ConfigParser.ParsingError as perr: except configparser.ParsingError as perr:
raise ConfigError(str(perr)) raise ConfigError(str(perr))
return config.instance return config.instance
......
...@@ -50,7 +50,7 @@ class EditCommand(MultiCommand, ListCommand): ...@@ -50,7 +50,7 @@ class EditCommand(MultiCommand, ListCommand):
def _todos_to_temp(self): def _todos_to_temp(self):
f = tempfile.NamedTemporaryFile() f = tempfile.NamedTemporaryFile()
for todo in self.todos: for todo in self.todos:
f.write("%s\n" % todo.__str__()) f.write((str(todo) + "\n").encode('utf-8'))
f.seek(0) f.seek(0)
return f return f
......
...@@ -92,7 +92,7 @@ class DirectedGraph(object): ...@@ -92,7 +92,7 @@ class DirectedGraph(object):
visited.add(current) visited.add(current)
if p_reverse: 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] if current in neighbors]
stack = stack + parents stack = stack + parents
...@@ -182,7 +182,7 @@ class DirectedGraph(object): ...@@ -182,7 +182,7 @@ class DirectedGraph(object):
""" """
removals = set() removals = set()
for from_node, neighbors in self._edges.iteritems(): for from_node, neighbors in self._edges.items():
childpairs = \ childpairs = \
[(c1, c2) for c1 in neighbors for c2 in neighbors if c1 != c2] [(c1, c2) for c1 in neighbors for c2 in neighbors if c1 != c2]
...@@ -198,7 +198,7 @@ class DirectedGraph(object): ...@@ -198,7 +198,7 @@ class DirectedGraph(object):
""" Prints the graph in Dot format. """ """ Prints the graph in Dot format. """
out = 'digraph g {\n' 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) out += " {}\n".format(from_node)
for neighbor in neighbors: for neighbor in neighbors:
......
...@@ -100,7 +100,8 @@ class Sorter(object): ...@@ -100,7 +100,8 @@ class Sorter(object):
sorted_todos = p_todos sorted_todos = p_todos
for function, order in reversed(self.functions): 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 return sorted_todos
......
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