Unittest - Hook testing, fixed a few mistakes
This commit is contained in:
@@ -51,10 +51,10 @@ class Hooks(object):
|
|||||||
def __getitem__(self, name):
|
def __getitem__(self, name):
|
||||||
return self._hooks[name]
|
return self._hooks[name]
|
||||||
|
|
||||||
def __setitem(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
self._hooks[key] = value
|
self._hooks[key] = value
|
||||||
|
|
||||||
def __delitem(self, key):
|
def __delitem__(self, key):
|
||||||
del self._hooks[key]
|
del self._hooks[key]
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@@ -81,6 +81,8 @@ class Hooks(object):
|
|||||||
else:
|
else:
|
||||||
self[hookname] = Hook(hookname, self.hookdir, content)
|
self[hookname] = Hook(hookname, self.hookdir, content)
|
||||||
|
|
||||||
|
self[hookname].enable()
|
||||||
|
|
||||||
def add_default(self, hookname, log=False):
|
def add_default(self, hookname, log=False):
|
||||||
"""Register a pre-built hook that exists in the folder containing hooks
|
"""Register a pre-built hook that exists in the folder containing hooks
|
||||||
used for testing.
|
used for testing.
|
||||||
@@ -94,6 +96,9 @@ class Hooks(object):
|
|||||||
else:
|
else:
|
||||||
self[hookname] = Hook(hookname, self.hookdir, default=True)
|
self[hookname] = Hook(hookname, self.hookdir, default=True)
|
||||||
|
|
||||||
|
# Finally enable this hook
|
||||||
|
self[hookname].enable()
|
||||||
|
|
||||||
def remove(self, hook):
|
def remove(self, hook):
|
||||||
"""Remove the hook matching given hookname"""
|
"""Remove the hook matching given hookname"""
|
||||||
try:
|
try:
|
||||||
@@ -178,9 +183,6 @@ class Hook(object):
|
|||||||
with open(self.hookfile, 'w') as fh:
|
with open(self.hookfile, 'w') as fh:
|
||||||
fh.write(content)
|
fh.write(content)
|
||||||
|
|
||||||
# Finally enable the hook
|
|
||||||
self.enable()
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
try:
|
try:
|
||||||
if self.hookname == other.hookname:
|
if self.hookname == other.hookname:
|
||||||
@@ -292,9 +294,6 @@ class LoggedHook(Hook):
|
|||||||
# Setup wrapper pointing to the correct hook name
|
# Setup wrapper pointing to the correct hook name
|
||||||
self._setup_wrapper()
|
self._setup_wrapper()
|
||||||
|
|
||||||
# Finally enable all hooks
|
|
||||||
self.enable()
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<LoggedHook '{0}'>".format(self.hookname)
|
return "<LoggedHook '{0}'>".format(self.hookname)
|
||||||
|
|
||||||
@@ -381,6 +380,7 @@ class LoggedHook(Hook):
|
|||||||
|
|
||||||
with open(self.hooklog_in) as fh:
|
with open(self.hooklog_in) as fh:
|
||||||
for i, line in enumerate(fh):
|
for i, line in enumerate(fh):
|
||||||
|
line = line.rstrip("\n")
|
||||||
if line.startswith("%"):
|
if line.startswith("%"):
|
||||||
# Timestamp includes nanosecond resolution
|
# Timestamp includes nanosecond resolution
|
||||||
timestamp = line.split(" ")[-1]
|
timestamp = line.split(" ")[-1]
|
||||||
@@ -393,6 +393,7 @@ class LoggedHook(Hook):
|
|||||||
|
|
||||||
with open(self.hooklog_out) as fh:
|
with open(self.hooklog_out) as fh:
|
||||||
for line in fh:
|
for line in fh:
|
||||||
|
line = line.rstrip("\n")
|
||||||
if line.startswith("!"):
|
if line.startswith("!"):
|
||||||
exitcode = int(line.split(" ")[-1])
|
exitcode = int(line.split(" ")[-1])
|
||||||
log["exitcode"] = exitcode
|
log["exitcode"] = exitcode
|
||||||
@@ -406,6 +407,8 @@ class LoggedHook(Hook):
|
|||||||
# Update last modification timestamp in cache
|
# Update last modification timestamp in cache
|
||||||
self._cache["last_change"] = self._get_log_stat()
|
self._cache["last_change"] = self._get_log_stat()
|
||||||
|
|
||||||
|
return self._cache["log"]
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
"""Make hookfile executable to allow triggering
|
"""Make hookfile executable to allow triggering
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
SELF=$(basename $0)
|
SELF=$(basename $0)
|
||||||
ORIGINALHOOK="$(dirname $0)/original_${SELF}"
|
ORIGINALHOOK="$(dirname $0)/original_${SELF}"
|
||||||
IN="${NEWFILE}.log.in"
|
IN="${ORIGINALHOOK}.log.in"
|
||||||
OUT="${NEWFILE}.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)" >> ${OUT}
|
echo "% Called at $(date +%s%N)" >> ${IN}
|
||||||
|
|
||||||
$ORIGINALHOOK < <(tee -a ${IN}) > >(tee -a ${OUT})
|
$ORIGINALHOOK < <(tee -a ${IN}) > >(tee -a ${OUT})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user