Merge branch '2.4.1' of ssh://git.tasktools.org/tm/task into 2.4.1
Conflicts: test/template.t
This commit is contained in:
@@ -36,10 +36,11 @@ class HookError(Exception):
|
|||||||
|
|
||||||
class TimeoutWaitingForStream(object):
|
class TimeoutWaitingForStream(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.stream = name
|
self.name = name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "*** Timeout reached while waiting for %s ***".format(self.name)
|
return "*** Timeout reached while waiting for {0} ***".format(
|
||||||
|
self.name)
|
||||||
|
|
||||||
|
|
||||||
class StreamsAreMerged(object):
|
class StreamsAreMerged(object):
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ class LoggedHook(Hook):
|
|||||||
for k1 in log:
|
for k1 in log:
|
||||||
# Timestamps
|
# Timestamps
|
||||||
if k1 == "calls":
|
if k1 == "calls":
|
||||||
timestamp = lambda x: datetime.fromtimestamp(int(x) / 1e9)
|
timestamp = lambda x: datetime.fromtimestamp(float(x))
|
||||||
newlog[k1] = map(timestamp, log[k1])
|
newlog[k1] = map(timestamp, log[k1])
|
||||||
|
|
||||||
elif k1 in ("input", "output"):
|
elif k1 in ("input", "output"):
|
||||||
@@ -460,35 +460,36 @@ class LoggedHook(Hook):
|
|||||||
|
|
||||||
return newlog
|
return newlog
|
||||||
|
|
||||||
def assert_triggered(self):
|
def assertTriggered(self):
|
||||||
"""Check if current hook file was triggered/used by taskwarrior
|
"""Check if current hook file was triggered/used by taskwarrior
|
||||||
"""
|
"""
|
||||||
log = self._parse_log()
|
log = self._parse_log()
|
||||||
|
|
||||||
if log["calls"]:
|
assert log["calls"], "{0} was never called".format(self.hookname)
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def assert_triggered_count(self, count):
|
def assertTriggeredCount(self, count):
|
||||||
"""Check if current hook file was triggered/used by taskwarrior and
|
"""Check if current hook file was triggered/used by taskwarrior and
|
||||||
how many times.
|
how many times.
|
||||||
"""
|
"""
|
||||||
log = self._parse_log()
|
log = self._parse_log()
|
||||||
|
|
||||||
if len(log["calls"]) == count:
|
assert len(log["calls"]) == count, ("{0} calls expected for {1} but "
|
||||||
return True
|
"found {2}".format(
|
||||||
else:
|
count,
|
||||||
return False
|
self.hookname,
|
||||||
|
log["calls"]
|
||||||
|
))
|
||||||
|
|
||||||
def assert_exitcode(self, exitcode):
|
def assertExitcode(self, exitcode):
|
||||||
"""Check if current hook finished with the expected exit code
|
"""Check if current hook finished with the expected exit code
|
||||||
"""
|
"""
|
||||||
log = self._parse_log()
|
log = self._parse_log()
|
||||||
|
|
||||||
if log["exitcode"] == exitcode:
|
assert log["exitcode"] == exitcode, ("Expected exit code {0} for {1} "
|
||||||
return True
|
"but found {2}".format(
|
||||||
else:
|
exitcode,
|
||||||
return False
|
self.hookname,
|
||||||
|
log["exitcode"]
|
||||||
|
))
|
||||||
|
|
||||||
# vim: ai sts=4 et sw=4
|
# vim: ai sts=4 et sw=4
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class TestHooksBugNumber(TestCase):
|
|||||||
self.t.activate_hooks()
|
self.t.activate_hooks()
|
||||||
|
|
||||||
def test_onmodify_custom(self):
|
def test_onmodify_custom(self):
|
||||||
# Testing a custom made hook
|
"""Testing a custom made hook"""
|
||||||
hookname = "on-modify-example-raw"
|
hookname = "on-modify-example-raw"
|
||||||
|
|
||||||
content = """#!/usr/bin/env python
|
content = """#!/usr/bin/env python
|
||||||
@@ -134,8 +134,10 @@ sys.exit(0)
|
|||||||
self.assertIn("The hook did its thing", out)
|
self.assertIn("The hook did its thing", out)
|
||||||
|
|
||||||
def test_onmodify_builtin_with_log(self):
|
def test_onmodify_builtin_with_log(self):
|
||||||
# Testing a builtin hook and keeping track of its input/output
|
"""Testing a builtin hook and keeping track of its input/output
|
||||||
# The builtin hook is found in test/test_hooks
|
|
||||||
|
The builtin hook in found in test/test_hooks
|
||||||
|
"""
|
||||||
hookname = "on-modify-for-template.py"
|
hookname = "on-modify-for-template.py"
|
||||||
self.t.hooks.add_default(hookname, log=True)
|
self.t.hooks.add_default(hookname, log=True)
|
||||||
|
|
||||||
@@ -144,10 +146,12 @@ sys.exit(0)
|
|||||||
code, out, err = self.t()
|
code, out, err = self.t()
|
||||||
self.assertIn("This is an example modify hook", out)
|
self.assertIn("This is an example modify hook", out)
|
||||||
|
|
||||||
logs = self.t.hooks[hookname].get_logs()
|
hook = self.t.hooks[hookname]
|
||||||
|
logs = hook.get_logs()
|
||||||
|
|
||||||
# Hook was called once
|
# Hook was called once
|
||||||
self.assertEqual(len(logs["calls"]), 1)
|
hook.assertTriggeredCount(1)
|
||||||
|
hook.assertExitcode(0)
|
||||||
|
|
||||||
# Some message output from the hook
|
# Some message output from the hook
|
||||||
self.assertEqual(logs["output"]["msgs"][0],
|
self.assertEqual(logs["output"]["msgs"][0],
|
||||||
@@ -158,8 +162,10 @@ sys.exit(0)
|
|||||||
"This is an example modify hook")
|
"This is an example modify hook")
|
||||||
|
|
||||||
def test_onmodify_bad_builtin_with_log(self):
|
def test_onmodify_bad_builtin_with_log(self):
|
||||||
# Testing a builtin hook and keeping track of its input/output
|
"""Testing a builtin hook and keeping track of its input/output
|
||||||
# The builtin hook is found in test/test_hooks
|
|
||||||
|
The builtin hook in found in test/test_hooks
|
||||||
|
"""
|
||||||
hookname = "on-modify-for-template-badexit.py"
|
hookname = "on-modify-for-template-badexit.py"
|
||||||
self.t.hooks.add_default(hookname, log=True)
|
self.t.hooks.add_default(hookname, log=True)
|
||||||
|
|
||||||
@@ -168,10 +174,12 @@ sys.exit(0)
|
|||||||
code, out, err = self.t()
|
code, out, err = self.t()
|
||||||
self.assertNotIn("This is an example modify hook", out)
|
self.assertNotIn("This is an example modify hook", out)
|
||||||
|
|
||||||
logs = self.t.hooks[hookname].get_logs()
|
hook = self.t.hooks[hookname]
|
||||||
|
logs = hook.get_logs()
|
||||||
|
|
||||||
# Hook was called once
|
# Hook was called once
|
||||||
self.assertEqual(len(logs["calls"]), 1)
|
hook.assertTriggeredCount(1)
|
||||||
|
hook.assertExitcode(1)
|
||||||
|
|
||||||
# Some message output from the hook
|
# Some message output from the hook
|
||||||
self.assertEqual(logs["output"]["msgs"][0],
|
self.assertEqual(logs["output"]["msgs"][0],
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ IN="${ORIGINALHOOK}.log.in"
|
|||||||
OUT="${ORIGINALHOOK}.log.out"
|
OUT="${ORIGINALHOOK}.log.out"
|
||||||
|
|
||||||
# Let it know that we were executed
|
# Let it know that we were executed
|
||||||
echo "% Called at $(date +%s%N)" >> ${IN}
|
echo "% Called at $(python -c 'import time; print(time.time())')" >> ${IN}
|
||||||
|
|
||||||
# Log what arrives via stdin to ${IN} and what comes via stdout to ${OUT}
|
# Log what arrives via stdin to ${IN} and what comes via stdout to ${OUT}
|
||||||
$ORIGINALHOOK < <(tee -a ${IN}) > >(tee -a ${OUT})
|
$ORIGINALHOOK < <(tee -a ${IN}) > >(tee -a ${OUT})
|
||||||
|
|||||||
Reference in New Issue
Block a user