Permalink
Browse files

ReviewFixes: Reset tags instead of stop/start task; formatting changes

  • Loading branch information...
vedharish authored and lauft committed May 14, 2018
1 parent d07cc99 commit ea671d28bd1eb224b9fb2f7a00fbb77eaf408caf
Showing with 14 additions and 32 deletions.
  1. +8 −12 ext/on-modify.timewarrior
  2. +6 −20 test/test_on-modify.timewarrior.t.py
@@ -42,7 +42,7 @@ old = json.loads(sys.stdin.readline())
new = json.loads(sys.stdin.readline())
print(json.dumps(new))

def get_timew_name_from_json(json_obj):
def extract_timew_tags_from(json_obj):
# Extract attributes for use as tags.
tags = [json_obj['description']]

@@ -52,7 +52,7 @@ def get_timew_name_from_json(json_obj):
if 'tags' in json_obj:
tags.extend(json_obj['tags'])

return ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
return ' '.join(['"{0}"'.format(tag) for tag in tags]).encode('utf-8').strip()

start_or_stop = ''

@@ -65,19 +65,15 @@ elif 'start' not in new and 'start' in old:
start_or_stop = 'stop'

if start_or_stop:
combined = get_timew_name_from_json(new)
combined = extract_timew_tags_from(new)

command = 'timew {0} {1} :yes'.format(start_or_stop, combined)
subprocess.call(shlex.split(command))
subprocess.call(shlex.split('timew {0} {1} :yes'.format(start_or_stop, combined)))

# Modifications to task other than start/stop
elif 'start' in new and 'start' in old:
old_combined = get_timew_name_from_json(old)
new_combined = get_timew_name_from_json(new)
old_combined = extract_timew_tags_from(old)
new_combined = extract_timew_tags_from(new)

if old_combined != new_combined:
command = 'timew stop {0} :yes'.format(old_combined)
subprocess.call(shlex.split(command))

command = 'timew start {0} :yes'.format(new_combined)
subprocess.call(shlex.split(command))
subprocess.call(shlex.split('timew untag @1 {0} :yes'.format(old_combined)))
subprocess.call(shlex.split('timew tag @1 {0} :yes'.format(new_combined)))
@@ -120,10 +120,8 @@ def test_hook_should_process_modify_desc(self):
""")

self.assertRegexpMatches(out, """\
Tracking foo
Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
Current (\d{2}:| )\d{2}
Total ?\d{1,2}:\d{2}:\d{2}
Removed dummy from @1
Added foo to @1
\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "foo"\}
""")
self.assertEqual('', err)
@@ -138,14 +136,8 @@ def test_hook_should_process_modify_tags(self):
""")

self.assertRegexpMatches(out, """\
Recorded dummy tag1 tag2
Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
Ended (\d{2}:| )\d{2}
Total ?\d{1,2}:\d{2}:\d{2}
Tracking dummy tag3 tag4
Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
Current (\d{2}:| )\d{2}
Total ?\d{1,2}:\d{2}:\d{2}
Removed dummy tag1 tag2 from @1
Added dummy tag3 tag4 to @1
\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "tags": \["tag3", "tag4"\], "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\}
""")
self.assertEqual('', err)
@@ -160,14 +152,8 @@ def test_hook_should_process_modify_project(self):
""")

self.assertRegexpMatches(out, """\
Recorded dummy proj1
Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
Ended (\d{2}:| )\d{2}
Total ?\d{1,2}:\d{2}:\d{2}
Tracking dummy proj2
Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
Current (\d{2}:| )\d{2}
Total ?\d{1,2}:\d{2}:\d{2}
Removed dummy proj1 from @1
Added dummy proj2 to @1
\{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "project": "proj2", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\}
""")
self.assertEqual('', err)

0 comments on commit ea671d2

Please sign in to comment.