def get_log_files(self): """Get execution logs dir and results """ if self.logs_startdir is not None: if self.logs_startdir == self.res_startdir: logs_execdir = self.results_execdir else: logs_execdir = file_Utils.createDir_addtimestamp( self.logs_startdir, self.nameonly) logfile = self.get_exec_file_by_type("Logs", logs_execdir) elif self.logs_startdir is None: colocate = False logs_location = xml_Utils.getChildTextbyParentTag( self.filepath, 'Details', 'Logsdir') results_location = xml_Utils.getChildTextbyParentTag( self.filepath, 'Details', 'Resultsdir') #get default logs and results directory default_xml = Tools.__path__[0] + os.sep + 'w_settings.xml' default_logsdir = get_credentials(default_xml, 'def_dir', ['Logsdir'], 'Setting') default_resultsdir = get_credentials(default_xml, 'def_dir', ['Resultsdir'], 'Setting') #use the default directory if user didn't define it in test case/test suite/project if results_location is None or results_location is False: if default_resultsdir['Resultsdir'] is not None: results_location = default_resultsdir['Resultsdir'] if logs_location is None or logs_location is False: if default_logsdir['Logsdir'] is not None: logs_location = default_logsdir['Logsdir'] if logs_location is None or logs_location is False\ or str(logs_location).strip() == "": logs_execdir = self.create_def_exec_dir() logfile = self.get_exec_file_by_type('Logs', logs_execdir) elif logs_location is not None and logs_location is not False: logs_location_rel = str(logs_location).strip() logs_location = file_Utils.getAbsPath( logs_location_rel, os.path.dirname(self.filepath)) results_location_rel = str(results_location).strip() results_location = file_Utils.getAbsPath( results_location_rel, os.path.dirname(self.filepath)) if logs_location == results_location: colocate = True logfile, logs_execdir = self.checkdir_create_file( logs_location, 'Logs', colocate) # print "printing logs_execdir: ", logs_execdir logsdir = os.path.dirname(logfile) return logfile, logsdir, logs_execdir
def __check_dir_exists(cls, filepath, dirtag): """ Verify that the directory exists in the path provided. Arguments: 1. filepath: file path will be parsed as input for checking directories 2. dirtag: directory tag that used to get directory path """ dirt = xml_Utils.getChildTextbyParentTag(filepath, 'Details', dirtag) directory = file_Utils.getAbsPath(dirt, os.path.dirname(filepath)) if directory is not False and directory is not None: print_info("{0} path {1}".format(dirtag, directory)) if not os.path.exists(directory): print_warning("Directory does not exist in location {0}."\ "\nWarrior framework will try to create the directory, if creation "\ "fails then default warriorspace will be used to collect logs/results"\ .format(directory)) else: if dirtag is 'Resultsdir': print_info( "Default directory in Warriorspace will be used to collect results" ) else: print_info( "Default directory in Warriorspace will be used to collect logs" )
def __check_input_datafile(cls, filepath, testname, check_files_dict): """ Verify that the input data file exists in the path provided. If path not provided verify the default data file Arguments: 1. filepath: filepath will be parsed as input for checking Input data 3. testname: to mention whether it is Testcase/Testsuite datafile 2. check_files_dict: a dict element to check the status of files whether it has been verified already or not Return: 1. result(bool): if the Datafiles exist, returns True: else False 2. check_files_dict: a dict element to check the status of files whether it has been verified already or not """ result = [] input_data_file = xml_Utils.getChildTextbyParentTag(filepath, 'Details', 'InputDataFile') if input_data_file is not False and input_data_file is not None: if testname is 'Testsuite': check_files_dict['check_datafile'] = True input_data_file = str(input_data_file).strip() if str(input_data_file).upper() == 'NO_DATA': print_info('No_Data option selected for this testcase') result.append(True) elif 'NO_DATA' not in str(input_data_file).upper(): data_file_path = file_Utils.getAbsPath(input_data_file, os.path.dirname(filepath)) print_info("{0} input data_file_path: {1}".format(testname, data_file_path)) if os.path.exists(data_file_path): print_info("{0} Input datafile is present "\ "in location {1}".format(testname, data_file_path)) result.append(True) else: print_error("{0} Input datafile is NOT "\ "present in location {1}".format(testname, data_file_path)) result.append(False) elif input_data_file is None or input_data_file is False: if testname is 'Testcase': print_info("InputDataFile is not provided,"\ "checking if default InputDataFile exists....") default_datafilepath = execution_files_class.get_default_xml_datafile(\ filepath) print_debug("default_datafile_path: {0}".format(default_datafilepath)) if os.path.exists(default_datafilepath): print_info("Default input datafile for the Testcase is available") result.append(True) else: print_error("Default input datafile for the Testcase is NOT available") result.append(False) else: check_files_dict['check_datafile'] = False return result, check_files_dict
def check_get_datatype(self, datafile): """Check and get the datatype for testcase """ data_type = xml_Utils.getChildTextbyParentTag(self.filepath, 'Details', 'Datatype') if str(datafile).upper().strip() == 'NO_DATA': data_type = 'CUSTOM' print_info('This test case will be run without any InputDataFile') elif data_type is None or data_type is False or\ str(data_type).strip() == "": data_type = 'CUSTOM' elif data_type is not None and data_type is not False: data_type = str(data_type).strip() supported_values = ['iterative', 'custom', 'hybrid'] if data_type.lower() not in supported_values: print_warning("unsupported value '{0}' provided for data_type," " supported values are "\ "'{1}' and case-insensitive".format(data_type, supported_values)) print_info( "Hence using default value for data_type which is 'custom'" ) data_type = 'CUSTOM' return data_type
def get_result_files(self): """Get execution results dir and files """ if self.res_startdir is not None: results_execdir = file_Utils.createDir_addtimestamp(self.res_startdir, self.nameonly) rfile = self.get_exec_file_by_type("Results", results_execdir) elif self.res_startdir is None: results_location = xml_Utils.getChildTextbyParentTag(self.filepath, 'Details', 'Resultsdir') #get default results directory default_xml = Tools.__path__[0] + os.sep + 'w_settings.xml' default_resultsdir = get_credentials(default_xml, 'def_dir', ['Resultsdir'], 'Setting') #use the default directory if user didn't define it in test case/test suite/project if results_location is None or results_location is False: if default_resultsdir['Resultsdir'] is not None: results_location = default_resultsdir['Resultsdir'] if results_location is None or results_location is False\ or str(results_location).strip() == "": results_execdir = self.create_def_exec_dir() #proj_exec_dir rfile = self.get_exec_file_by_type("Results", results_execdir) elif results_location is not None and results_location is not False: results_location_rel = str(results_location).strip() results_location = file_Utils.getAbsPath(results_location_rel, os.path.dirname(self.filepath)) rfile, results_execdir = self.checkdir_create_file(results_location, "Results") # print "printing results_execdir: ", results_execdir resultfile = file_Utils.getNewExtension(rfile, "xml") resultsdir = os.path.dirname(resultfile) return resultfile, resultsdir, results_execdir
def check_get_datafile(self): """Check InputDatFile tag in the xml file and based on the values return the datafile to be used for the testcase/testsuite - If user provided a datafile, will use it. - If user specified 'Default' will use the default datafile - If user did not provide any value will use default datafile - If user specified 'NODATA' will print a msg saying so. """ datafile = xml_Utils.getChildTextbyParentTag(self.filepath, 'Details', 'InputDataFile') if datafile is None or datafile is False or \ str(datafile).strip() == "": if self.filetype == "tc": #print "get default datatype for testcase" datafile = get_default_xml_datafile(self.filepath) if self.filetype == "ts": # Check if test suite datatype starts with iterative. # If yes then get default datafile else set it as false # this is because at testsuite level input datafile is # supported only if the suite datatype is iterative seq/parallel datatype = self.check_get_datatype(False) if str(datatype).lower().startswith("iterative"): datafile = get_default_xml_datafile(self.filepath) else: datafile = False elif self.filetype == "proj": datafile = False elif str(datafile).strip().upper() == "DEFAULT": print_info( "This testcase will be executed using the default InputDataFile" ) datafile = get_default_xml_datafile(self.filepath) elif str(datafile).strip().upper() == 'NO_DATA': print_info('This test case will be run without any InputDataFile') datafile = "NO_DATA" elif datafile is not None and datafile is not False: datafile_rel = str(datafile).strip() datafile = file_Utils.getAbsPath(datafile_rel, os.path.dirname(self.filepath)) if str(datafile).strip().upper( ) != 'NO_DATA' and datafile is not False: if not file_Utils.fileExists(datafile): print '\n' print_error("!!! *** InputDataFile does not exist in provided path:"\ "{0} *** !!!".format(datafile)) return datafile
def check_get_runtype(self): """Check and get the runtype for testcase """ if xml_Utils.nodeExists(self.filepath, 'Runtype'): run_type = xml_Utils.getChildTextbyParentTag(self.filepath, 'Details', 'Runtype') if run_type is not None and run_type is not False: run_type = str(run_type).strip() supported_values = ['sequential_keywords', 'parallel_keywords'] if run_type.lower() not in supported_values: print_warning("unsupported value '{0}' provided for run_type," "supported values are "\ "'{1}' and case-insensitive".format(run_type, supported_values)) print_info("Hence using default value for run_type which is 'sequential_keywords'") run_type = 'SEQUENTIAL_KEYWORDS' else: run_type = "SEQUENTIAL_KEYWORDS" return run_type