Skip to content

Commit

Permalink
Merge pull request #22 from kostajh/develop
Browse files Browse the repository at this point in the history
Update tests for TW Experimental
  • Loading branch information
ralphbean committed Jun 25, 2013
2 parents 17e83ca + f2b886c commit 13d3c7b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ python:
- "2.7"
- "3.2"
- "3.3"
before_install:
- sudo add-apt-repository ppa:ultrafredde/ppa -y
- sudo apt-get update -qq
- sudo apt-get install -qq task
- task --version
install: python setup.py install
script: python setup.py test
notifications:
Expand Down
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ Looking at tasks
>>> type(tasks['pending'][0])
<type 'dict'>

Experimental mode

>>> from taskw import TaskWarriorExperimental
>>> w = TaskWarriorExperimental()
>>> tasks = w.load_tasks()
>>> tasks.keys()
['completed', 'pending']
>>> type(tasks['pending'])
<type 'list'>
>>> type(tasks['pending'][0])
<type 'dict'>


Adding tasks
++++++++++++

Expand Down
50 changes: 25 additions & 25 deletions taskw/test/test_datas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ def test_add(self):
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 1)

def test_add_complicated(self):
self.tw.task_add(
"foobar",
uuid="1234-1234",
annotate_123457="awesome",
project="some_project"
)
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 1)

def test_unchanging_load_tasks(self):
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 0)
Expand All @@ -92,21 +82,6 @@ def test_completing_task_by_id_unspecified(self):
ok_(tasks['completed'][0]['end'] is not None)
eq_(tasks['completed'][0]['status'], 'completed')

def test_completing_task_with_date(self):
self.tw.task_add("foobar")
uuid = self.tw.load_tasks()['pending'][0]['uuid']
self.tw.task_done(uuid=uuid, end="1234567890")
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 0)
eq_(len(tasks['completed']), 1)

try:
eq_(tasks['completed'][0]['end'], '1234567890')
except Exception:
assert(tasks['completed'][0]['end'].startswith('20130514T'))

eq_(tasks['completed'][0]['status'], 'completed')

def test_completing_task_by_id_specified(self):
self.tw.task_add("foobar")
self.tw.task_done(id=1)
Expand Down Expand Up @@ -184,6 +159,16 @@ def test_update_exc(self):
class TestDBNormal(_BaseTestDB):
class_to_test = TaskWarrior

def test_add_complicated(self):
self.tw.task_add(
"foobar",
uuid="1234-1234",
annotate_123457="awesome",
project="some_project"
)
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 1)

@raises(ValueError)
def test_completing_completed_task(self):
task = self.tw.task_add("foobar")
Expand Down Expand Up @@ -244,6 +229,21 @@ def test_delete_with_end(self):
eq_(tasks['completed'][0]['end'], '1234567890')
eq_(tasks['completed'][0]['status'], 'deleted')

def test_completing_task_with_date(self):
self.tw.task_add("foobar")
uuid = self.tw.load_tasks()['pending'][0]['uuid']
self.tw.task_done(uuid=uuid, end="1234567890")
tasks = self.tw.load_tasks()
eq_(len(tasks['pending']), 0)
eq_(len(tasks['completed']), 1)

try:
eq_(tasks['completed'][0]['end'], '1234567890')
except Exception:
assert(tasks['completed'][0]['end'].startswith('20130514T'))

eq_(tasks['completed'][0]['status'], 'completed')

def test_delete_completed(self):
task = self.tw.task_add("foobar")
task = self.tw.task_done(uuid=task['uuid'])
Expand Down
2 changes: 1 addition & 1 deletion taskw/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def encode_task_experimental(task):
task['tags'] = ','.join(task['tags'])
for k in task:
for unsafe, safe in six.iteritems(encode_replacements_experimental):
if isinstance(task[k], basestring):
if isinstance(task[k], str):
task[k] = task[k].replace(unsafe, safe)

# Then, format it as a string
Expand Down
32 changes: 20 additions & 12 deletions taskw/warrior.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def can_use(cls):
['task', '--version'],
stdout=subprocess.PIPE
).communicate()[0]
taskwarrior_version = map(int, taskwarrior_version.split('.'))
return taskwarrior_version >= [2, 0, 0]
taskwarrior_major_version = int(taskwarrior_version.decode().split('.')[0])
return taskwarrior_major_version >= 2

def load_tasks(self, **kw):
# Load tasks using `task export`
Expand All @@ -376,11 +376,11 @@ def load_tasks(self, **kw):
pending_tasks = json.loads(subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.json.array=TRUE', 'rc.verbose=nothing', 'status:pending',
'export'], stdout=subprocess.PIPE).communicate()[0])
'export'], stdout=subprocess.PIPE).communicate()[0].decode())
completed_tasks = json.loads(subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.json.array=TRUE', 'rc.verbose=nothing', 'status:completed',
'export'], stdout=subprocess.PIPE).communicate()[0])
'export'], stdout=subprocess.PIPE).communicate()[0].decode())
tasks['pending'] = pending_tasks
tasks['completed'] = completed_tasks
return tasks
Expand All @@ -399,7 +399,11 @@ def get_task(self, **kw):

def _load_task(self, **kw):

key = kw.keys()[0]
# TODO: Change this, because we can actually use multiple args.
if len(kw) != 1:
raise KeyError("Only 1 ID keyword argument may be specified")

key = list(kw.keys())[0]
if key is not 'id' and key is not 'uuid' and key is not 'description':
search = key + ":" + str(kw[key])
else:
Expand All @@ -412,11 +416,16 @@ def _load_task(self, **kw):
task = subprocess.Popen([
'task', 'rc:%s' % self.config_filename,
'rc.verbose=nothing', search,
'export'], stdout=subprocess.PIPE).communicate()[0]
'export'], stdout=subprocess.PIPE).communicate()[0].decode()
if task:
try:
task_data = json.loads(task)
return task_data[0][six.u('id')], task_data[0]
if type(task_data) is dict:
# Only one item was returned from search
return task_data[six.u('id')], task_data
else:
# Multiple items returned from search, return just the 1st
return task_data[0][six.u('id')], task_data[0]
pass
except:
pass
Expand Down Expand Up @@ -445,10 +454,7 @@ def task_add(self, description, tags=None, **kw):

# Check if 'uuid' is in the task we just added.
if not 'uuid' in added_task:
print('No uuid! uh oh.')
print(id)
pprint.pprint(added_task)
return
raise KeyError('No uuid! uh oh.')
if annotations and 'uuid' in added_task:
for annotation in annotations:
self.task_annotate(added_task, annotation)
Expand All @@ -465,6 +471,8 @@ def task_annotate(self, task, annotation):
return annotated_task

def task_done(self, **kw):
if not kw:
raise KeyError('No key was passed.')
id, task = self.get_task(**kw)

subprocess.Popen([
Expand All @@ -477,7 +485,7 @@ def task_done(self, **kw):
def task_update(self, task):

if 'uuid' not in task:
return None, dict()
raise KeyError('Task must have a UUID.')

id, _task = self.get_task(uuid=task['uuid'])

Expand Down

0 comments on commit 13d3c7b

Please sign in to comment.