mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
Tests: expose 'args' passed to hook scripts
- Useful to validate that all the expected arguments were passed with correct escaping. - Update test/template.t with one use-case for 'args'
This commit is contained in:
parent
09d86eb165
commit
fd17a68930
4 changed files with 12 additions and 8 deletions
|
@ -10,7 +10,6 @@ try:
|
|||
except ImportError:
|
||||
import json
|
||||
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from .utils import DEFAULT_HOOK_PATH
|
||||
from .exceptions import HookError
|
||||
|
@ -396,7 +395,7 @@ class LoggedHook(Hook):
|
|||
It should look something like this:
|
||||
|
||||
## STDIN file
|
||||
% Called at 1414874711
|
||||
% Called at 1414874711 with 'arg1 arg2 ...'
|
||||
{... JSON received by the hook ... }
|
||||
{... more JSON ...}
|
||||
|
||||
|
@ -424,12 +423,14 @@ class LoggedHook(Hook):
|
|||
for i, line in enumerate(fh):
|
||||
line = line.rstrip("\n")
|
||||
if line.startswith("%"):
|
||||
tstamp, args = line.split(" with ")
|
||||
# Timestamp includes nanosecond resolution
|
||||
timestamp = line.split(" ")[-1]
|
||||
timestamp = tstamp.split(" ")[-1]
|
||||
# convert timestamp to python datetime object
|
||||
log["calls"].append(
|
||||
datetime.fromtimestamp(float(timestamp))
|
||||
)
|
||||
log["calls"].append({
|
||||
"timestamp": datetime.fromtimestamp(float(timestamp)),
|
||||
"args": args,
|
||||
})
|
||||
elif line.startswith("{"):
|
||||
# Decode json input (to hook)
|
||||
log["input"]["json"].append(json_decoder(line))
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -63,6 +62,7 @@ class TestHooksOnLaunch(TestCase):
|
|||
self.assertEqual('data' in taskenv, True, 'data:...')
|
||||
self.assertEqual('version' in taskenv, True, 'version:...')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
unittest.main(testRunner=TAPTestRunner())
|
||||
|
|
|
@ -157,6 +157,9 @@ sys.exit(0)
|
|||
# (according to python's JSON parser)
|
||||
hook.assertValidJSONOutput()
|
||||
|
||||
# Checking which arguments were passed to the hook
|
||||
self.assertIn("/Hello/Greetings/", logs["calls"][0]["args"])
|
||||
|
||||
# Some message output from the hook
|
||||
self.assertEqual(logs["output"]["msgs"][0],
|
||||
"Hello from the template hook")
|
||||
|
|
|
@ -6,7 +6,7 @@ IN="${ORIGINALHOOK}.log.in"
|
|||
OUT="${ORIGINALHOOK}.log.out"
|
||||
|
||||
# Let it know that we were executed
|
||||
echo "% Called at $(python -c 'import time; print(time.time())')" >> ${IN}
|
||||
echo "% Called at $(python -c 'import time; print(time.time())') with '$@'" >> ${IN}
|
||||
|
||||
# Log what arrives via stdin to ${IN} and what comes via stdout to ${OUT}
|
||||
$ORIGINALHOOK "$@" < <(tee -a ${IN}) > >(tee -a ${OUT})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue