"""Implementation of the cs.status script, which prints the status of allof the tests in one or more test suites"""from__future__importprint_functionfromCIME.XML.standard_module_setupimport*fromCIME.XML.expected_fails_fileimportExpectedFailsFilefromCIME.test_statusimportTestStatus,SHAREDLIB_BUILD_PHASE,TEST_PEND_STATUSimportosimportsysfromcollectionsimportdefaultdict
[docs]defcs_status(test_paths,summary=False,fails_only=False,count_fails_phase_list=None,check_throughput=False,check_memory=False,expected_fails_filepath=None,force_rebuild=False,out=sys.stdout,):"""Print the test statuses of all tests in test_paths. The default is to print to stdout, but this can be overridden with the 'out' argument. If summary is True, then only the overall status of each test is printed If fails_only is True, then only test failures are printed (this includes PENDs as well as FAILs). If count_fails_phase_list is provided, it should be a list of phases (from the phases given by test_status.ALL_PHASES). For each phase in this list: do not give line-by-line output; instead, just report the total number of tests that have not PASSed this phase (this includes PENDs and FAILs). (This is typically used with the fails_only option, but it can also be used without that option.) If expected_fails_filepath is provided, it should be a string giving the full path to a file listing expected failures for this test suite. Expected failures are then labeled as such in the output. """expect(not(summaryandfails_only),"Cannot have both summary and fails_only")expect(not(summaryandcount_fails_phase_list),"Cannot have both summary and count_fails_phase_list",)ifcount_fails_phase_listisNone:count_fails_phase_list=[]non_pass_counts=dict.fromkeys(count_fails_phase_list,0)xfails=_get_xfails(expected_fails_filepath)test_id_output=defaultdict(str)test_id_counts=defaultdict(int)fortest_pathintest_paths:test_dir=os.path.dirname(test_path)ts=TestStatus(test_dir=test_dir)ifforce_rebuild:withts:ts.set_status(SHAREDLIB_BUILD_PHASE,TEST_PEND_STATUS)test_id=os.path.basename(test_dir).split(".")[-1]ifsummary:output=_overall_output(ts," {status}{test_name}\n",check_throughput,check_memory)else:iffails_only:output=""else:output=_overall_output(ts," {test_name} (Overall: {status}) details:\n",check_throughput,check_memory,)output+=ts.phase_statuses_dump(prefix=" ",skip_passes=fails_only,skip_phase_list=count_fails_phase_list,xfails=xfails.get(ts.get_name()),)ifcount_fails_phase_list:ts.increment_non_pass_counts(non_pass_counts)test_id_output[test_id]+=outputtest_id_counts[test_id]+=1fortest_idinsorted(test_id_output):count=test_id_counts[test_id]print("{}: {} test{}".format(test_id,count,"s"ifcount>1else""),file=out)print(test_id_output[test_id],file=out)print(" ",file=out)ifcount_fails_phase_list:print(72*"=",file=out)print("Non-PASS results for select phases:",file=out)forphaseincount_fails_phase_list:print("{} non-passes: {}".format(phase,non_pass_counts[phase]),file=out)
def_get_xfails(expected_fails_filepath):"""Returns a dictionary of ExpectedFails objects, where the keys are test names expected_fails_filepath should be either a string giving the path to the file containing expected failures, or None. If None, then this returns an empty dictionary (as if expected_fails_filepath were pointing to a file with no expected failures listed). """ifexpected_fails_filepathisnotNone:expected_fails_file=ExpectedFailsFile(expected_fails_filepath)xfails=expected_fails_file.get_expected_fails()else:xfails={}returnxfailsdef_overall_output(ts,format_str,check_throughput,check_memory):"""Returns a string giving the overall test status Args: ts: TestStatus object format_str (string): string giving the format of the output; must contain place-holders for status and test_name """test_name=ts.get_name()status=ts.get_overall_test_status(check_throughput=check_throughput,check_memory=check_memory,)[0]returnformat_str.format(status=status,test_name=test_name)