def run_suite(resultdir): curdir = os.getcwd() suitefile = os.path.join(curdir, 'suite.conf') suites = [] if os.path.exists(suitefile): fh = open(suitefile, 'r') for line in fh: if 'suite_' in line: line = line.replace("\n", "") line = line.replace("\t", "") line = line.replace("\r", "") line = line.lower() suites.append(line) configfiles = [0]*len(suites) for dirname,dir,files in os.walk(curdir): for file in files: if 'config_current.ini' in file: suitepath = os.path.split(dirname) suitename = suitepath[1] suitename = suitename.lower() if suitename in suites: index = suites.index(suitename) configpath = os.path.join(dirname,file) configfiles.pop(index) configfiles.insert(index, configpath) parentdir = os.path.split(curdir) resultlocation = os.path.join(resultdir,parentdir[1]) if os.path.exists(resultlocation): shutil.rmtree(resultlocation, ignore_errors='true') for each in configfiles: sourcedir = os.path.dirname(each) if os.path.exists(os.path.join(sourcedir, "Results")): shutil.rmtree(os.path.join(sourcedir, "Results"), ignore_errors='true') os.chdir(sourcedir) command = ("nosetests -c %s" % each) os.system(command) suitename = os.path.split(sourcedir) destidir = os.path.join(resultlocation, suitename[1]) shutil.copytree(sourcedir, destidir, symlinks=False, ignore=shutil.ignore_patterns('*.py', '*.ini', '*.pyc', '*.coverage')) main_index.write_main_index(resultlocation) os.chdir(curdir)
def OK_clicked(self): self.ui.Result_textEdit.clear() testcaselocation = str(self.ui.TestCaseLocation_lineEdit.displayText()) resultlocation = str(self.ui.ResultLocation_lineEdit.displayText()) if os.path.exists(testcaselocation) and os.path.exists(resultlocation): parentdir = os.path.split(testcaselocation) self.ui.Result_textEdit.clear() if "suite_" in parentdir[1]: parentdir1 = os.path.split(parentdir[0]) resultdir = os.path.join(str(resultlocation), parentdir1[1]) else: for dirn,dir,files in os.walk(testcaselocation): listdir=os.listdir(dirn) for each in listdir: if 'suite_' in each: parentdirectory = os.path.split(dirn) resultdir = os.path.join(str(resultlocation), parentdirectory[1]) if os.path.exists(resultdir): shutil.rmtree(resultdir, ignore_errors='true') else: os.mkdir(resultdir) if self.ui.ResultLocation_lineEdit.displayText() != " " and self.ui.TestCaseLocation_lineEdit.displayText() != " ": if len(suites) != 0: for i in range(0,model.rowCount()): modelitem = model.item(i) if modelitem.checkState() == 2: children = [] for j in range(0,modelitem.rowCount()): childitem = modelitem.child(j) if childitem.checkState() == 2: children.append(str(childitem.text())) if len(children) != 0: sourcedir = suites[i] suitename = os.path.split(sourcedir) self.setWindowTitle("Executing tests....") config_temp_path = os.path.join(suites[i],"config_temp.ini") config_path = os.path.join(suites[i],"config.ini") fh = open(config_temp_path, "w+") fh1 = open(config_path, "rb") for line in fh1: if 'tests=' in line: newline = ("tests=%s" % children) newline = newline.replace("[","") newline = newline.replace("]","") newline = newline.replace(" ","") newline = newline.replace("'","") fh.write(newline) else: fh.write(line) time.sleep(10) try: destidir = os.path.join(resultdir, suitename[1]) results = os.path.join(sourcedir, "Results") if os.path.exists(results): shutil.rmtree(results, ignore_errors='true') if os.path.exists(config_temp_path): os.chdir(suites[i]) subprocess.Popen(["nosetests", "-c", "config_temp.ini"]) fh.close() fh1.close() sys.path.append("..") import main_index time.sleep(5) shutil.copytree(sourcedir, destidir, symlinks=False, ignore=shutil.ignore_patterns('*.py', '*.ini', '*.pyc', '*.coverage')) self.ui.Result_textEdit.setTextColor(Qt.green) mesg = ("Suite: %s executed successfully" % suitename[1]) self.ui.Result_textEdit.append(mesg) self.setWindowTitle("Test Framework") except: self.ui.Result_textEdit.setTextColor(Qt.red) mesg = ("Suite: %s not executed successfully" % suitename[1]) self.ui.Result_textEdit.append(mesg) self.ui.Result_textEdit.setTextColor(Qt.black) if os.path.exists(resultdir): main_index.write_main_index(str(resultdir)) elif os.path.exists(testcaselocation) or os.path.exists(resultlocation): self.ui.Result_textEdit.clear() if os.path.exists(testcaselocation) == False: self.ui.Result_textEdit.setTextColor(Qt.red) mesg = ("Test case directory does not exist. Please verify.") self.ui.Result_textEdit.append(mesg) elif os.path.exists(resultlocation) == False: self.ui.Result_textEdit.setTextColor(Qt.red) mesg = ("Result location does not exist. Please verify.") self.ui.Result_textEdit.append(mesg) else: self.ui.Result_textEdit.clear() self.ui.Result_textEdit.setTextColor(Qt.red) mesg = ("Test case directory and result location are not valid. Please verify.") self.ui.Result_textEdit.append(mesg)