Commit de1a805d authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add test for adding a todo with special characters.

Also moved the utf8 utility to the superclass' module because more
command tests are using it now.
parent a73e5bfc
...@@ -16,10 +16,11 @@ ...@@ -16,10 +16,11 @@
from datetime import date from datetime import date
import unittest import unittest
from six import u
from topydo.commands import AddCommand from topydo.commands import AddCommand
from topydo.commands import ListCommand from topydo.commands import ListCommand
from test.CommandTest import CommandTest from test.CommandTest import CommandTest, utf8
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib import TodoList from topydo.lib import TodoList
...@@ -234,6 +235,13 @@ class AddCommandTest(CommandTest): ...@@ -234,6 +235,13 @@ class AddCommandTest(CommandTest):
self.assertEqual(self.output, "") self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_add_unicode(self):
command = AddCommand.AddCommand([u("Special \u25c4")], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, utf8(u("| 1| {} Special \u25c4\n").format(self.today)))
self.assertEqual(self.errors, "")
def test_help(self): def test_help(self):
command = AddCommand.AddCommand(["help"], self.todolist, self.out, self.error) command = AddCommand.AddCommand(["help"], self.todolist, self.out, self.error)
command.execute() command.execute()
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest import unittest
from six import PY2
from topydo.lib.Utils import escape_ansi from topydo.lib.Utils import escape_ansi
from test.TopydoTest import TopydoTest from test.TopydoTest import TopydoTest
...@@ -33,5 +34,13 @@ class CommandTest(TopydoTest): ...@@ -33,5 +34,13 @@ class CommandTest(TopydoTest):
if p_error: if p_error:
self.errors += escape_ansi(p_error + "\n") self.errors += escape_ansi(p_error + "\n")
# utility for several commands
def utf8(p_string):
""" Converts a Unicode string to UTF-8 in case of Python 2. """
if PY2:
p_string = p_string.encode('utf-8')
return p_string
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from six import u, PY2 from six import u
import unittest import unittest
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.commands.ListCommand import ListCommand from topydo.commands.ListCommand import ListCommand
from test.CommandTest import CommandTest from test.CommandTest import CommandTest, utf8
from test.TestFacilities import load_file_to_todolist from test.TestFacilities import load_file_to_todolist
class ListCommandTest(CommandTest): class ListCommandTest(CommandTest):
...@@ -188,13 +188,6 @@ class ListCommandTest(CommandTest): ...@@ -188,13 +188,6 @@ class ListCommandTest(CommandTest):
self.assertEqual(self.output, "") self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n") self.assertEqual(self.errors, command.usage() + "\n\n" + command.help() + "\n")
def _utf8(p_string):
""" Converts a Unicode string to UTF-8 in case of Python 2. """
if PY2:
p_string = p_string.encode('utf-8')
return p_string
class ListCommandUnicodeTest(CommandTest): class ListCommandUnicodeTest(CommandTest):
def setUp(self): def setUp(self):
super(ListCommandUnicodeTest, self).setUp() super(ListCommandUnicodeTest, self).setUp()
...@@ -207,7 +200,7 @@ class ListCommandUnicodeTest(CommandTest): ...@@ -207,7 +200,7 @@ class ListCommandUnicodeTest(CommandTest):
self.assertFalse(self.todolist.is_dirty()) self.assertFalse(self.todolist.is_dirty())
expected = _utf8(u("| 1| (C) And some sp\u00e9cial tag:\u25c4\n")) expected = utf8(u("| 1| (C) And some sp\u00e9cial tag:\u25c4\n"))
self.assertEqual(self.output, expected) self.assertEqual(self.output, expected)
......
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