def __init__(self,config=Config,result_handler=None,**kwargs): self.config = config if result_handler and getattr(result_handler,'handle',None): self.result_handler = result_handler else: from resultHandler import xmlHandler self.result_handler = xmlHandler() testdir = self.config.testdir # scan test file self.testcases = {} # 管理测试用例 #self.testCasesFile = {}#文件与testcase对应 for testfile in self.get_test_files(): # 构造测试并添加,视情况看是否需要启用新定时器 testcase = TestCase() file_name = os.path.sep.join((os.getcwd(),testfile)) try: xml = self.parsexml(testfile) testcase.fromxml(xml) if testcase.is_valid(): self.testcases[testcase.name] = testcase self.file2testcase[file_name] = testcase.name #后来添加 #self.testCasesFile[testfile] = testcase.name else: raise Exception,'no testcase found of empty testcase' except: log_exce('invalid testcase definition in file : %s, will be discard.'%testfile) log.info('load test file done! there are %d valided testcases.'%len(self.testcases.keys()))
def __init__(self, parent = None): super(MyView, self).__init__(parent) self.setupUi(self) # setup model tc = TestCase('a.xml') tc.load(tc.tcFileName) self.model = MyModel(tc) self.treeView.setModel(self.model) ''' connect signal/slot pairs ''' #self.aboutButton.clicked.connect(self.about)
def parse(self, xmlPath): doc = minidom.parse(xmlPath) root = doc.documentElement nameNodes = self.getXmlNodes(root, 'name') caseName = self.getNodeValue(nameNodes[0]) apList = [] apsNodes = self.getXmlNodes(root, 'aps') apNodes = self.getXmlNodes(apsNodes[0], 'ap') for apNode in apNodes: model = self.getAttrValue(apNode, 'model') mac = self.getAttrValue(apNode, 'mac') apList.append({"model":model, "mac":mac}) dutList = [] dutsNodes = self.getXmlNodes(root, 'duts') dutNodes = self.getXmlNodes(dutsNodes[0], 'dut') for dutNode in dutNodes: model = self.getAttrValue(dutNode, 'model') mac = self.getAttrValue(dutNode, 'mac') dutList.append({"model":model, "mac":mac}) scenarioList = [] scenariosNodes = self.getXmlNodes(root, 'scenarios') scenarioNodes = self.getXmlNodes(scenariosNodes[0], 'scenario') for scenarioNode in scenarioNodes: scenarioName = self.getAttrValue(scenarioNode, 'name') categoryNodes = self.getXmlNodes(scenarioNode, 'category') categoryValue = self.getNodeValue(categoryNodes[0]) scriptNodes = self.getXmlNodes(scenarioNode, 'script') scriptValue = self.getNodeValue(scriptNodes[0]) parameterNodes = self.getXmlNodes(scenarioNode, 'parameter') parameterValue = self.getNodeValue(parameterNodes[0]) scenario = Scenario(scenarioName, categoryValue, scriptValue, parameterValue) scenarioList.append(scenario) testCase = TestCase() testCase.name = caseName testCase.apList = apList testCase.dutList = dutList testCase.scenarioList = scenarioList return testCase
class TestRunner(object): """Test case running tool Given a test case path, the tool will parse the case structure data, and call connection tool to execute the case command, a output will be saved to testcase profile directory. Test case data have following structures: setup: hold sqls to setup the environment before running the case One test case support many permutation to be executed, each permutation should be run entirely clean environment, so for each permutation, we need to do the environment setup, and also SHOULD do environment tear down(teardown is important and this will make the next setup successful), Support dryrun mode, which will not setup any real db connections, it just print the step sequence for some debuging use. :type case_path: str :param case_path: absolute path of the test case data file """ def __init__(self, case_path): self._testcase = TestCase(case_path) self._maint_session = None self._sessions = {} self._waitings = [] self._backend_pids = [] self._errorsteps = {} # {step: errormsg} #def run(self, dry_run=False): def run(self, case_type): """TestRunner execution interface, it will control the testcase running main procedure. it also can run a dry run. procedures: >>> parse the testcase raw data file to a structure >>> setup maintainance and test running db connections, the >>> maintainance session will execute environment related >>> commands or some management operations >>> collect something which is useful for later use >>> start the permutation executions >>> clear the maintainace and test running db connections :type case_type: String : rse_keywords_listparam case_type: Tell the function which kind of case is running,spec or spt ..note: all the sqls in setup and teardown section will have a list type sqls in step is a string type, refer to the description of parser file for detail reason """ self._testcase.build() # if dry_run: # self._start_dry_run() # return # if case_type == 'python': # self._start_exec_keywords() self._make_maint_session() self._make_test_sessions() self._collect_backend_pids() self._start_permutations() self._clear_test_sessions() self._clear_maint_session() # def _start_exec_keywords(self): # command_list = self._parse_keywords_list() # if len(command_list) == 0: # print('no shell command, continue other test steps') # else: # for cmd in command_list: # length = len(cmd) # i = 0 # exec_cmd = 'python ' # while i<length: # exec_cmd = exec_cmd + cmd[i] + ' ' # i = i+1 # os.system(exec_cmd) # def _parse_keywords_list(self): # commands = [] # keywords_list = self._testcase.keywords() # if len(keywords_list) == 0: # print('there is no shell commands') # else: # xmlpath=os.path.abspath("keywords.xml") # dom = xml.dom.minidom.parse(xmlpath) # root = dom.documentElement # keywordslist = root.getElementsByTagName('operation') # # for item in keywords_list: # item = item.split() # for keyword in keywordslist: # if keyword.getAttribute('keyword') == item[0]: # func = keyword.getAttribute("script") # item[0]=str(func) # commands.append(item) # return commands def _clear_tmp_data(self): self._waitings = [] self._errorsteps = {} self._testcase.reset() def _load_setup_sqls(self): """get the sqls from testcase setup module, and execute them """ logger.debug("LOADING SETUP SQLS") for setup in self._testcase.setups(): helper = setup.sqlhelper() helper.execute(self._maint_session) output = helper.output() if output: print(output) def _load_teardown_sqls(self): """get the sqls from testcase teardown module, and execute them """ logger.debug("LOADING TEARDOWN SQLS") for teardown in self._testcase.teardowns(): helper = teardown.sqlhelper() helper.execute(self._maint_session) output = helper.output() if output: print(output) def _load_session_setup_sqls(self): """get the sqls from each session level setup module, and execute them in its session, all the steps for each session should be run after session setup. """ logger.debug("LOADING SESSION SETUP SQLS") for setup in self._testcase.session_setups(): session_tag = setup.session() dbsession = self._get_session_by_tag(session_tag) if dbsession is None: raise Exception("cannot find session by tag %s" % session_tag) helper = setup.sqlhelper() helper.execute(dbsession) output = helper.output() if output: print(output) def _load_session_teardown_sqls(self): """get the sqls from each session level teardown model, and execute them in its session, teardown operations should be run after each session test run. """ logger.debug("LOADING SESSION TEARDOWN SQLS") # fetch session teardown sqls from test case for teardown in self._testcase.session_teardowns(): session_tag = teardown.session() dbsession = self._get_session_by_tag(session_tag) if dbsession is None: raise Exception("cannot find session by tag %s" % session_tag) helper = teardown.sqlhelper() helper.execute(dbsession) output = helper.output() if output: print(output) def _start_dry_run(self): """only print the sqls for setup, teardown, permutation in sequence no actual database dependence will be used. """ print("----------DRY RUN MOD----------") print(str(self._testcase)) round_num = 1 for steps in self._testcase.next_permutation_steps(): print("starting permutation: %s" % " ".join([step.tag() for step in steps])) print("==LOADING SETUP SQLS==") for setup in self._testcase.setups(): print("Session(%s): %s" % ("Maint", setup.sql())) print("==LOADING SESSION SETUP SQLS==") for setup in self._testcase.session_setups(): print("Session(%s): %s" % (setup.session(), setup.sql())) print('==LOADING PERMUTATION STEPS SQlS==') for step in steps: print("Session(%s): %s" % (step.session(), step.sql())) print("==LOADING SESSION TEARDOWN SQLS==") for teardown in self._testcase.session_teardowns(): print("Session(%s): %s" % (teardown.session(), teardown.sql())) print("==LOADING TEARDOWN SQLS==") for teardown in self._testcase.teardowns(): print("Session(%s): %s" % ("Maint", teardown.sql())) print() round_num += 1 def _start_permutations(self): """run the steps for each permutation, look up session by the step tag, and run step sqls in its session. each permutation require a entirely new environment, the means the setup and teardown model should be run for every permutation """ round_num = 1 print("Parsed test spec with %d sessions" % len(self._sessions.keys())) for steps in self._testcase.next_permutation_steps(): # print("ROUND %d START" % round_num) print() print("starting permutation: %s" % " ".join([step.tag() for step in steps])) self._clear_tmp_data() self._load_setup_sqls() self._load_session_setup_sqls() logger.debug('LOADING PERMUTATION STEPS SQLS') for step in steps: self._run_step_sqls(step) self._final_complete_waiting_steps() self._load_session_teardown_sqls() self._load_teardown_sqls() round_num += 1 def _run_step_sqls(self, step): """ execute one step sqls, firstly need to know which session the sqls need to executed in. the sql execution has possiblity to be blocked by something, for example, by last step, for some interval data lock, if it is blocked by something, we call it a waiting step. we have a waiting list to hold all the current waiting steps. if a step become a waiting step, all the later step in the same session should also be hold. Here, the case designer should notice this as expected design, and try to release the lock in next steps (the blocking step normally should not followed by the steps in same session). the waiting step can go through when the some lock was released, and we need always to check the case and let it go through, removed from waiting list, so that the later step in the session can be executed. permutation step will be run in async mode, and try to get the result in the nonblocking way, we will mark the step as waiting or not, so that we avoid to be hold there, and cannot get to next step which will release the lock. :type step: dict :param step: structure hold a entirely test case step related data """ oldstep = self._complete_previous_steps(step) # _complete_previous_steps has possiblity to make some change of # current waiting list, and may make some waiting sessions to get # through, here need to release them if oldstep: # clear the old error step message to just monitor the very # recent step error message self._try_complete_waiting_steps(STEP_NOBLOCK | STEP_RETRY) self._report_multiple_error_messages(oldstep) session_tag = step.session() dbsession = self._get_session_by_tag(session_tag) if dbsession is None: raise Exception("cannot find session by tag %s" % session_tag) helper = step.sqlhelper() wait = False #while not helper.is_completed(): # dbsession.sendSQL(helper) # wait = self._try_complete_step(step, STEP_NOBLOCK) # if wait: # break helper.sendSQL(dbsession, self._check_lock) try: wait = self._new_try_complete_step(step, STEP_NOBLOCK) except WaitDataTimeoutException as e: raise # after execute a step, check wether it can make some waiting # steps to go through self._try_complete_waiting_steps(STEP_NOBLOCK | STEP_RETRY) self._report_multiple_error_messages(step) if wait: self._waitings.append(step) def _complete_previous_steps(self, step): """Check whether the session that needs to perform the next step is still blocked on an earlier step. If so, wait for it to finish. (In older versions of this tool, we allowed precisely one session to be waiting at a time. If we reached a step that required that session to execute the next command, we would declare the whole permutation invalid, cancel everything, and move on to the next one. Unfortunately, that made it impossible to test the deadlock detector using this framework, unless the number of processes involved in the deadlock was precisely two. We now assume that if we reach a step that is still blocked, we need to wait for it to unblock itself.) ..above paragraph was pasted from C version code :type step: dict :param step: structure hold a entirely test case step related data :rtype: dict :returns: the previous step in the same session which is blocking """ oldstep = None for wait_step in self._waitings: if step.session() != wait_step.session(): continue # normally the waiting list only have one entry for one # session, but we just keep the below code in the for # loop in case more session found oldstep = wait_step self._new_try_complete_step(oldstep, STEP_RETRY) self._waitings.remove(oldstep) return oldstep def _try_complete_waiting_steps(self, flags): """check all the existing waiting steps whether some of them can go through. use NOBLOCK mode, the check cannot hange to wait step to complete. """ # originally we use for loop, but when we remove a element, it seems # not working as we expected, so we just mark the to_delete item, and # remove it at last to_del = [] for step in self._waitings: wait = False wait = self._new_try_complete_step(step, flags) if wait: # still waiting, just keep it in the wait list continue else: # the step has completed either succeed, or fail #self._waitings.remove(step) to_del.append(step) # if the tag in the errorsteps, it means the complete with # fail, if not in errorsteps, should a empty error entry to # errorsteps for error combination report(align with c code) tag = step.tag() if tag not in self._errorsteps: self._errorsteps[step.tag()] = '' for step in to_del: self._waitings.remove(step) def _final_complete_waiting_steps(self): """check all the existing waiting steps whether some of them can go through. since it is the final complete, use RETRY mode to wait for all waiting step to complete """ for step in self._waitings: wait = False wait = self._new_try_complete_step(step, STEP_RETRY) self._report_error_message(step) def _try_complete_step(self, step, flags): """try to complete a step whether it is a locked or unlocked for unlocked, the getResult will return the result very soon, and for locked, it is a little complex, if the flags indicate nonblocked, try to lookup the maint session to see whether it is due to lock or some other reason to hold, if it is surely due to lock, just return True to indicate the step is locked and wait to unlock by the other session. for the case it is hang there not due to a lock, and it is wait for 60 seconds, and try to cancel the last step, if still no response and it take about 75 seconds, just quit. a retry mode should be support, we normally call this function firstly when just send the sql, and to see whether the sql is blocked, after that go to other session, then we still need to come back to complete this step, this time, we call the retry. .. note: here is problem is that although you provide a nonblock flag in the function parameter, if it is hang not for a lock, it will still block there for 60 or 75 seconds, this is an original design, since it is enough to handle the requirement, no change to be done here. .. note: there may be a very complex sql clause in a step (like begin blablabla ... commit), and the sql will be devided into sub sqls which need to be executed one by one, but only print the whole complex sql clause once, so add a new STEP type IN_SQLBLOCK which indicate the current step is a sub sql step, and try to see whether the whole sql has been printed :type step: dict :param step: structure hold a entirely test case step related data :type flags: bitarray :param flags: bits indicate the NONBLOCKED and RETRY mode :rtype: Boolen :returns: indicate whether the step is lock blocked, others cases return False """ session_tag = step.session() dbsession = self._get_session_by_tag(session_tag) block_time = 1 # block 100ms start_time = time.time() canceled = False timeout = False sqlhelper = step.sqlhelper() while True: try: timeout = dbsession.getResult(sqlhelper, block_time) except Exception as e: # failure is also a complete branch, and print complete self._errorsteps[step.tag()] = str(e) #return False break # the getResult may return a empty result, this is different # from the timeout case, for timeout it return False if timeout is True: break # getResult timeout case if flags & STEP_NOBLOCK: if self._check_lock(dbsession.get_backend_pid()): if not (flags & STEP_RETRY): print("step %s: %s <waiting ...>" % (step.tag(), step.sql())) return True now = time.time() if now - start_time > 60 and not canceled: dbsession.cancel_backend() canceled = True if now - start_time > 75: raise Exception("step %s timeout after 75 seconds" % step.tag()) if flags & STEP_RETRY: print("step %s: <... completed>" % step.tag()) else: # very triky STEP_IN_SQLBLOCK and printed flag # check for sqlblocks print workaround print("step %s: %s" % (step.tag(), step.sql())) print(sqlhelper.get_result().output()) return False def _new_try_complete_step(self, step, flags): session_tag = step.session() dbsession = self._get_session_by_tag(session_tag) sqlhelper = step.sqlhelper() while True: try: sqlhelper.try_complete_current_execution( dbsession, self._check_lock) break except WaitDataLockedException as e: if flags & STEP_NOBLOCK: if not (flags & STEP_RETRY): print("step %s: %s <waiting ...>" % (step.tag(), step.raw_sql())) return True except WaitDataTimeoutException as e: raise except WaitDataErrorException as e: self._errorsteps[step.tag()] = str(e) break if flags & STEP_RETRY: print("step %s: <... completed>" % step.tag()) else: print("step %s: %s" % (step.tag(), step.raw_sql())) output = sqlhelper.output() if output: print(output) return False def _check_lock(self, pid): """send a Maint prepare message to get the lock status for session execute the internal lock check function to check whether the pid specified is locked, if it is locked, the function will return True, ..note: pg_isolation_test_session_is_blocked function is involved in 9.6 :type pid: str or int :param pid: the process id or backend id need to check block status """ # join operation need string type list pids = [str(x) for x in self._backend_pids] sql = ("SELECT pg_catalog.pg_isolation_test_session_is_blocked" "({pid}, '{{{pids}}}')").format(pid=pid, pids=','.join(pids)) result = self._maint_session.execute(sql) rows = result.rows return rows[0][0] def _make_maint_session(self): """setup the maintainance db connection which is used for setup sqls and some management work. """ import config self._maint_session = PGConnectionManager.new_connection( config.dbname, config.user, config.password, config.host, config.port) self._maint_session.set_name('Maint') # we need to set the autocommit exeplicitly for maint session, # in PG code, we cannot see the autocommit setting, because the # PQConnect is used, and PGConnect is defalutly autocommit. self._maint_session.autocommit(True) sql = "SET client_min_messages = warning;" self._maint_session.execute(sql) def _clear_test_sessions(self): """kill the test related db connections """ for tag, conn in self._sessions.items(): logger.debug("conn(%s) has been cleared" % tag) conn.close() def _clear_maint_session(self): """kill the maintainance related db connection """ logger.debug("Maint conn has been cleared") self._maint_session.close() def _get_session_by_tag(self, tag): """each step was binded to a session, use the step session tag to find its sessions which was setup earlier. :type tag: str :param tag: session tag which is configured in case file :rtype: :class: `utils.connection.PGAsyncConnection` :returns: a database connection which has been bind given tag. """ return self._sessions.get(tag, None) def _make_test_sessions(self): """setup sessions which are used for permutation test run, session number should meet the testcase requirement, and each session should identified with the sesstion tag. """ tags = self._testcase.session_tags() import config for tag in tags: self._sessions[tag] = PGConnectionManager.new_async_connection( config.dbname, config.user, config.password, config.host, config.port) # the test session are all async connection, and there is no # autocommit property, since the default is autocommit # self._sessions[tag].autocommit(True) self._sessions[tag].set_name(tag) sql = "SET client_min_messages = warning;" self._sessions[tag].execute(sql) def _collect_backend_pids(self): """get all the backend pid related to permutation sessions and maint session, the backed pids are used as parameters to check session lock. """ self._backend_pids = [] if self._maint_session: backendpid = self._maint_session.get_backend_pid() if backendpid: self._backend_pids.append(backendpid) for tag, conn in self._sessions.items(): backendpid = conn.get_backend_pid() if backendpid: self._backend_pids.append(backendpid) def _report_error_message(self, step): """a error report method only report the target step error mssage :type step: dict :param step: session step data which is parsed from testcase data """ tag = step.tag() if tag in self._errorsteps: print(self._errorsteps[tag]) del self._errorsteps[tag] def _report_multiple_error_messages(self, step): """report the errors during the step processing since the error maybe happened during two session block case, so we try to print all the errors received from database backend for all the steps which has relations. :type step: dict :param step: session step data which is parsed from testcase data ..note: to compliant with C version code, if there is only the error for specified step, just call the _report_error_message """ tag = step.tag() extratags = [etag for etag in self._errorsteps.keys() if etag != tag] if len(extratags) == 0: self._report_error_message(step) return all_tags = [tag] all_tags.extend(extratags) if tag in self._errorsteps: if self._errorsteps[tag]: print("error in steps %s: %s" % (" ".join(all_tags), self._errorsteps[tag])) del self._errorsteps[tag] for etag in extratags: if self._errorsteps[etag]: print("error in steps %s: %s" % (" ".join(all_tags), self._errorsteps[etag])) del self._errorsteps[etag]
def __init__(self, url): TestCase.__init__(self, APP, PROG, RES) self.url = url
from sys import argv from testcase import TestCase if __name__ == '__main__': seed = 0 if len(argv) <= 1 else int(argv[1]) tc = TestCase(seed) print(tc)
def insert(self, solution: TestCase): solution.execute_test_on(self.source_code) self.solutions.append(solution)
def initial_population(self, population_size: int, test_type: int): self.solutions = [] for _ in range(population_size): test = TestCase(test_type=test_type) test.execute_test_on(self.source_code) self.solutions.append(test)
def __init__(self, name): TestCase.__init__(self, name)
def test_TestCase(): print('Running test_TestCase()') tc = TestCase('TestCaseNumberOne', [6, 4, 2]) print(tc) print()
def __generate_test_case(self, case_identification=''): """ 生成或更新测试用例 :param case_identification: 测试标识 :return: """ test_case = None try: test_case = self.test_cases[case_identification] except KeyError: self._case_id += 1 test_case = TestCase(case_id=str(self._case_id), case_mark=case_identification) self.test_cases[case_identification] = test_case # 更新除用例id和用例标识之外的其它内容 test_case.case_name = str(self.test_item_edit.text()).decode('utf-8') test_case.case_cat = self.test_cat_combox.currentIndex() test_case.case_req_track = str(self.require_trace_edit.text()) test_case.case_content = str(self.test_content_edit.text()) test_case.case_sys_prepare = str(self.sys_prepare_edit.text()) test_case.case_constraint = str(self.precondation_edit.text()) test_case.case_input = str(self.test_input_edit.text()) test_case.case_exec_procedure[:] = [] for i in range(0, self.test_procedure_tabel.rowCount()): test_case.case_exec_procedure.append([ str(self.test_procedure_tabel.item(i, 0).text()) if self.test_procedure_tabel.item(i, 0) else str(i+1), str(self.test_procedure_tabel.item(i, 1).text()) if self.test_procedure_tabel.item(i, 1) else '无', str(self.test_procedure_tabel.item(i, 2).text()) if self.test_procedure_tabel.item(i, 2) else '无', str(self.test_procedure_tabel.item(i, 3).text()) if self.test_procedure_tabel.item(i, 3) else '无', str(self.test_procedure_tabel.item(i, 4).text()) if self.test_procedure_tabel.item(i, 4) else '无', str(self.test_procedure_tabel.item(i, 5).text()) if self.test_procedure_tabel.item(i, 5) else '无', str(self.test_procedure_tabel.item(i, 6).text()) if self.test_procedure_tabel.item(i, 6) else '无', ]) test_case.case_qualified_rule = str(self.estimate_rule_eidt.text()) test_case.case_env = self.test_env_combox.currentIndex() test_case.case_qualified_method = self.qualified_method_combox.currentIndex() test_case.case_safe_secret = str(self.safe_secret_edit.text()) test_case.test_person = self.test_person_combox.currentIndex() test_case.test_join_person = str(self.test_person_join_edit.text()) test_case.test_date = str(self.test_date_timepickedit.text()) test_case.case_data = str(self.test_data_edit.text()) test_case.case_problem_sheet = str(self.problem_sheet_edit.text()) test_case.case_correct_sheet = str(self.correct_sheet_edit.text()) test_case.case_diff = str(self.test_diff_edit.text()) return test_case
def run_testcase_by_id(testcase_id, testplan='无计划'): try: testcase_info = mytestlink.getTestCase(testcase_id) # 获取测试用例基本信息 logger.info('获取测试用例信息 %s' % testcase_info) except Exception as e: logger.error('获取用例信息失败 %s,,暂停执行该用例' % e) return ('Fail',[('global_funtion_module','获取用例信息失败 %s' % e)]) # 获取用例所在套件和项目名称 response = mytestlink.getFullPath([int(testcase_id)]) response = response[str(testcase_id)] testsuite_name = '' for suit in response[1:]: testsuite_name = testsuite_name + '-' + suit testsuite_name = testsuite_name.lstrip('-') project_name = response[0] # 构造测试用例对象 testcase_name = testcase_info[0]['name'] testcase_steps = testcase_info[0]['steps'] testcase_isactive = int(testcase_info[0]['active']) testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps, testcase_isactive,project_name) testsuite_id = int(testcase_info[0]['testsuite_id']) logger.info('正在读取套件[id=%s]的协议,host,端口配置...' % (testsuite_id)) testsuite_info = mytestlink.getTestSuiteByID(testsuite_id) testsuite_name = testsuite_info['name'] testsuite_details = other_tools.conver_date_from_testlink(testsuite_info['details']) project = mytestlink.getFullPath(testsuite_id) project = project[str(testsuite_id)][0] testsuite_obj = TestSuite(testsuite_id, testsuite_name, testsuite_details, project) testsuite_conf = testsuite_obj.get_testsuite_conf() # 获取套件基本信息 if '' == testsuite_conf: logger.error('测试套件[id=%s ,name=%s]未配置协议,host,端口信息,暂时无法执行' % (testsuite_id, testsuite_name)) return ('Fail', [('golbal_function_module', '测试套件[id=%s ,name=%s]未配置协议,host,端口信息,暂时无法执行' % (testsuite_id, testsuite_name))]) try: details = json.loads(testsuite_conf) protocol = details['protocol'] host = details['host'] port = details['port'] except Exception as e: logger.error('测试套件[id=%s ,name=%s]协议,host,端口信息配置错误,未执行:%s'% (testsuite_id, testsuite_name, e)) return ('Fail',[('golbal_function_module', '测试套件[id=%s ,name=%s]协议,host,端口信息配置错误,未执行:%s'% (testsuite_id, testsuite_name, e))]) # 构造http对象 myhttp = MyHttp(protocol, host, port) try: sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \ ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)' data = (executed_history_id, testcase_id, testcase_name, testsuite_name, testplan, project_name, 'Block','0000-00-00 00:00:00') logger.info('记录测试用例到测试用例报表') testdb.execute_insert(sql_insert, data) logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name)) run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) # 记录运行时间 testcase_run_result = testcase_obj.run_testcase(myhttp, testplan) logger.info('正在更新用例执行结果') sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \ ' WHERE executed_history_id = %s and testcase_id = %s' \ ' AND project=\'%s\' AND testplan=\'%s\'' data = (testcase_run_result[0], run_time, executed_history_id, testcase_id, project_name, testplan) testdb.execute_update(sql_update, data) logger.info('指定用例[%s]已执行完' % testcase_id) return testcase_run_result except Exception as e: logger.error('运行用例出错 %s' % e) return ('Fail',[('golbal_function_module', '%s' % e)])
from testcase import TestCase import json config = './config' with open(config) as json_file: model_config = json.load(json_file) case = TestCase(model_config) print(case.input_names) print(case.get_measurements()) case.initialize(start_time=600, warmup_period=60) y = case.advance({'oveAct_activate': 1, 'oveAct_u': 0}) print(y) y = case.advance({'oveAct_activate': 1, 'oveAct_u': 1}) print(y)
def run_testplan(self, http): logger.info('正在获取测试计划[project=%s,name=%s]的测试用例' % (self.testproject, self.testplan_name)) testcases_for_testplan = mytestlink.getTestCasesForTestPlan(self.testplan_id) if [] == testcases_for_testplan: logger.warning('未获取到测试用例') return testcases_id_for_testplan = testcases_for_testplan.keys() logger.info('成功获取测试计划[project=%s,name=%s]的测试用例id:%s' % (self.testproject, self.testplan_name, testcases_id_for_testplan)) if 0 == self.active_status: logger.warning('测试计划[project=%s,name=%s]处于不活动状态[active=0],不执行' % (self.testproject, self.testplan_name)) return for testcase_id_str in testcases_id_for_testplan: testcase_id = int(testcase_id_str) testcase_info = mytestlink.getTestCase(testcase_id) # 获取测试用例基本信息 logger.info('获取测试用例信息 %s' % testcase_info) # 构造测试用例对象 testcase_steps = testcase_info[0]['steps'] testcase_name = testcase_info[0]['name'] preconditions = testcase_info[0]['preconditions'] if preconditions.find('初始化用例') != -1: logger.info('用例[id=%s, name=%s]为全局初始化用例,已跳过执行' % (testcase_id, testcase_name)) continue testcase_isactive = int(testcase_info[0]['active']) # 获取测试套件名称 full_path = mytestlink.getFullPath([testcase_id]) full_path = full_path[str(testcase_id)] testsuite_name = '' for suit in full_path[1:]: testsuite_name = testsuite_name + '-' + suit testsuite_name = testsuite_name.lstrip('-') testcase_obj = TestCase(testcase_id, testcase_name, testcase_steps, testcase_isactive, self.testproject) sql_insert = 'INSERT INTO '+testcase_report_tb +'(executed_history_id, testcase_id, testcase_name, testsuit, testplan, project, runresult, runtime)' \ ' VALUES(%s, %s, %s, %s, %s, %s, %s, %s)' data = (executed_history_id, testcase_id, str(testcase_name), testsuite_name, self.testplan_name, self.testproject, 'Block', '') logger.info('记录测试用例到测试用例报表') testdb.execute_insert(sql_insert, data) logger.info('开始执行测试用例[id=%s,name=%s]' % (testcase_id, testcase_name)) run_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) # 记录运行时间 testcase_run_result = testcase_obj.run_testcase(http, self.testplan_name) logger.info('正在更新用例执行结果') sql_update = 'UPDATE '+testcase_report_tb +' SET runresult=\"%s\", runtime=\"%s\"' \ ' WHERE executed_history_id = %s AND testcase_id = %s' \ ' AND project=\'%s\' AND testplan=\'%s\'' data = (testcase_run_result[0], run_time, executed_history_id, testcase_id, self.testproject, self.testplan_name) testdb.execute_update(sql_update, data) bulid_info = mytestlink.getLatestBuildForTestPlan(self.testplan_id) # 固定取最新的版本 bulid_version = bulid_info['name'] logger.info('正在更新testlink上测试计划[testplan_id=%s, bulid_version=%s],对应用例[testcase_id=%s]的执行结果' % (self.testplan_id, bulid_version, testcase_id)) notes = '用例[id:%s]在测试计划[testplan_id:%s,testplan_name:%s,bulidversion:%s]中的执行结果' \ % (testcase_id, self.testplan_id,self.testplan_name, bulid_version) if 'Fail' == testcase_run_result[0] or 'Error' == testcase_run_result[0]: self.__execute_case_in_testlink(testcase_id, bulid_version, 'f', notes) # f - 失败 elif 'Pass' == testcase_run_result[0]: self.__execute_case_in_testlink(testcase_id, bulid_version, 'p', notes) # f - 成功 else: pass # 如果未执行,啥都不做 logger.info('测试计划[project=%s ,testplan=%s]已执行完' % (self.testproject, self.testplan_name))
finish = False total = [0] * tc.K for col in range(tc.W): if len(fields[col]) <= row: finish = True break block = fields[col][row] total[block.color] += block.value if finish: break score += max(total) return score if __name__ == '__main__': if len(argv) < 3: usage() exit(1) with open(argv[1]) as in_file: tc = TestCase(input=in_file) with open(argv[2]) as out_file: output = [] for i, row in enumerate(out_file, start=1): try: output.append(int(row)) except Exception: raise RuntimeError("[ERROR] %d行目 出力が不正です : %s" % (i, row)) score = judge(tc, output) print("score:%d" % score)
g = interpolate.interp1d(df['time'], df[col], kind='zero') self.case.data.loc[:,col] = \ g(self.case.data.index) else: warnings.warn('The following file does not have '\ 'time column and therefore no data is going to '\ 'be used from this file as test case data.', Warning) print(f) # Close the fmu z_fmu.close() # Convert any string formatted numbers to floats. self.case.data = self.case.data.applymap(float) if __name__ == "__main__": import sys case_dir = os.path.join(\ os.path.split(os.path.split(os.path.abspath(__file__))[0])[0], 'testcase2') # Append the case directory to see the config file sys.path.append(case_dir) from testcase import TestCase case = TestCase() man = Data_Manager(case) data = man.get_data()
def __init__(self, name): self.wasRun = None TestCase.__init__(self, name)
rootDir = os.environ.get('EMULATOR_C_DIR',"\\epoc32\\winscw\\c")+"\\" else: print 'Select winscw or armv5. (Defaults to winscw if no argument supplied).' sys.exit() # Root directory for test and reference images # Test images are at imgDir + "test\\" # Reference images are at imgDir + "ref\\" imgDir = rootDir+"img\\" # Directory for log result files logDir = rootDir+"logs\\" # Directory for ONB summary file onbDir = rootDir; # HTML file name for an error message page of the test results KErrorMessagePageName = "error.html" errorLog = file(logDir + KErrorMessagePageName, "wt") # Testing the images myTest = TestCase("myTest", imgDir, logDir, onbDir) myTest.readRefImage(errorLog) myTest.readTestImage(errorLog) myTest.computeDifferences(errorLog) errorLog.close()
# 準備 problem_URL_splitted = problem_URL.split('/') contest_name = problem_URL_splitted[-3] problem_dir = os.path.join(CONFIG.TESTCASES, contest_name) testcase_preffix = problem_URL_splitted[-1] program_file_abspath = os.path.join(PATH, program_filepath) # ファイルのフォーマットチェック program = Program(program_file_abspath) if program.check_invalid_extension(): logger.warning('Invalid File extention') sys.exit(0) # testcase 取得 testcase = TestCase(problem_URL, problem_dir, testcase_preffix) testcase.get_local_testcases() if len(testcase.testcase_files) == 0 or redownload: testcase.get_samples() testcase.get_local_testcases() if len(testcase.testcase_files) == 0: logger.warning('no testcases') sys.exit(0) # コンパイル、実行コマンドの準備 program.compile() program.make_test_command() # 全テストケースチェック testcase.test_all_testcase(program.execute_command) testcase.display()