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 @@
from datetime import date
import unittest
from six import u
from topydo.commands import AddCommand
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 import TodoList
......@@ -234,6 +235,13 @@ class AddCommandTest(CommandTest):
self.assertEqual(self.output, "")
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):
command = AddCommand.AddCommand(["help"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
from six import PY2
from topydo.lib.Utils import escape_ansi
from test.TopydoTest import TopydoTest
......@@ -33,5 +34,13 @@ class CommandTest(TopydoTest):
if p_error:
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__':
unittest.main()
......@@ -14,12 +14,12 @@
# 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, PY2
from six import u
import unittest
from topydo.lib.Config import config
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
class ListCommandTest(CommandTest):
......@@ -188,13 +188,6 @@ class ListCommandTest(CommandTest):
self.assertEqual(self.output, "")
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):
def setUp(self):
super(ListCommandUnicodeTest, self).setUp()
......@@ -207,7 +200,7 @@ class ListCommandUnicodeTest(CommandTest):
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)
......
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