diff --git a/test/basetest/timew.py b/test/basetest/timew.py index c6109958..a5ac745f 100644 --- a/test/basetest/timew.py +++ b/test/basetest/timew.py @@ -8,7 +8,7 @@ import shutil import tempfile import unittest from .exceptions import CommandError -from .utils import run_cmd_wait, run_cmd_wait_nofail, which, timew_binary_location +from .utils import run_cmd_wait, run_cmd_wait_nofail, which, timew_binary_location, DEFAULT_EXTENSION_PATH from .compat import STRING_TYPE @@ -36,12 +36,25 @@ class Timew(object): self._original_pwd = os.getcwd() self.datadir = tempfile.mkdtemp(prefix="timew_") self.timewrc = os.path.join (self.datadir, 'timewarrior.cfg') + self.extdir = os.path.join(self.datadir, 'extensions') # Ensure any instance is properly destroyed at session end atexit.register(lambda: self.destroy()) self.reset_env() + def add_default_extension(self, filename): + """Add default extension to current instance + """ + if not os.path.isdir(self.extdir): + os.mkdir(self.extdir) + + extfile = os.path.join(self.extdir, filename) + if os.path.isfile(extfile): + raise "{} already exists".format(extfile) + + shutil.copy(os.path.join(DEFAULT_EXTENSION_PATH, filename), extfile) + def __repr__(self): txt = super(Timew, self).__repr__() return "{0} running from {1}>".format(txt[:-1], self.datadir) diff --git a/test/basetest/utils.py b/test/basetest/utils.py index 2cb95987..fe493fe2 100644 --- a/test/basetest/utils.py +++ b/test/basetest/utils.py @@ -35,9 +35,9 @@ DEFAULT_CERT_PATH = os.path.abspath( os.path.join(CURRENT_DIR, "..", "test_certs") ) -# Default location of test hooks -DEFAULT_HOOK_PATH = os.path.abspath( - os.path.join(CURRENT_DIR, "..", "test_hooks") +# Default location of test extensions +DEFAULT_EXTENSION_PATH = os.path.abspath( + os.path.join(CURRENT_DIR, "..", "test_extensions") ) diff --git a/test/extensions.t b/test/extensions.t new file mode 100755 index 00000000..e4a77271 --- /dev/null +++ b/test/extensions.t @@ -0,0 +1,77 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2016, 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 +from basetest.utils import DEFAULT_EXTENSION_PATH +import shutil +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Timew, TestCase + +# Test methods available: +# self.assertEqual(a, b) +# self.assertNotEqual(a, b) +# self.assertTrue(x) +# self.assertFalse(x) +# self.assertIs(a, b) +# self.assertIsNot(substring, text) +# self.assertIsNone(x) +# self.assertIsNotNone(x) +# self.assertIn(substring, text) +# self.assertNotIn(substring, text +# self.assertRaises(e) +# self.assertRegexpMatches(text, pattern) +# self.assertNotRegexpMatches(text, pattern) +# self.tap("") + +class TestExtensions(TestCase): + def setUp(self): + """Executed before each test in the class""" + self.t = Timew() + + def test_cli(self): + self.t.add_default_extension('ext_echo') + + code, out, err = self.t('ext_echo') + self.assertIn('test works', out) + + code, out, err = self.t('report ext_echo') + self.assertIn('test works', out) + + code, out, err = self.t('report ext') + self.assertInt('test works', out) + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 ft=python diff --git a/test/test_extensions/ext_echo b/test/test_extensions/ext_echo new file mode 100755 index 00000000..6fe0b95e --- /dev/null +++ b/test/test_extensions/ext_echo @@ -0,0 +1,2 @@ +#!/bin/sh +echo "test works"