Commit 9f48c518 authored by Jacek Sowiński's avatar Jacek Sowiński

Add tests for adding todos from file with `add -f`

parent 47479b6d
......@@ -16,7 +16,9 @@
from datetime import date
import unittest
import mock
from six import u
from io import StringIO
from topydo.commands import AddCommand
from topydo.commands import ListCommand
......@@ -242,6 +244,21 @@ class AddCommandTest(CommandTest):
self.assertEqual(self.output, utf8(u("| 1| {} Special \u25c4\n").format(self.today)))
self.assertEqual(self.errors, "")
@mock.patch("topydo.commands.AddCommand.stdin", StringIO(u("Fo\u00f3 due:tod id:1\nB\u0105r before:1")))
def test_add_from_stdin(self):
command = AddCommand.AddCommand(["-f", "-"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, utf8(u("| 1| {tod} Fo\u00f3 due:{tod} id:1\n| 2| {tod} B\u0105r p:1\n".format(tod=self.today))))
self.assertEqual(self.errors, "")
def test_add_from_file(self):
command = AddCommand.AddCommand(["-f", "test/data/AddCommandTest-from_file.txt"], self.todolist, self.out, self.error)
command.execute()
self.assertEqual(self.output, utf8(u("| 1| {tod} Foo @fo\u00f3b\u0105r due:{tod} id:1\n| 2| {tod} Bar +baz t:{tod} p:1\n".format(tod=self.today))))
self.assertEqual(self.errors, "")
def test_help(self):
command = AddCommand.AddCommand(["help"], self.todolist, self.out, self.error)
command.execute()
......
Foo @foóbąr due:tod id:1
Bar +baz t:tod before:1
......@@ -19,6 +19,7 @@
from datetime import date
import re
from sys import stdin
import codecs
from topydo.lib.Config import config
from topydo.lib.Command import Command
......@@ -100,9 +101,9 @@ class AddCommand(Command):
if self.from_file == '-':
f = stdin
else:
f = open(self.from_file, 'r')
f = codecs.open(self.from_file, 'r', encoding='utf-8')
todos = f.read().decode('utf-8').splitlines()
todos = f.read().splitlines()
return 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