Commit 076e9852 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add new sort field for length of a todo item

parent 181b2743
1 No length (zero)
2016-04-25 2 No length (zero)
3 Length of 0 days t:2016-04-25 due:2016-04-25
4 Length of 0 days t:2016-04-25 due:2016-04-25
5 Length of 0 days tomorrow t:2016-04-26 due:2016-04-26
2016-04-25 1 Length of 1 day with creation due:2016-04-26
2 Length of 1 day t:2016-04-25 due:2016-04-26
2016-04-25 Length of 2 days with creation due:2016-04-27
4 Length of 0 days t:2016-04-25 due:2016-04-25
2016-04-25 2 No length (zero)
3 Length of 0 days t:2016-04-25 due:2016-04-25
5 Length of 0 days tomorrow t:2016-04-26 due:2016-04-26
2 Length of 1 day t:2016-04-25 due:2016-04-26
2016-04-25 Length of 2 days with creation due:2016-04-27
2016-04-25 1 Length of 1 day with creation due:2016-04-26
1 No length (zero)
......@@ -14,6 +14,7 @@
# 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 freezegun import freeze_time
import unittest
from test.facilities import (load_file, load_file_to_todolist, print_view,
......@@ -23,6 +24,7 @@ from topydo.lib.Config import config
from topydo.lib.Sorter import Sorter
@freeze_time("2016, 04, 25")
class SorterTest(TopydoTest):
def sort_file(self, p_filename, p_filename_ref, p_sorter):
"""
......@@ -189,5 +191,14 @@ class SorterTest(TopydoTest):
'test/data/SorterTest13-result-context.txt', sorter)
def test_sort18(self):
"""
Check sorting by length.
"""
sorter = Sorter('length,text')
self.sort_file('test/data/SorterTest14.txt',
'test/data/SorterTest14-result.txt', sorter)
if __name__ == '__main__':
unittest.main()
......@@ -52,6 +52,8 @@ def get_field_function(p_field):
result = importance
elif p_field == 'importance-avg' or p_field == 'importance-average':
result = average_importance
elif p_field == 'length':
result = lambda a: a.length()
elif p_field == 'project' or p_field == 'projects':
result = lambda a: sorted([c.lower() for c in a.projects()])
elif p_field == 'text':
......
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