mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
tests: Add export_one and latest helpers to the Task test interface
- The 'export_one' method will export one task matching a filter, raising error if not exactly one task was matched. - The 'latest' property will return the task matching the "+LATEST" filter.
This commit is contained in:
parent
f5b9370623
commit
9fe7993d96
1 changed files with 26 additions and 0 deletions
|
@ -156,6 +156,32 @@ class Task(object):
|
|||
|
||||
return json.loads(out)
|
||||
|
||||
def export_one(self, export_filter=None):
|
||||
"""
|
||||
Return a dictionary representing the exported task. Will
|
||||
fail if mutliple tasks match the filter.
|
||||
"""
|
||||
|
||||
result = self.export(export_filter=export_filter)
|
||||
|
||||
if len(result) != 1:
|
||||
descriptions = [task.get('description') or '[description-missing]'
|
||||
for task in result]
|
||||
|
||||
raise ValueError(
|
||||
"One task should match the '{0}' filter, '{1}' "
|
||||
"matches:\n {2}".format(
|
||||
export_filter or '',
|
||||
len(result),
|
||||
'\n '.join(descriptions)
|
||||
))
|
||||
|
||||
return result[0]
|
||||
|
||||
@property
|
||||
def latest(self):
|
||||
return self.export_one("+LATEST")
|
||||
|
||||
@staticmethod
|
||||
def _split_string_args_if_string(args):
|
||||
"""Helper function to parse and split into arguments a single string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue