File indexing completed on 2024-05-12 05:21:41

0001 # Copyright (c) 2019 Alexander Potashev <aspotashev@gmail.com>
0002 #
0003 # This program is free software; you can redistribute it and/or
0004 # modify it under the terms of the GNU General Public License as
0005 # published by the Free Software Foundation; either version 2 of
0006 # the License or (at your option) version 3 or any later version
0007 # accepted by the membership of KDE e.V. (or its successor approved
0008 # by the membership of KDE e.V.), which shall act as a proxy
0009 # defined in Section 14 of version 3 of the license.
0010 #
0011 # This program is distributed in the hope that it will be useful,
0012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 # GNU General Public License for more details.
0015 #
0016 # You should have received a copy of the GNU General Public License
0017 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 
0019 import os
0020 import tempfile
0021 
0022 
0023 def test_import(app_testfile):
0024     app_testfile.importPlannerFile('invalid')
0025     assert app_testfile.tasks() == []
0026 
0027     path = os.path.join(os.path.dirname(__file__), '../src/tests/data/kitchen.planner')
0028     app_testfile.importPlannerFile(path)
0029     assert len(app_testfile.tasks()) == 21
0030 
0031 
0032 def test_export(app_testfile):
0033     app_testfile.addTask('Task1')
0034     app_testfile.addTask('Task2')
0035 
0036     task_id = app_testfile.taskIdsFromName('Task1')[0]
0037     app_testfile.changeTime(task_id, 135)
0038 
0039     fd, tempfile_path = tempfile.mkstemp(text=True)
0040     app_testfile.exportCSVFile(tempfile_path, '', '', 0, False, True, '*', '<>')
0041 
0042     with open(fd, closefd=True) as f:
0043         lines = f.readlines()
0044         assert len(lines) == 2
0045         assert lines[0] == '<>Task2<>*0:00*0:00*0:00*0:00\n'
0046         assert lines[1] == '<>Task1<>*2:15*2:15*2:15*2:15\n'