import datetime
import itertools
import json
+import os
import pytz
import six
import shutil
class TasklibTest(unittest.TestCase):
+ def get_taskwarrior(self, **kwargs):
+ tw_kwargs = dict(
+ data_location=self.tmp,
+ taskrc_location='/',
+ )
+ tw_kwargs.update(kwargs)
+ return TaskWarrior(**tw_kwargs)
+
def setUp(self):
self.tmp = tempfile.mkdtemp(dir='.')
- self.tw = TaskWarrior(data_location=self.tmp, taskrc_location='/')
+ self.tw = self.get_taskwarrior()
def tearDown(self):
shutil.rmtree(self.tmp)
+class TaskWarriorTest(TasklibTest):
+
+ def test_custom_command(self):
+ # ensure that a custom command which contains multiple parts
+ # is properly split up
+ tw = self.get_taskwarrior(
+ task_command='wsl task',
+ # prevent `_get_version` from running as `wsl` may not exist
+ version_override=os.getenv('TASK_VERSION'),
+ )
+ self.assertEqual(tw._get_task_command(), ['wsl', 'task'])
+
+
class TaskFilterTest(TasklibTest):
def test_all_empty(self):
t = Task(self.tw, description='test')
t.save()
- self.assertEquals(t['description'], 'test')
+ self.assertEqual(t['description'], 'test')
t['description'] = 'test-modified'
t.save()
- self.assertEquals(t['description'], 'test-modified')
+ self.assertEqual(t['description'], 'test-modified')
def test_modify_simple_attribute_with_space(self):
# Space can pose problems with parsing
t = Task(self.tw, description='test task')
t.save()
- self.assertEquals(t['description'], 'test task')
+ self.assertEqual(t['description'], 'test task')
t['description'] = 'test task modified'
t.save()
- self.assertEquals(t['description'], 'test task modified')
+ self.assertEqual(t['description'], 'test task modified')
def test_empty_dependency_set_of_unsaved_task(self):
t = Task(self.tw, description='test task')
self.assertEqual(t['depends'], set([dependency]))
+ def test_set_simple_dependency_lazyuuidtaskset(self):
+ # Adds only one dependency as a LazyUUIDTaskSet to task with no dependencies
+ t = Task(self.tw, description='test task')
+ dependency = Task(self.tw, description='needs to be done first')
+
+ t.save()
+ dependency.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency['uuid']])
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency['uuid']]))
+
def test_set_complex_dependency_set(self):
# Adds two dependencies to task with no dependencies
t = Task(self.tw, description='test task')
self.assertEqual(t['depends'], set([dependency1, dependency2]))
+ def test_set_complex_dependency_lazyuuidtaskset(self):
+ # Adds two dependencies as a LazyUUIDTaskSet to task with no dependencies
+ t = Task(self.tw, description='test task')
+ dependency1 = Task(self.tw, description='needs to be done first')
+ dependency2 = Task(self.tw, description='needs to be done second')
+
+ t.save()
+ dependency1.save()
+ dependency2.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency1['uuid'], dependency2['uuid']])
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency1['uuid'], dependency2['uuid']]))
+
def test_remove_from_dependency_set(self):
# Removes dependency from task with two dependencies
t = Task(self.tw, description='test task')
self.assertEqual(t['depends'], set([dependency1]))
+ def test_remove_from_dependency_lazyuuidtaskset(self):
+ # Removes dependency from task with two dependencies as LazyUUIDTaskSet
+ t = Task(self.tw, description='test task')
+ dependency1 = Task(self.tw, description='needs to be done first')
+ dependency2 = Task(self.tw, description='needs to be done second')
+
+ dependency1.save()
+ dependency2.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency1['uuid'], dependency2['uuid']])
+ t.save()
+
+ t['depends'].remove(dependency2)
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency1['uuid']]))
+
def test_add_to_dependency_set(self):
# Adds dependency to task with one dependencies
t = Task(self.tw, description='test task')
self.assertEqual(t['depends'], set([dependency1, dependency2]))
+ def test_add_to_dependency_lazyuuidtaskset(self):
+ # Adds dependency to task with one dependencies as LazyUUIDTaskSet
+ t = Task(self.tw, description='test task')
+ dependency1 = Task(self.tw, description='needs to be done first')
+ dependency2 = Task(self.tw, description='needs to be done second')
+
+ dependency1.save()
+ dependency2.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency1['uuid']])
+ t.save()
+
+ t['depends'].add(dependency2)
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency1['uuid'], dependency2['uuid']]))
+
+ def test_add_lazyuuidtaskset_to_dependency_lazyuuidtaskset(self):
+ # Adds dependency as LazyUUIDTaskSet to task with one dependencies as LazyUUIDTaskSet
+ t = Task(self.tw, description='test task')
+ dependency1 = Task(self.tw, description='needs to be done first')
+ dependency2 = Task(self.tw, description='needs to be done second')
+
+ dependency1.save()
+ dependency2.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency1['uuid']])
+ t.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency2['uuid']]).union(t['depends'])
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency1['uuid'], dependency2['uuid']]))
+
def test_add_to_empty_dependency_set(self):
- # Adds dependency to task with one dependencies
+ # Adds dependency to task with no dependencies
t = Task(self.tw, description='test task')
dependency = Task(self.tw, description='needs to be done first')
self.assertEqual(t['depends'], set([dependency]))
+ def test_add_to_empty_dependency_lazyuuidtaskset(self):
+ # Adds dependency as LazyUUIDTaskSet to task with no dependencies
+ t = Task(self.tw, description='test task')
+ dependency = Task(self.tw, description='needs to be done first')
+
+ dependency.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency['uuid']])
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency['uuid']]))
+
def test_simple_dependency_set_save_repeatedly(self):
# Adds only one dependency to task with no dependencies
t = Task(self.tw, description='test task')
self.assertEqual(t['depends'], set([dependency]))
+ def test_simple_dependency_lazyuuidtaskset_save_repeatedly(self):
+ # Adds only one dependency as LazyUUIDTaskSet to task with no dependencies
+ t = Task(self.tw, description='test task')
+ dependency = Task(self.tw, description='needs to be done first')
+ dependency.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency['uuid']])
+ t.save()
+
+ # We taint the task, but keep depends intact
+ t['description'] = 'test task modified'
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency['uuid']]))
+
+ # We taint the task, but assign the same set to the depends
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency['uuid']])
+ t['description'] = 'test task modified again'
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency['uuid']]))
+
+ def test_simple_dependency_lazyuuidtaskset_save_before_repeatedly(self):
+ # Adds only one dependency as LazyUUIDTaskSet to a saved task with no dependencies
+ t = Task(self.tw, description='test task')
+ dependency = Task(self.tw, description='needs to be done first')
+ dependency.save()
+ t.save()
+
+ t['depends'] = LazyUUIDTaskSet(self.tw, [dependency['uuid']])
+ t.save()
+
+ self.assertEqual(t['depends'], LazyUUIDTaskSet(self.tw, [dependency['uuid']]))
+
def test_compare_different_tasks(self):
# Negative: compare two different tasks
t1 = Task(self.tw, description='test task')