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
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
install:
- "pip install ."
- "pip install icalendar"
......
......@@ -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'],
'edit-cmd-tests': ['mock'],
......
......@@ -19,11 +19,11 @@ import unittest
from topydo.lib import AddCommand
from topydo.lib import ListCommand
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.Config import config
from topydo.lib import TodoList
class AddCommandTest(CommandTest.CommandTest):
class AddCommandTest(CommandTest):
def setUp(self):
super(AddCommandTest, self).setUp()
self.todolist = TodoList.TodoList([])
......
......@@ -17,10 +17,10 @@
import unittest
from topydo.lib.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([])
......
......@@ -17,13 +17,13 @@
import unittest
from topydo.lib.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)
......
......@@ -16,7 +16,7 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.Config import config
from topydo.lib.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 = [
......
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.DepCommand import DepCommand
from topydo.lib.TodoList import TodoList
class DepCommandTest(CommandTest.CommandTest):
class DepCommandTest(CommandTest):
def setUp(self):
super(DepCommandTest, self).setUp()
todos = [
......
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.DepriCommand import DepriCommand
from topydo.lib.TodoList import TodoList
class DepriCommandTest(CommandTest.CommandTest):
class DepriCommandTest(CommandTest):
def setUp(self):
super(DepriCommandTest, self).setUp()
todos = [
......
......@@ -17,7 +17,7 @@
from datetime import date, timedelta
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.DoCommand import DoCommand
from topydo.lib.TodoList import TodoList
......@@ -27,7 +27,7 @@ def _yes_prompt(self):
def _no_prompt(self):
return "n"
class DoCommandTest(CommandTest.CommandTest):
class DoCommandTest(CommandTest):
def setUp(self):
super(DoCommandTest, self).setUp()
todos = [
......
......@@ -17,12 +17,12 @@
import unittest
import mock
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.EditCommand import EditCommand
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 = [
......@@ -70,7 +70,7 @@ class EditCommandTest(CommandTest.CommandTest):
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())
......@@ -83,7 +83,7 @@ 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())
......@@ -97,7 +97,7 @@ 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())
......
......@@ -18,14 +18,14 @@ import re
import unittest
from topydo.lib.Config import config
import CommandTest
from test.CommandTest import CommandTest
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):
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 replace_ical_tags(p_text):
......
......@@ -17,14 +17,14 @@
import unittest
from topydo.lib.Config import config
import CommandTest
from test.CommandTest import CommandTest
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):
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):
command = ListCommand([""], self.todolist, self.out, self.error)
......
......@@ -16,13 +16,13 @@
import unittest
import CommandTest
import TestFacilities
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
from topydo.lib.ListContextCommand import ListContextCommand
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()
......@@ -30,7 +30,7 @@ class ListContextCommandTest(CommandTest.CommandTest):
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()
......
......@@ -16,25 +16,25 @@
import unittest
import CommandTest
import TestFacilities
from test.CommandTest import CommandTest
from test.TestFacilities import load_file_to_todolist
from topydo.lib.ListProjectCommand import ListProjectCommand
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.assertEquals(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.assertEquals(self.output, "Project1\nProject2\n")
self.assertFalse(self.errors)
def test_help(self):
......
......@@ -17,11 +17,11 @@
from datetime import date, timedelta
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.PostponeCommand import PostponeCommand
from topydo.lib.TodoList import TodoList
class PostponeCommandTest(CommandTest.CommandTest):
class PostponeCommandTest(CommandTest):
def setUp(self):
super(PostponeCommandTest, self).setUp()
self.today = date.today()
......
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.PriorityCommand import PriorityCommand
from topydo.lib.TodoList import TodoList
class PriorityCommandTest(CommandTest.CommandTest):
class PriorityCommandTest(CommandTest):
def setUp(self):
super(PriorityCommandTest, self).setUp()
todos = [
......
......@@ -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()
......
......@@ -16,15 +16,15 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.Config import config
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):
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 """
......
......@@ -16,11 +16,11 @@
import unittest
import CommandTest
from test.CommandTest import CommandTest
from topydo.lib.TagCommand import TagCommand
from topydo.lib.TodoList import TodoList
class TagCommandTest(CommandTest.CommandTest):
class TagCommandTest(CommandTest):
def setUp(self):
super(TagCommandTest, self).setUp()
todos = [
......
......@@ -18,11 +18,12 @@
import getopt
import sys
from six.moves import input
def usage():
""" Prints the command-line usage of topydo. """
print """\
print("""\
Synopsis: topydo [-c <config>] [-d <archive>] [-t <todo.txt>] subcommand [help|args]
topydo -h
topydo -v
......@@ -52,7 +53,7 @@ Available commands:
* tag
Run `topydo help <subcommand>` for command-specific help.
"""
""")
sys.exit(0)
......@@ -76,8 +77,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
......@@ -173,7 +174,7 @@ class CLIApplication(object):
self.todolist,
lambda o: write(sys.stdout, o),
error,
raw_input)
input)
return False if command.execute() == False else True
......
......@@ -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.SafeConfigParser(self.defaults)
files = [
"/etc/topydo.conf",
......@@ -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
......
......@@ -50,7 +50,7 @@ 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
......
......@@ -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:
......
......@@ -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
......
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