Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_timezone_naive_date_using_init(self):
t = Task(self.tw, description='test task', due=self.localdate_naive)
self.assertEqual(t['due'], self.localtime_aware)
from subprocess import call,PIPE,check_output, Popen
from tasklib import TaskWarrior,Task
import unittest
import shutil
import dbus
import time
import re
import os
dirname, filename = os.path.split(os.path.realpath(__file__))
#change to the project dir
os.chdir(dirname)
class TestPomodoro(unittest.TestCase):
tw = TaskWarrior(data_location='.task/', create=True)
new_task = Task(tw, description="task for the test")
new_task.save()
uuid = new_task['uuid']
def get_active_task(self):
for task in self.tw.tasks.pending():
if task.active:
#get all fields in task
task.refresh()
return task
return {}
def tearDown(self):
try:
interface.do_fsm("stop")[0]
# Check that the output is a permutation of:
# {"project":"Home","description":"test task","due":"20150101232323Z"}
allowed_segments = self.exported_raw_data[1:-1].split(',')
allowed_output = [
'{' + ','.join(segments) + '}'
for segments in itertools.permutations(allowed_segments)
]
self.assertTrue(
any(t.export_data() == expected
for expected in allowed_output),
)
class TimezoneAwareDatetimeTest(TasklibTest):
def setUp(self):
super(TimezoneAwareDatetimeTest, self).setUp()
self.zone = local_zone
self.localdate_naive = datetime.datetime(2015, 2, 2)
self.localtime_naive = datetime.datetime(2015, 2, 2, 0, 0, 0)
self.localtime_aware = self.zone.localize(self.localtime_naive)
self.utctime_aware = self.localtime_aware.astimezone(pytz.utc)
def test_timezone_naive_datetime_setitem(self):
t = Task(self.tw, description='test task')
t['due'] = self.localtime_naive
self.assertEqual(t['due'], self.localtime_aware)
def test_timezone_naive_datetime_using_init(self):
t = Task(self.tw, description='test task', due=self.localtime_naive)
def test_deserializer_returning_empty_value_for_empty_string(self):
# Test that any deserializer returns empty value when passed ''
t = Task(self.tw)
deserializers = [
getattr(t, deserializer_name)
for deserializer_name in filter(
lambda x: x.startswith('deserialize_'),
dir(t),
)
]
for deserializer in deserializers:
self.assertTrue(deserializer('') in (None, [], set()))
def test_unicode_task(self):
Task(self.tw, description='†åßk').save()
self.tw.tasks.get()
def test_complete_completed_task(self):
t = Task(self.tw, description='test task')
t.save()
t.done()
self.assertRaises(Task.CompletedTask, t.done)
def test_return_all_from_failed_executed_command(self):
Task(self.tw, description='test task', tags=['test']).save()
out, err, rc = self.tw.execute_command(
['countinvalid'],
return_all=True,
allow_failure=False,
)
self.assertNotEqual(rc, 0)
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_serializers_returning_empty_string_for_none(self):
# Test that any serializer returns '' when passed None
t = Task(self.tw)
serializers = [
getattr(t, serializer_name)
for serializer_name in filter(
lambda x: x.startswith('serialize_'),
dir(t),
)
]
for serializer in serializers:
self.assertEqual(serializer(None), '')
def test_filter_for_task_with_space_in_project(self):
task = Task(self.tw, description='test', project='random project')
task.save()
filtered_task = self.tw.tasks.get(project='random project')
self.assertEqual(filtered_task['project'], 'random project')