Source code for cafe.drivers.behave.runner

# Copyright 2015 Rackspace
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import argparse
import os
import subprocess
from cafe.configurator.managers import TestEnvManager


[docs]def entry_point(): # Set up arguments argparser = argparse.ArgumentParser(prog='behave-runner') argparser.add_argument( "product", nargs=1, metavar="<product>", help="Product name") argparser.add_argument( "config", nargs=1, metavar="<config_file>", help="Product test config") argparser.add_argument( dest='behave_opts', nargs=argparse.REMAINDER, metavar="<behave_opts>", help="Options to pass to Behave") args = argparser.parse_args() config = str(args.config[0]) product = str(args.product[0]) behave_opts = args.behave_opts test_env_manager = TestEnvManager(product, config) test_env_manager.finalize() product_root_test_path = os.path.join( test_env_manager.test_repo_path, product) """ Attempts to use first positional argument after product config as a sub-path to the test repo path. If not a sub-path, raise exception. """ if behave_opts and not behave_opts[0].startswith('-'): user_provided_path = behave_opts[0] attempted_sub_path = os.path.join( product_root_test_path, user_provided_path.lstrip(os.path.sep)) if os.path.exists(attempted_sub_path): behave_opts[0] = attempted_sub_path else: raise Exception( "{directory} is not a sub-path in the {repo} repo.".format( directory=behave_opts[0], repo=test_env_manager.test_repo_package)) else: behave_opts.insert(0, product_root_test_path) print_mug(behave_opts[0]) behave_opts.insert(0, "behave") subprocess.call(behave_opts) exit(0)
if __name__ == '__main__': entry_point()