Unittest - default to ../src/ as location for task/taskd binaries

This commit is contained in:
Renato Alves 2014-07-31 17:03:49 +01:00
parent 16af4d088c
commit d9d3b47c31
3 changed files with 30 additions and 7 deletions

View file

@ -5,7 +5,7 @@ import tempfile
import shutil
import atexit
import unittest
from .utils import run_cmd_wait, run_cmd_wait_nofail, which
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, binary_location
from .exceptions import CommandError
@ -20,7 +20,9 @@ class Task(object):
A taskw client should not be used after being destroyed.
"""
def __init__(self, taskd=None, taskw="task"):
DEFAULT_TASK = binary_location("task")
def __init__(self, taskd=None, taskw=DEFAULT_TASK):
"""Initialize a Task warrior (client) that can interact with a taskd
server. The task client runs in a temporary folder.

View file

@ -8,7 +8,7 @@ import atexit
from time import sleep
from subprocess import Popen
from .utils import (find_unused_port, release_port, port_used, run_cmd_wait,
which, parse_datafile)
which, parse_datafile, CURRENT_DIR, binary_location)
from .exceptions import CommandError
try:
@ -16,9 +16,10 @@ try:
except ImportError:
DEVNULL = open(os.devnull, 'w')
# Location relative to current script location
_curdir = os.path.dirname(os.path.abspath(__file__))
DEFAULT_CERT_PATH = os.path.abspath(os.path.join(_curdir, "..", "test_certs"))
# Directory relative to basetest module location
DEFAULT_CERT_PATH = os.path.abspath(
os.path.join(CURRENT_DIR, "..", "test_certs")
)
class Taskd(object):
@ -34,7 +35,7 @@ class Taskd(object):
A server can be stopped and started multiple times, but should not be
started or stopped after being destroyed.
"""
DEFAULT_TASKD = "taskd"
DEFAULT_TASKD = binary_location("taskd")
def __init__(self, taskd=DEFAULT_TASKD, certpath=None,
address="127.0.0.1"):

View file

@ -18,9 +18,29 @@ from .exceptions import CommandError
USED_PORTS = set()
ON_POSIX = 'posix' in sys.builtin_module_names
# Directory relative to basetest module location
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
# Location of binary files (usually the src/ folder)
BIN_PREFIX = os.path.abspath(
os.path.join(CURRENT_DIR, "..", "..", "src")
)
# Environment flags to control skipping of task and taskd tests
TASKW_SKIP = os.environ.get("TASKW_SKIP", False)
TASKD_SKIP = os.environ.get("TASKD_SKIP", False)
# Environment flags to control use of PATH or in-tree binaries
USE_PATH = os.environ.get("USE_PATH", False)
def binary_location(cmd):
"""If USE_PATH is set rely on PATH to look for task/taskd binaries.
Otherwise ../src/ is used by default.
"""
if USE_PATH:
return cmd
else:
return os.path.join(BIN_PREFIX, cmd)
def wait_process(proc, timeout=1):