mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
Tests: Add testing for hook args. Doesn't work.
This commit is contained in:
parent
0a54d46589
commit
d31227d2e2
2 changed files with 97 additions and 0 deletions
71
test/hooks.env.t
Executable file
71
test/hooks.env.t
Executable file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/usr/bin/env python2.7
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
################################################################################
|
||||||
|
##
|
||||||
|
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
|
||||||
|
##
|
||||||
|
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
## of this software and associated documentation files (the "Software"), to deal
|
||||||
|
## in the Software without restriction, including without limitation the rights
|
||||||
|
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
## copies of the Software, and to permit persons to whom the Software is
|
||||||
|
## furnished to do so, subject to the following conditions:
|
||||||
|
##
|
||||||
|
## The above copyright notice and this permission notice shall be included
|
||||||
|
## in all copies or substantial portions of the Software.
|
||||||
|
##
|
||||||
|
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
## SOFTWARE.
|
||||||
|
##
|
||||||
|
## http://www.opensource.org/licenses/mit-license.php
|
||||||
|
##
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
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__)))
|
||||||
|
|
||||||
|
from basetest import Task, TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestHooksOnLaunch(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
"""Executed before each test in the class"""
|
||||||
|
self.t = Task()
|
||||||
|
self.t.activate_hooks()
|
||||||
|
|
||||||
|
def test_onlaunch_builtin_env(self):
|
||||||
|
"""on-launch-env - a well-behaved, successful, on-launch hook that echoes its env."""
|
||||||
|
hookname = 'on-launch-good-env'
|
||||||
|
self.t.hooks.add_default(hookname, log=True)
|
||||||
|
|
||||||
|
code, out, err = self.t(("_get", "system.os")) # Arbitrary command
|
||||||
|
|
||||||
|
hook = self.t.hooks[hookname]
|
||||||
|
hook.assertTriggeredCount(1)
|
||||||
|
hook.assertExitcode(0)
|
||||||
|
|
||||||
|
logs = hook.get_logs()
|
||||||
|
self.t.diag(logs)
|
||||||
|
taskenv = {k:v for k, v in (line.split(":", 1) for line in logs["output"]["msgs"])}
|
||||||
|
|
||||||
|
self.assertEqual('api' in taskenv, True, 'api:...')
|
||||||
|
self.assertEqual('args' in taskenv, True, 'args:...')
|
||||||
|
self.assertEqual('command' in taskenv, True, 'command:...')
|
||||||
|
self.assertEqual('rc' in taskenv, True, 'rc:...')
|
||||||
|
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())
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
26
test/test_hooks/on-launch-good-env
Normal file
26
test/test_hooks/on-launch-good-env
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# The on-launch event is triggered once, after initialization, before any
|
||||||
|
# processing occurs. This hooks script has no effect on processing.
|
||||||
|
|
||||||
|
# Input:
|
||||||
|
# - None
|
||||||
|
|
||||||
|
# Output:
|
||||||
|
# - Optional feedback/error.
|
||||||
|
echo $1
|
||||||
|
echo $2
|
||||||
|
echo $3
|
||||||
|
echo $4
|
||||||
|
echo $5
|
||||||
|
echo $6
|
||||||
|
#for arg in $*
|
||||||
|
#do
|
||||||
|
# echo $arg
|
||||||
|
#done
|
||||||
|
|
||||||
|
# Status:
|
||||||
|
# - 0: JSON ignored, non-JSON is feedback.
|
||||||
|
# - non-0: JSON ignored, non-JSON is error.
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue