Example #1
0
def run_test_pkg(pkg_name):
    log_info("--%s package----------------------------------------" % pkg_name)
    
    #Determine where the test package is and ensure it exists
    log_debug("The current working directory is " + __CWD)
    pkg_dir_name = __CWD + "\\" + pkg_name.replace(".", "\\")
    log_debug("The test package location is " + pkg_dir_name)
    if not file_exists(pkg_dir_name + r"\__init__.py"):
        err_msg = "No such test package: %s" % pkg_dir_name
        log_error(err_msg)
        raise Exception(err_msg)
    
    #Build up a list of all subpackages/modules contained in test package
    subpkg_list = [x for x in nt.listdir(pkg_dir_name) if not x.endswith(".py") and file_exists(pkg_dir_name + "\\" + x + "\\__init__.py")]
    log_debug("Subpackages found: %s" % (str(subpkg_list)))
    module_list = [x for x in nt.listdir(pkg_dir_name) if x.endswith(".py") and x!="__init__.py"]
    log_debug("Modules found: %s" % (str(module_list)))
    if len(module_list)==0:
        log_warn("No test modules found in the %s test package!" % pkg_name)
        print ""
    
    #Import all tests
    for test_module in module_list:
        test_module = pkg_name + "." + test_module.split(".py", 1)[0]
        log_info("--Testing %s..." % test_module)
        try:
            __import__(test_module)
        except SystemExit, e:
            if e.code!=0: 
                raise Exception("Importing '%s' caused an unexpected exit code: %s" % (test_module, str(e.code)))
        print ""
Example #2
0
def run_test_pkg(pkg_name, do_not_run=[]):
    log_info("--%s package----------------------------------------" % pkg_name)

    #Determine where the test package is and ensure it exists
    log_debug("The current working directory is " + __CWD)
    pkg_dir_name = __CWD + "\\" + pkg_name.replace(".", "\\")
    log_debug("The test package location is " + pkg_dir_name)
    if not file_exists(pkg_dir_name + r"\__init__.py"):
        err_msg = "No such test package: %s" % pkg_dir_name
        log_error(err_msg)
        raise Exception(err_msg)

    #Build up a list of all subpackages/modules contained in test package
    subpkg_list = [
        x for x in nt.listdir(pkg_dir_name)
        if not x.endswith(".py") and file_exists(pkg_dir_name + "\\" + x +
                                                 "\\__init__.py")
    ]
    log_debug("Subpackages found: %s" % (str(subpkg_list)))
    module_list = [
        x for x in nt.listdir(pkg_dir_name)
        if x.endswith(".py") and x != "__init__.py"
    ]
    log_debug("Modules found: %s" % (str(module_list)))
    if len(module_list) == 0:
        log_warn("No test modules found in the %s test package!" % pkg_name)
        print("")

    if options.GEN_TEST_PLAN:
        l.info("Generating test documentation for '%s' package..." % pkg_name)
        pydoc.writedoc(pkg_name)

    #Import all tests
    for test_module in module_list:
        test_module = pkg_name + "." + test_module.split(".py", 1)[0]

        if options.RUN_TESTS:
            if test_module in do_not_run:
                log_info("--Testing of %s has been disabled!" % test_module)
                continue
            log_info("--Testing %s..." % test_module)
            try:
                __import__(test_module)
            except SystemExit as e:
                if e.code != 0:
                    raise Exception(
                        "Importing '%s' caused an unexpected exit code: %s" %
                        (test_module, str(e.code)))
            print("")

        if options.GEN_TEST_PLAN:
            l.info("Generating test documentation for '%s' module..." %
                   test_module)
            pydoc.writedoc(test_module)

    #Recursively import subpackages
    for subpkg in subpkg_list:
        run_test_pkg(pkg_name + "." + subpkg)
Example #3
0
def run_test_pkg(pkg_name, do_not_run=[]):
    log_info("--%s package----------------------------------------" % pkg_name)
    
    #Determine where the test package is and ensure it exists
    log_debug("The current working directory is " + __CWD)
    pkg_dir_name = __CWD + "\\" + pkg_name.replace(".", "\\")
    log_debug("The test package location is " + pkg_dir_name)
    if not file_exists(pkg_dir_name + r"\__init__.py"):
        err_msg = "No such test package: %s" % pkg_dir_name
        log_error(err_msg)
        raise Exception(err_msg)
    
    #Build up a list of all subpackages/modules contained in test package
    subpkg_list = [x for x in nt.listdir(pkg_dir_name) if not x.endswith(".py") and file_exists(pkg_dir_name + "\\" + x + "\\__init__.py")]
    log_debug("Subpackages found: %s" % (str(subpkg_list)))
    module_list = [x for x in nt.listdir(pkg_dir_name) if x.endswith(".py") and x!="__init__.py"]
    log_debug("Modules found: %s" % (str(module_list)))
    if len(module_list)==0:
        log_warn("No test modules found in the %s test package!" % pkg_name)
        print("")
    
    if options.GEN_TEST_PLAN:
        l.info("Generating test documentation for '%s' package..." % pkg_name)
        pydoc.writedoc(pkg_name)
    
    #Import all tests
    for test_module in module_list:
        test_module = pkg_name + "." + test_module.split(".py", 1)[0]
        
        if options.RUN_TESTS:
            if test_module in do_not_run:
                log_info("--Testing of %s has been disabled!" % test_module)
                continue
            log_info("--Testing %s..." % test_module)
            try:
                __import__(test_module)
            except SystemExit as e:
                if e.code!=0: 
                    raise Exception("Importing '%s' caused an unexpected exit code: %s" % (test_module, str(e.code)))
            print("")
        
        if options.GEN_TEST_PLAN:
            l.info("Generating test documentation for '%s' module..." % test_module)
            pydoc.writedoc(test_module)

    
    #Recursively import subpackages
    for subpkg in subpkg_list:
        run_test_pkg(pkg_name + "." + subpkg)