diff --git a/test/basetest/hooks.py b/test/basetest/hooks.py index cfb364893..245f0bc68 100644 --- a/test/basetest/hooks.py +++ b/test/basetest/hooks.py @@ -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)) diff --git a/test/hooks.env.t b/test/hooks.env.t index 0939f5ec0..288835198 100755 --- a/test/hooks.env.t +++ b/test/hooks.env.t @@ -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()) diff --git a/test/template.t b/test/template.t index 575b02c18..2259d4c83 100644 --- a/test/template.t +++ b/test/template.t @@ -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") diff --git a/test/test_hooks/wrapper.sh b/test/test_hooks/wrapper.sh index 21b891d9d..f34d8dfe5 100644 --- a/test/test_hooks/wrapper.sh +++ b/test/test_hooks/wrapper.sh @@ -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})