diff --git a/test/test_active_tasks.py b/test/test_active_tasks.py new file mode 100644 index 0000000..94eed86 --- /dev/null +++ b/test/test_active_tasks.py @@ -0,0 +1,85 @@ +# Copyright (c) 2019 Alexander Potashev +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License or (at your option) version 3 or any later version +# accepted by the membership of KDE e.V. (or its successor approved +# by the membership of KDE e.V.), which shall act as a proxy +# defined in Section 14 of version 3 of the license. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +def test_active_tasks(app_testfile): + app_testfile.addTask('Task1') + app_testfile.addTask('Task1') + app_testfile.addTask('Task2') + + tasks1 = app_testfile.taskIdsFromName('Task1') + tasks2 = app_testfile.taskIdsFromName('Task2') + + for task_id in tasks1 + tasks2: + app_testfile.startTimerFor(task_id) + assert app_testfile.activeTasks() == ['Task2', 'Task1', 'Task1'] + assert app_testfile.tasks() == ['Task2', 'Task1', 'Task1'] + + for task_id in tasks2: + app_testfile.stopTimerFor(task_id) + assert app_testfile.activeTasks() == ['Task1', 'Task1'] + assert app_testfile.tasks() == ['Task2', 'Task1', 'Task1'] + + assert app_testfile.isActive(tasks1[0]) == True + assert app_testfile.isActive(tasks2[0]) == False + + assert app_testfile.isTaskNameActive('Task1') == True + assert app_testfile.isTaskNameActive('Task2') == False + + +def test_start_stop_by_name(app_testfile): + app_testfile.addTask('Task1') + app_testfile.addTask('Task1') + app_testfile.addTask('Task2') + + # startTimerForTaskName() starts only one task if there are duplicate names. + assert app_testfile.startTimerForTaskName('Task1') == True + assert app_testfile.startTimerForTaskName('Task2') == True + assert app_testfile.activeTasks() == ['Task2', 'Task1'] + + assert app_testfile.stopTimerForTaskName('Task2') == True + assert app_testfile.activeTasks() == ['Task1'] + + +def test_stop_all_times(app_testfile): + app_testfile.addTask('Task1') + app_testfile.addTask('Task1') + app_testfile.addTask('Task2') + + for task_id in app_testfile.taskIdsFromName('Task1') + app_testfile.taskIdsFromName('Task2'): + app_testfile.startTimerFor(task_id) + assert len(app_testfile.activeTasks()) == 3 + + app_testfile.stopAllTimersDBUS() + assert app_testfile.activeTasks() == [] + assert len(app_testfile.tasks()) == 3 + + +def test_set_percent_complete(app_testfile): + app_testfile.addTask('Task1') + task_id = app_testfile.taskIdsFromName('Task1')[0] + + app_testfile.startTimerFor(task_id) + assert app_testfile.activeTasks() == ['Task1'] + + app_testfile.setPercentComplete(task_id, 99) + assert app_testfile.activeTasks() == ['Task1'] + + # Task completion also stop the timer + app_testfile.setPercentComplete(task_id, 100) + assert app_testfile.activeTasks() == [] diff --git a/test/test_benchmark.py b/test/test_benchmark.py index 70c1d9b..c883071 100644 --- a/test/test_benchmark.py +++ b/test/test_benchmark.py @@ -1,39 +1,40 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + # Old comments from Bash-based benchmark: # This is a bash script for a ktimetracker benchmark - how fast is ktimetracker on your system ? # example: my 2.4GHz Quad-core X64 computer with 4GB RAM needs 50 seconds def run(app): for n in range(2): # add 300 tasks for i in range(300): name = 'task%d-%03d' % (n, i) app.addTask(name) ids = app.taskIdsFromName(name) assert len(ids) == 1 app.startTimerFor(ids[0]) app.saveAll() app.stopAllTimersDBUS() def test_benchmark(benchmark, app_testfile): benchmark.pedantic(run, args=(app_testfile,)) diff --git a/test/test_booktime.py b/test/test_booktime.py index 7e9ee5f..f988f91 100644 --- a/test/test_booktime.py +++ b/test/test_booktime.py @@ -1,55 +1,54 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def test_bad_date(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] retval = app_testfile.bookTime(task_id, 'notadate', 360) assert retval == 5 def test_bad_duration(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] retval = app_testfile.bookTime(task_id, '20050619', -5) assert retval == 7 def test_bad_time(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] retval = app_testfile.bookTime(task_id, '20050619Tabc', 360) assert retval == 5 def test_bad_uid(app_testfile): app_testfile.addTask('Task1') retval = app_testfile.bookTime('bad-uid', '20050619', 360) assert retval == 4 def test_valid(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] duration = 12 - retval = app_testfile.bookTime(task_id, '2005-06-19', duration) - assert retval == 0 + assert app_testfile.bookTime(task_id, '2005-06-19', duration) == 0 - retval = app_testfile.totalMinutesForTaskId(task_id) - assert retval == duration + assert app_testfile.totalMinutesForTaskId(task_id) == duration diff --git a/test/test_changetime.py b/test/test_changetime.py index 7b04da0..643e235 100644 --- a/test/test_changetime.py +++ b/test/test_changetime.py @@ -1,23 +1,26 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def test_change_time(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] retval = app_testfile.changeTime(task_id, 50) assert retval == 0 + + assert app_testfile.totalMinutesForTaskId(task_id) == 50 diff --git a/test/test_delete.py b/test/test_delete.py index 277b2dd..2cb497d 100644 --- a/test/test_delete.py +++ b/test/test_delete.py @@ -1,33 +1,38 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def test_delete(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] app_testfile.deleteTask(task_id) + assert app_testfile.tasks() == [] assert len(app_testfile.version()) > 0 def test_delete_parent(app_testfile): app_testfile.addTask('Task1') task_id = app_testfile.taskIdsFromName('Task1')[0] app_testfile.addSubTask('blah', task_id) app_testfile.deleteTask(task_id) + # Should delete both tasks: parent and child + assert app_testfile.tasks() == [] + assert len(app_testfile.version()) > 0 diff --git a/test/test_delete.py b/test/test_import_export.py similarity index 55% copy from test/test_delete.py copy to test/test_import_export.py index 277b2dd..baaba0a 100644 --- a/test/test_delete.py +++ b/test/test_import_export.py @@ -1,33 +1,46 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -def test_delete(app_testfile): - app_testfile.addTask('Task1') - task_id = app_testfile.taskIdsFromName('Task1')[0] - app_testfile.deleteTask(task_id) - assert len(app_testfile.version()) > 0 +import os +import tempfile + +def test_import(app_testfile): + app_testfile.importPlannerFile('invalid') + assert app_testfile.tasks() == [] -def test_delete_parent(app_testfile): + path = os.path.join(os.path.dirname(__file__), '../src/tests/data/kitchen.planner') + app_testfile.importPlannerFile(path) + assert len(app_testfile.tasks()) == 21 + + +def test_export(app_testfile): app_testfile.addTask('Task1') + app_testfile.addTask('Task2') + task_id = app_testfile.taskIdsFromName('Task1')[0] + app_testfile.changeTime(task_id, 135) - app_testfile.addSubTask('blah', task_id) - app_testfile.deleteTask(task_id) + fd, tempfile_path = tempfile.mkstemp(text=True) + app_testfile.exportCSVFile(tempfile_path, '', '', 0, False, True, '*', '<>') - assert len(app_testfile.version()) > 0 + with open(fd, closefd=True) as f: + lines = f.readlines() + assert len(lines) == 2 + assert lines[0] == '<>Task2<>*0:00*0:00*0:00*0:00\n' + assert lines[1] == '<>Task1<>*2:15*2:15*2:15*2:15\n' diff --git a/test/test_changetime.py b/test/test_samename_tasks.py similarity index 77% copy from test/test_changetime.py copy to test/test_samename_tasks.py index 7b04da0..685e181 100644 --- a/test/test_changetime.py +++ b/test/test_samename_tasks.py @@ -1,23 +1,27 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -def test_change_time(app_testfile): + +def test_same_name_tasks(app_testfile): + app_testfile.addTask('Task1') app_testfile.addTask('Task1') - task_id = app_testfile.taskIdsFromName('Task1')[0] - retval = app_testfile.changeTime(task_id, 50) - assert retval == 0 + task_ids = app_testfile.taskIdsFromName('Task1') + assert len(task_ids) == 2 + assert len(task_ids[0]) == 36 + assert len(task_ids[1]) == 36 + assert task_ids[0] != task_ids[1] diff --git a/test/test_version.py b/test/test_version.py index 47153e3..fb1e6d8 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -1,20 +1,21 @@ # Copyright (c) 2019 Alexander Potashev # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def test_delete_parent(app_testfile): assert len(app_testfile.version()) > 0