File indexing completed on 2024-05-19 05:21:55

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 
0020 def test_active_tasks(app_testfile):
0021     app_testfile.addTask('Task1')
0022     app_testfile.addTask('Task1')
0023     app_testfile.addTask('Task2')
0024 
0025     tasks1 = app_testfile.taskIdsFromName('Task1')
0026     tasks2 = app_testfile.taskIdsFromName('Task2')
0027 
0028     for task_id in tasks1 + tasks2:
0029         app_testfile.startTimerFor(task_id)
0030     assert app_testfile.activeTasks() == ['Task2', 'Task1', 'Task1']
0031     assert app_testfile.tasks() == ['Task2', 'Task1', 'Task1']
0032 
0033     for task_id in tasks2:
0034         app_testfile.stopTimerFor(task_id)
0035     assert app_testfile.activeTasks() == ['Task1', 'Task1']
0036     assert app_testfile.tasks() == ['Task2', 'Task1', 'Task1']
0037 
0038     assert app_testfile.isActive(tasks1[0]) == True
0039     assert app_testfile.isActive(tasks2[0]) == False
0040 
0041     assert app_testfile.isTaskNameActive('Task1') == True
0042     assert app_testfile.isTaskNameActive('Task2') == False
0043 
0044 
0045 def test_start_stop_by_name(app_testfile):
0046     app_testfile.addTask('Task1')
0047     app_testfile.addTask('Task1')
0048     app_testfile.addTask('Task2')
0049 
0050     # startTimerForTaskName() starts only one task if there are duplicate names.
0051     assert app_testfile.startTimerForTaskName('Task1') == True
0052     assert app_testfile.startTimerForTaskName('Task2') == True
0053     assert app_testfile.activeTasks() == ['Task2', 'Task1']
0054 
0055     assert app_testfile.stopTimerForTaskName('Task2') == True
0056     assert app_testfile.activeTasks() == ['Task1']
0057 
0058 
0059 def test_stop_all_times(app_testfile):
0060     app_testfile.addTask('Task1')
0061     app_testfile.addTask('Task1')
0062     app_testfile.addTask('Task2')
0063 
0064     for task_id in app_testfile.taskIdsFromName('Task1') + app_testfile.taskIdsFromName('Task2'):
0065         app_testfile.startTimerFor(task_id)
0066     assert len(app_testfile.activeTasks()) == 3
0067 
0068     app_testfile.stopAllTimersDBUS()
0069     assert app_testfile.activeTasks() == []
0070     assert len(app_testfile.tasks()) == 3
0071 
0072 
0073 def test_set_percent_complete(app_testfile):
0074     app_testfile.addTask('Task1')
0075     task_id = app_testfile.taskIdsFromName('Task1')[0]
0076 
0077     app_testfile.startTimerFor(task_id)
0078     assert app_testfile.activeTasks() == ['Task1']
0079 
0080     app_testfile.setPercentComplete(task_id, 99)
0081     assert app_testfile.activeTasks() == ['Task1']
0082 
0083     # Task completion also stop the timer
0084     app_testfile.setPercentComplete(task_id, 100)
0085     assert app_testfile.activeTasks() == []