107    """Runs each script in the tests directory and returns the results.
  108 
  109    Parameters
  110    ----------
  111    tests_dir: str
  112      The path to the test dir, containing the test scripts (`*.sh`).
  113 
  114    Returns
  115    -------
  116    dict: key = script path, value = (exit_code, elapsed_time, stdout, stderr)
  117 
  118    """
  119    test_results = {}
  120 
  121    for subdir in sorted(glob(join(tests_dir, '*'))):
  122        component_group = basename(subdir)
  123        print(
"\n{}{}\n{}{}".format(INFO, component_group,
 
  124                                    len(component_group) * '=', RST))
  125        for test_script in sorted(glob(join(subdir, '*.sh')) + glob(join(subdir, '*.csh'))):
  126            print(
"+ {}".format(test_script), end=
' => ')
 
  127            sys.stdout.flush()
  128            start_time = time()
  129            proc = Popen(test_script, stdout=PIPE, stderr=PIPE)
  130            out, err = [safe_str(t) for t in proc.communicate()]
  131            exit_code = proc.wait()
  132            delta_t = time() - start_time
  133            test_results[test_script] = (exit_code, delta_t, out, err)
  134            print(
" ({:.2f} s) ".format(delta_t), end=
'')
 
  135            sys.stdout.flush()
  136            if exit_code > 0:
  137                print(
"{}FAILED (exit code {}){}".format(FAIL, exit_code, RST))
 
  138                sys.stdout.flush()
  139            else:
  140                print(
"{}OK{}".format(OK, RST))
 
  141                sys.stdout.flush()
  142 
  143    return test_results
  144 
  145