Add runner autocomplete
Change-Id: I4d15d14bf25c5a932ebd1af4729c86c53b15e797
This commit is contained in:
parent
02a97f1c2a
commit
48395351d1
|
@ -173,16 +173,17 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||
def __init__(self):
|
||||
desc = "Open Common Automation Framework Engine"
|
||||
usage_string = """
|
||||
cafe-runner <config> <testrepos>... [--fail-fast]
|
||||
[--supress-load-tests] [--dry-run]
|
||||
[--data-directory=DATA_DIRECTORY] [--regex-list=REGEX...]
|
||||
[--file] [--parallel=(class|test)] [--result=(json|xml)]
|
||||
[--result-directory=RESULT_DIRECTORY] [--tags=TAG...]
|
||||
[--verbose=VERBOSE]
|
||||
cafe-runner <config> <testrepos>... [--failfast]
|
||||
[--dry-run] [--data-directory=DATA_DIRECTORY]
|
||||
[--regex-list=REGEX...] [--file] [--parallel=(class|test)]
|
||||
[--result=(json|xml)] [--result-directory=RESULT_DIRECTORY]
|
||||
[--tags=TAG...] [--verbose=VERBOSE] [--exit-on-error]
|
||||
[--workers=NUM]
|
||||
cafe-runner <config> <testrepo>... --list
|
||||
cafe-runner --list
|
||||
cafe-runner --help
|
||||
"""
|
||||
|
||||
super(ArgumentParser, self).__init__(
|
||||
usage=usage_string, description=desc)
|
||||
|
||||
|
@ -228,11 +229,6 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||
help="Lists configs if no repo is specified otherwise lists tests"
|
||||
" for all the specified repos.")
|
||||
|
||||
self.add_argument(
|
||||
"--supress-load-tests", "-s",
|
||||
action="store_true",
|
||||
help="supress load tests method")
|
||||
|
||||
self.add_argument(
|
||||
"--data-directory", "-D",
|
||||
action=DataDirectoryAction,
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
import os
|
||||
import importlib
|
||||
import pkgutil
|
||||
|
||||
from cafe.configurator.managers import EngineConfigManager
|
||||
from cafe.engine.config import EngineConfig
|
||||
|
||||
ENGINE_CONFIG = EngineConfig(
|
||||
os.environ.get("CAFE_ENGINE_CONFIG_FILE_PATH") or
|
||||
EngineConfigManager.ENGINE_CONFIG_PATH)
|
||||
|
||||
|
||||
def print_configs():
|
||||
config_dir = os.path.abspath(os.path.expanduser(
|
||||
ENGINE_CONFIG.config_directory))
|
||||
for path, dirs, files in os.walk(config_dir):
|
||||
for file_ in files:
|
||||
if file_.endswith(".config"):
|
||||
print os.path.join(path, file_)[len(config_dir) + len(os.sep):]
|
||||
|
||||
|
||||
def print_imports(string):
|
||||
import_paths = string.strip().rsplit(".", 1)
|
||||
if len(import_paths) == 1:
|
||||
for _, module_name, _ in pkgutil.iter_modules():
|
||||
if module_name.startswith(import_paths[0]):
|
||||
print module_name
|
||||
else:
|
||||
try:
|
||||
base = importlib.import_module(import_paths[0])
|
||||
for _, name, _ in pkgutil.iter_modules(base.__path__):
|
||||
if name.startswith(import_paths[1]):
|
||||
print "{0}.{1}".format(import_paths[0], name)
|
||||
except:
|
||||
return
|
||||
|
||||
|
||||
def print_products():
|
||||
try:
|
||||
base = importlib.import_module(ENGINE_CONFIG.default_test_repo)
|
||||
for _, name, _ in pkgutil.iter_modules(base.__path__):
|
||||
print name
|
||||
except:
|
||||
return
|
||||
|
||||
|
||||
def print_configs_by_product(product):
|
||||
config_dir = os.path.join(
|
||||
os.path.abspath(os.path.expanduser(ENGINE_CONFIG.config_directory)),
|
||||
product)
|
||||
for path, dirs, files in os.walk(config_dir):
|
||||
for file_ in files:
|
||||
if file_.endswith(".config"):
|
||||
print os.path.join(path, file_)[len(config_dir) + len(os.sep):]
|
|
@ -68,10 +68,6 @@ class PositiveDataGenerator(DatasetList):
|
|||
"arg_update": ["--failfast"],
|
||||
"update": {"failfast": True}})
|
||||
|
||||
self.append_new_dataset("supress_load_tests", {
|
||||
"arg_update": ["--supress-load-tests"],
|
||||
"update": {"supress_load_tests": True}})
|
||||
|
||||
self.append_new_dataset("parallel_class", {
|
||||
"arg_update": ["--parallel", "class"],
|
||||
"update": {"parallel": "class"}})
|
||||
|
@ -129,7 +125,6 @@ class ArgumentsTests(unittest.TestCase):
|
|||
"dry_run": False,
|
||||
"exit_on_error": False,
|
||||
"failfast": False,
|
||||
"supress_load_tests": False,
|
||||
"parallel": None,
|
||||
"result": None,
|
||||
"result_directory": "./",
|
||||
|
@ -161,7 +156,12 @@ class ArgumentsTests(unittest.TestCase):
|
|||
try:
|
||||
args = ArgumentParser().parse_args(arg_list)
|
||||
for key, value in expected.items():
|
||||
self.assertEqual(value, getattr(args, key, "NoValueFound"))
|
||||
if key == "regex_list":
|
||||
self.assertEqual(
|
||||
value, [i.pattern for i in getattr(args, key, [])])
|
||||
else:
|
||||
self.assertEqual(value, getattr(args, key, "NoValueFound"))
|
||||
|
||||
except SystemExit as exception:
|
||||
if exception.code != 0:
|
||||
self.assertEqual(exception, None)
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
_cafe_runner()
|
||||
{
|
||||
local cur configs packages options product
|
||||
COMPREPLY=()
|
||||
#get current word
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
#Consumer only exists in the parallel runner
|
||||
python -c "from cafe.drivers.unittest.runner import Consumer" 2>/dev/null
|
||||
status=$?
|
||||
|
||||
#if last call was successful (0 return status we have the parallel runner
|
||||
if ((1 > $status)); then
|
||||
|
||||
# process list options
|
||||
options='--help --dry-run --exit-on-error --list --data-directory --regex-list --file --parallel --result --result-directory --tags --verbose --workers'
|
||||
if [[ ${cur} == -* ]]; then
|
||||
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
|
||||
COMPREPLY="${COMPREPLY} "
|
||||
return 0
|
||||
fi
|
||||
|
||||
# process configs
|
||||
if [[ ${COMP_CWORD} < 2 ]]; then
|
||||
configs=`python -c "from cafe.drivers.unittest.autocomplete import print_configs;print_configs()"`
|
||||
COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
|
||||
COMPREPLY="${COMPREPLY} "
|
||||
return 0
|
||||
fi
|
||||
|
||||
# process repos (this does not account for option params)
|
||||
packages=`echo $cur | python -c "import sys;from cafe.drivers.unittest.autocomplete import print_imports;print_imports(sys.stdin.read())"`
|
||||
COMPREPLY=( $(compgen -W "${packages}" -- ${cur}) )
|
||||
return 0
|
||||
|
||||
else # the normal runner
|
||||
options='--help --test-repo --verbose --fail-fast --supress-load-tests --packages --module-regex --module --method-regex --tags --result --result-directory --parallel --dry-run --data-directory --data --list'
|
||||
if [[ ${cur} == -* ]]; then
|
||||
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
|
||||
COMPREPLY="${COMPREPLY} "
|
||||
return 0
|
||||
fi
|
||||
|
||||
# process product completion
|
||||
if [[ ${COMP_CWORD} < 2 ]]; then
|
||||
products=`python -c "from cafe.drivers.unittest.autocomplete import print_products;print_products()"`
|
||||
COMPREPLY=( $(compgen -W "${products}" -- ${cur}) )
|
||||
COMPREPLY="${COMPREPLY} "
|
||||
return 0
|
||||
fi
|
||||
|
||||
# process configs by product
|
||||
configs=`python -c "import sys;from cafe.drivers.unittest.autocomplete import print_configs_by_product;print_configs_by_product(\"${COMP_WORDS[1]}\")"`
|
||||
COMPREPLY=( $(compgen -W "${configs}" -- ${cur}) )
|
||||
COMPREPLY="${COMPREPLY} "
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
complete -o nospace -F _cafe_runner cafe-runner
|
||||
|
Loading…
Reference in New Issue