Best Python code snippet using slash
api.py
Source:api.py
1import os2import ast3import threading4import xml.etree.ElementTree as ET5from datetime import datetime6from datetime import date7from flask_cors import CORS8from flask import Response9from flask import Flask, request, jsonify10app = Flask(__name__)11CORS(app)12app.config['JSON_SORT_KEYS'] = False13app.config["DEBUG"] = True14XML_PATH = os.environ['XML_PATH']15RESULTS_PATH = os.environ['RESULTS_PATH']16# errors17TEST_TAG_NOT_FOUND_404 = Response("Test tag not found in tests list.", status=404, mimetype='text/plain')18INVALID_TEST_TAG_403 = Response('Invalid test tag', status=403, mimetype='text/plain')19TAG_ALREADY_IN_RUN_403 = Response('Tag is already in run.', status=403, mimetype='text/plain')20TEST_PARAMS_NOT_VALID_403 = Response('Test params are not valid.', status=403, mimetype='text/plain')21TEST_RESULT_NOT_FOUND_404 = Response('Test result not found.', status=404, mimetype='text/plain')22RUN_NOT_FOUND_404 = Response(f'Requested run not found in {RESULTS_PATH}.', status=404, mimetype='text/plain')23TEST_VARS_FILE_NOT_FOUND_400 = Response('Test vars file not found. Run might be corrupted.',24 status=400,25 mimetype='text/plain')26TEST_VARS_NOT_FOUND_400 = Response('Cannot parse vars for test. File might be corrupted.',27 status=400,28 mimetype='text/plain')29OK_202 = Response(status=202)30OK_200 = Response(status=200)31class TagNotFound(Exception):32 pass33def to_bool(val):34 if val == 'True':35 return True36 return False37def create_test(test_tag):38 test = ET.Element('test')39 test.set('tag', test_tag)40 test.set('valid', 'false')41 test.set('active', 'false')42 ET.SubElement(test, 'path')43 ET.SubElement(test, 'pn')44 ET.SubElement(test, 'sapUser')45 ET.SubElement(test, 'password')46 ET.SubElement(test, 'args')47 return test48def valid_test_tag(test_collection, new_tag):49 if ' ' in new_tag:50 return False51 if '/' in new_tag:52 return False53 if '\\' in new_tag:54 return False55 if test_collection.find(f'./test[@tag="{new_tag}"]'):56 return False57 return True58def get_test_from_collection(test_collection, test_tag):59 test = test_collection.find(f'./test[@tag="{test_tag}"]')60 if test:61 return test62 return None63def check_test_validity(test):64 for prop in test:65 if prop.tag != 'args':66 if prop.text is None or prop.text == '':67 return False68 return True69def get_test_params(test):70 test_params = {}71 for param in test:72 if param.tag != 'args':73 test_params[param.tag] = param.text if param.text else ""74 else:75 test_params[param.tag] = [{'name': arg.attrib["key"], 'value': arg.attrib["value"]} for arg in param]76 return test_params77def delete_test(root, test_tag):78 test_collection = root.find('test_collection')79 test = test_collection.find(f'./test[@tag="{test_tag}"]')80 if test is None:81 raise TagNotFound82 test_collection.remove(test)83def _deactivate_test(root, test_tag):84 test_collection = root.find('test_collection')85 test = test_collection.find(f'./test[@tag="{test_tag}"]')86 if test is None:87 return False88 test.set('active', str(False))89 return True90def get_suite_tests(test_path, suite_name, suite_test):91 tests = []92 root = ET.parse(test_path)93 index = 094 for suite in root.findall('testsuite'):95 for test in suite:96 if test.find('failure') is not None:97 status = 'failure'98 elif test.find('skipped') is not None:99 status = 'skipped'100 elif test.find('error') is not None:101 status = 'broken'102 else:103 status = 'passed'104 tests.append({'testName': test.attrib['name'],105 'status': status,106 'index': str(index),107 'suiteFile': suite_name,108 'suiteTest': suite_test109 })110 index += 1111 return tests112def get_tests_from_test_params(test, test_params): # ToDo: change this name and consult the shmuck cuz this is hella shady113 tests = []114 pns = ''115 try:116 pns = ast.literal_eval(test.find('pn').text)117 except ValueError:118 pass119 if isinstance(pns, list):120 for i in range(len(pns)):121 t = test_params.copy()122 t['pn'] = pns[i]123 t['tag'] = f"{test.attrib['tag']}{i}"124 tests.append(t)125 else:126 test_params['tag'] = test.attrib['tag']127 tests.append(test_params)128 return tests129def create_run_cmd(test, result_path):130 cmd = (f'/usr/bin/python3 -m pytest -rA --junitxml={result_path} -s {test["path"]} ' # TODO131 f'--pn \'{test["pn"]}\' '132 f'--sap_user \'{test["sapUser"]}\' '133 f'--password \'{test["password"]}\' ')134 if bool(test['args']):135 args = '--args \"['136 for arg in test['args']:137 args += f'{{\'{arg["name"]}\': \'{arg["value"]}\'}}, '138 args = args[:-2]139 cmd += f'{args}]\"'140 with open(f'{result_path}_vars.txt', 'w+') as file:141 file.write(f'path:{test["path"]}\n')142 file.write(f'pn:{test["pn"]}\n')143 file.write(f'sap_user:{test["sapUser"]}\n')144 file.write(f'password:{test["password"]}\n')145 file.write(f'args:{test["args"]}\n')146 return cmd147def run_cmds(commands, path):148 for cmd in commands:149 print(cmd)150 os.system(f'{cmd} >> {path}.txt 2>&1')151def get_suite_results(suite_path):152 root = ET.parse(suite_path).getroot()153 suite_result = {154 'passed': 0,155 'errors': 0,156 'skipped': 0,157 'failures': 0158 }159 for test in root.findall('testsuite'):160 suite_result['errors'] += int(test.attrib['errors'])161 suite_result['skipped'] += int(test.attrib['skipped'])162 suite_result['failures'] += int(test.attrib['failures'])163 suite_result['passed'] += int(test.attrib['tests']) - suite_result['failures'] - suite_result['errors'] - suite_result['skipped']164 return suite_result165def append_run_results(results, new_results):166 results['errors'] += new_results['errors']167 results['skipped'] += new_results['skipped']168 results['passed'] += new_results['passed']169 results['failures'] += new_results['failures']170@app.route('/api/v1/getAllTestTags', methods=['GET'])171def get_all_tests_tags(): # find elements, also pretty useless172 root = ET.parse(XML_PATH).getroot()173 test_collection = root.find('test_collection')174 test_tags = []175 for test in test_collection:176 test_tags.append(test.attrib['tag'])177 return jsonify(test_tags)178@app.route('/api/v1/getTest/<test_tag>', methods=['GET'])179def get_test(test_tag): # change to get test params180 root = ET.parse(XML_PATH).getroot()181 test = root.find(f'./test_collection/test[@tag="{test_tag}"]')182 if test is None:183 return TEST_TAG_NOT_FOUND_404184 return jsonify(get_test_params(test=test))185@app.route('/api/v1/addTest/<test_tag>', methods=['POST'])186def add_test(test_tag):187 tree = ET.parse(XML_PATH)188 root = tree.getroot()189 test_collection = root.find('test_collection')190 if valid_test_tag(test_collection=test_collection,191 new_tag=test_tag) is False:192 return INVALID_TEST_TAG_403193 test_collection.append(create_test(test_tag))194 tree.write(XML_PATH)195 return {'tag': test_tag, 'valid': False, 'active': False}, 202196@app.route('/api/v1/removeTest/<test_tag>', methods=['DELETE'])197def remove_test(test_tag):198 tree = ET.parse(XML_PATH)199 root = tree.getroot()200 try:201 delete_test(root=root,202 test_tag=test_tag)203 except TagNotFound:204 return TEST_TAG_NOT_FOUND_404205 tree.write(XML_PATH)206 return {'tag': test_tag}, 202207@app.route('/api/v1/updateTest/<test_tag>', methods=['PATCH'])208def update_test(test_tag):209 test_params = request.json210 tree = ET.parse(XML_PATH)211 root = tree.getroot()212 test = root.find(f'./test_collection/test[@tag="{test_tag}"]')213 if test is None:214 return TEST_TAG_NOT_FOUND_404215 for key, value in test_params.items():216 if key != 'args':217 test.find(key).text = value218 else:219 args = ET.Element('args')220 for arg in value:221 if arg['name'] != '':222 elem = ET.SubElement(args, 'arg')223 elem.set('key', arg['name'])224 elem.set('value', arg['value'])225 test.remove(test.find('args'))226 test.append(args)227 test.attrib['valid'] = str(check_test_validity(test))228 tree.write(XML_PATH)229 return {'testTag': test_tag, 'valid': to_bool(test.attrib['valid'])}, 202230@app.route('/api/v1/SetTestActiveState/<test_tag>', methods=['PATCH'])231def set_test_active_state(test_tag): # activate test232 json = request.json233 tree = ET.parse(XML_PATH)234 root = tree.getroot()235 test_collection = root.find('test_collection')236 test = get_test_from_collection(test_collection=test_collection,237 test_tag=test_tag)238 if test is None:239 return TEST_TAG_NOT_FOUND_404240 if check_test_validity(test) is False:241 return TEST_PARAMS_NOT_VALID_403242 test.attrib['active'] = str(json['active'])243 tree.write(XML_PATH)244 return {'testTag': test_tag, 'active': json['active']}, 202245@app.route('/api/v1/getAllActiveTests', methods=['GET'])246def get_all_active_tests():247 root = ET.parse(XML_PATH).getroot()248 test_collection = root.find('test_collection')249 active_tests = []250 for test in test_collection:251 active_tests.append({'tag': test.attrib['tag'], 'active': test.attrib['active']})252 return jsonify(active_tests)253@app.route('/api/v1/getAllTestStatus', methods=['GET']) # deprecated254def get_all_tests_status():255 root = ET.parse(XML_PATH).getroot()256 test_collection = root.find('test_collection')257 return jsonify([dict(zip(['tag', 'valid'], [elem.attrib['tag'], elem.attrib['valid']]))258 for elem in test_collection])259@app.route('/api/v1/renameTest', methods=['PATCH'])260def rename_test(old_tag, new_tag):261 root = ET.parse(XML_PATH).getroot()262 test = root.find(f'./test_collection/test[@tag="{old_tag}"]')263 if test is None:264 return TEST_TAG_NOT_FOUND_404265 test.set('tag', new_tag)266 for test in root.find('run'):267 if test.text == old_tag:268 test.text = new_tag269 response = jsonify({'testTag': new_tag})270 return response, 202271@app.route('/api/v1/getAllTests', methods=['GET'])272def get_all_tests():273 root = ET.parse(XML_PATH).getroot()274 test_collection = root.find('test_collection')275 return jsonify([dict(zip(['tag', 'valid', 'active'],276 [elem.attrib['tag'], to_bool(elem.attrib['valid']), to_bool(elem.attrib['active'])]))277 for elem in test_collection])278@app.route('/api/v1/runTests', methods=['PUT'])279def run_tests():280 root = ET.parse(XML_PATH).getroot()281 test_collection = root.find('test_collection')282 tests_for_run = []283 run_tag = f'{date.today().strftime("%d-%m-%Y")}_{datetime.now().strftime("%H-%M-%S")}'284 result_path = f'{RESULTS_PATH}{os.path.sep}{run_tag}'285 os.mkdir(result_path)286 # get all tests for run and their parameters287 for test in test_collection:288 if to_bool(test.attrib['active']) is True and to_bool(test.attrib['valid']) is True:289 tests = get_tests_from_test_params(test, get_test_params(test))290 if len(tests) > 1:291 tests_for_run.append({'tests': tests, 'tag': test.attrib['tag']})292 else:293 tests_for_run.extend(tests)294 run_commands = []295 # create a run command for each test296 for test in tests_for_run:297 if 'tests' in test:298 tag_result_path = f'{result_path}{os.path.sep}{test["tag"]}'299 os.mkdir(tag_result_path)300 for i in range(len(test['tests'])):301 run_commands.append(create_run_cmd(test=test['tests'][i],302 result_path=f'{tag_result_path}{os.path.sep}{test["tag"]}_{i}'))303 else:304 run_commands.append(run_commands.append(create_run_cmd(test=test,305 result_path=f'{result_path}{os.path.sep}{test["tag"]}')))306 threading.Thread(target=run_cmds, args=(run_commands, f'{result_path}{os.path.sep}{run_tag}')).start()307 return OK_200308@app.route('/api/v1/getRunResults/<run_tag>')309def get_run_results(run_tag):310 run_path = f'{RESULTS_PATH}{os.path.sep}{run_tag}'311 try:312 files = os.listdir(run_path)313 except FileNotFoundError:314 return RUN_NOT_FOUND_404315 run_results = {316 'passed': 0,317 'errors': 0,318 'skipped': 0,319 'failures': 0,320 }321 for file in files:322 file_path = f'{run_path}{os.path.sep}{file}'323 if file.endswith('.txt'):324 continue325 if os.path.isdir(file_path):326 for suite_test in os.listdir(file_path):327 if not suite_test.endswith('.txt'):328 append_run_results(results=run_results,329 new_results=get_suite_results(suite_path=f'{file_path}{os.path.sep}{suite_test}'))330 else:331 append_run_results(results=run_results,332 new_results=get_suite_results(suite_path=file_path))333 run_results['total'] = sum(run_results.values())334 return jsonify(run_results)335@app.route('/api/v1/getRunTests/<run_tag>')336def get_run_tests(run_tag):337 run_path = f'{RESULTS_PATH}{os.path.sep}{run_tag}'338 try:339 files = os.listdir(run_path)340 except FileNotFoundError:341 return RUN_NOT_FOUND_404342 tests = []343 for file in files:344 if file.endswith('.txt'):345 continue346 suite_path = f'{run_path}{os.path.sep}{file}'347 if os.path.isdir(suite_path):348 for suite_test in os.listdir(suite_path):349 if not suite_test.endswith('.txt'):350 tests.extend(get_suite_tests(test_path=f'{suite_path}{os.path.sep}{suite_test}',351 suite_name=file,352 suite_test=suite_test))353 else:354 tests.extend(get_suite_tests(test_path=suite_path,355 suite_name=file,356 suite_test=''))357 return jsonify(tests)358@app.route('/api/v1/getTestLog/<run_tag>/<suite_file>/<suite_test>/<index>')359def get_test_log(run_tag, suite_file, suite_test, index):360 index = int(index) # find a better solution361 file_path = f'{RESULTS_PATH}{os.path.sep}{run_tag}{os.path.sep}{suite_file}'362 try:363 if os.path.isdir(file_path):364 root = ET.parse(f'{file_path}{os.path.sep}{suite_test}')365 else:366 root = ET.parse(file_path)367 except FileNotFoundError:368 return RUN_NOT_FOUND_404369 suites = root.findall('testsuite')370 curr_index = 0371 for suite in suites:372 testcases = suite.findall('testcase')373 if len(testcases) > index:374 test_name = testcases[index].attrib['name']375 failure = testcases[index].find('failure')376 if failure is not None:377 return jsonify({'name': test_name, 'status': 'failed', 'log': failure.text})378 skipped = testcases[index].find('skipped')379 if skipped is not None:380 return jsonify({'name': test_name, 'status': 'skipped', 'log': skipped.text})381 error = testcases[index].find('error')382 if error is not None:383 return jsonify({'name': test_name, 'status': 'broken', 'log': error.text})384 return jsonify({'name': test_name, 'status': 'passed', 'log': ''})385 curr_index += len(testcases) - 1386 return TEST_RESULT_NOT_FOUND_404387@app.route('/api/v1/getAllRuns')388def get_all_runs():389 return jsonify(os.listdir(RESULTS_PATH))390@app.route('/api/v1/getTestVariables/<run_tag>/<suite_file>/<suite_test>')391def get_test_variables(run_tag, suite_file, suite_test):392 file_path = f'{RESULTS_PATH}{os.path.sep}{run_tag}{os.path.sep}{suite_file}'393 try:394 if os.path.isdir(file_path):395 test_vars_file = f'{file_path}{os.path.sep}{suite_test}_vars.txt'396 else:397 test_vars_file = f'{file_path}_vars.txt'398 except FileNotFoundError:399 return TEST_VARS_FILE_NOT_FOUND_400400 with open(test_vars_file, 'r') as file:401 test_vars = []402 for line in file.readlines():403 var = line.split(':', 1)404 if var[0] != 'args':405 try:406 test_vars.append({'name': var[0],407 'value': var[1].rstrip('\n')})408 except IndexError:409 return TEST_VARS_NOT_FOUND_400410 else:411 test_vars.append({'name': 'args', 'value': ast.literal_eval(var[1])})412 return jsonify(test_vars)413if __name__ == '__main__':...
run.py
Source:run.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# @Date : 2020-07-23 16:53:584import sys5import os6import robot7from robot.api import logger8from robot.utils.asserts import assert_not_none9from robot.api import TestSuite10from robot.api import ResultWriter11from robot.conf import RobotSettings12from robot.libraries.BuiltIn import BuiltIn13from ruamel.yaml import YAML14from ruamel.yaml.constructor import SafeConstructor15def yaml_to_obj(yaml_file):16 import codecs17 yaml = YAML()18 yaml.allow_duplicate_keys = True19 try:20 with codecs.open(yaml_file, 'rb', 'utf-8') as f:21 datas_dict = yaml.load(f)22 if not datas_dict:23 raise Exception("Please check the file: {}".format(yaml_file))24 return datas_dict25 except Exception as e:26 raise e27def get_yaml_configures(yaml_obj):28 if not yaml_obj:29 raise Exception("get_yaml_configures parameter cannot be empty")30 return yaml_obj.get('config')31def get_yaml_cases(yaml_obj):32 if not yaml_obj:33 raise Exception("get_yaml_cases parameter cannot be empty")34 return yaml_obj.get('testcases')35def get_all_py_files(path):36 if not path or not os.path.exists(path):37 raise Exception("Cannot find a path or file: {}".format(path))38 results = []39 for root, dirs, files in os.walk(path):40 if not files:41 raise Exception(42 "Cannot find any keywords files in the path: {}".format(path))43 for file in files:44 if file.endswith('.py'):45 results.append(path + "/" + file)46 return results47def create_test_keyword(suite_test, name, args=None, kw_type=None):48 if not args:49 suite_test.keywords.create(name, type=kw_type)50 else:51 suite_test.keywords.create(name, args=args, type=kw_type)52def run_function(suite_test, step_functions, kw_name, kw_args, kw_type):53 ''' 54 run functions which also as keywords55 set return value as robot variable56 saved varibale type only support: global, suite, test, common varibale57 '''58 # print(step_functions)59 if step_functions:60 suite_test.keywords.create(61 'run_function_keyword', args=[step_functions, kw_name, kw_args], type=kw_type)62def create_step(suite_test, obj):63 for step in obj:64 kw_name = step.get('keyword')65 kw_args = step.get('args')66 kw_type = step.get('type')67 b_func = step.get('run_func')68 if b_func:69 run_function(suite_test, b_func, kw_name, kw_args, kw_type)70 else:71 create_test_keyword(suite_test, kw_name, kw_args, kw_type)72def create_case_step(suite_test, testcases):73 if not testcases:74 logger.warn("If config test-steps into yaml file will be better")75 return76 create_step(suite_test, testcases)77def create_assertion_step(suite_test, assertions):78 if not assertions:79 logger.warn("If config assertions into yaml file will be better")80 return81 create_step(suite_test, assertions)82def get_setup_or_teardown_numbers(suite_steps, kw_type='setup'):83 numbers = [index for index, item in enumerate(84 suite_steps) if item.get('type') == kw_type]85 if len(numbers) >= 2:86 raise Exception(87 "At least two {} were found in config steps: {}".format(kw_type, suite_steps))88def order_suite_setup_and_teardown(suite_steps):89 '''90 If find teardown and setup in steps,91 then make sure create setup keyword first92 '''93 get_setup_or_teardown_numbers(suite_steps)94 get_setup_or_teardown_numbers(suite_steps, 'teardown')95#96 b_teardown = False97 index_td = 098 import copy99 cp_steps = copy.deepcopy(suite_steps)100 for index, step in enumerate(suite_steps):101 kw_type = step.get('type')102 if kw_type == 'teardown':103 b_teardown = True104 index_td = index105 if kw_type == 'setup':106 if b_teardown and index > index_td:107 cp_steps[index_td], cp_steps[index] = cp_steps[index], cp_steps[index_td]108 return cp_steps109def import_libs_by_path(suite, libs_path):110 if not libs_path:111 return112 for path in libs_path:113 libs = get_all_py_files(path)114 for kw_file in libs:115 suite.resource.imports.library('{}'.format(kw_file))116yaml_file = '..\\cases.yaml'117yaml_obj = yaml_to_obj(yaml_file)118configs = get_yaml_configures(yaml_obj)119testcases = get_yaml_cases(yaml_obj)120suite_name = configs.get('suite_name')121librarys = configs.get('librarys')122librarys_path = configs.get('librarys_path')123suite_steps = configs.get('steps')124setup_numbers = [1 for item in suite_steps if item.get('type') == 'setup']125teardown_numbers = [126 1 for item in suite_steps if item.get('type') == 'teardown']127suite = TestSuite(suite_name)128# suite.resource.imports.library('./mykeywords.py')129for _lib in librarys:130 # print(_lib)131 suite.resource.imports.library('{}'.format(_lib))132import_libs_by_path(suite, librarys_path)133# un-comment follows line, see what happen134suite_steps = order_suite_setup_and_teardown(suite_steps)135create_case_step(suite, suite_steps)136# print(suite.keywords)137for case in testcases:138 test_case_name = case.get('name')139 tags = case.get('tags')140 steps = case.get('steps')141 assertions = case.get('assertions')142 # test = suite.tests.create(test_case_name, tags=tags)143 test = suite.tests.create(test_case_name, tags=tags)144 # test.keywords.create('test_builtin_keyword')145 create_case_step(test, steps)146 create_assertion_step(test, assertions)147path = "reports"148apiname = 'skynet'149options = {150 "output": "{}-output.xml".format(apiname),151 "log": "{}-log.html".format(apiname),152 "report": "{}-reporter.html".format(apiname),153 "outputdir": path,154 # "include": ['CI']155 # "exclude": ['SMOKE']156}157settings = RobotSettings(options)158suite.configure(**settings.suite_config)159result = suite.run(settings, critical='smoke')160ResultWriter(settings.output if settings.log161 else result).write_results(...
forking_test_runner.py
Source:forking_test_runner.py
1#!/usr/bin/env python2# Copyright (c) 2010 Stanford University3#4# Permission to use, copy, modify, and distribute this software for any5# purpose with or without fee is hereby granted, provided that the above6# copyright notice and this permission notice appear in all copies.7#8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.15"""Runs each unit test in a separate process.16This is useful for finding which tests cause crashes or enter infinite loops.17Pass any arguments to output timing statistics.18"""19import os20import re21import signal22import subprocess23import sys24import time25FAIL_AFTER_SECONDS = 2.026ignore = \27"""terminate called after throwing an instance of 'std::invalid_argument'28 what(): No test named <%s> found in test <All Tests>."""29cppunit_fail_header = """!!!FAILURES!!!30Test Results:31Run: 1 Failures: 1 Errors: 0321) test: RAMCloud::%s::%s (F) """33signals = dict([(getattr(signal, name), name)34 for name in dir(signal) if name.startswith('SIG')])35p = subprocess.Popen(['git', 'symbolic-ref', '-q', 'HEAD'],36 stdout=subprocess.PIPE)37p.wait()38git_branch = re.search('^refs/heads/(.*)$', p.stdout.read())39if git_branch is None:40 obj_dir = 'obj'41else:42 git_branch = git_branch.group(1)43 obj_dir = 'obj.%s' % git_branch44tests = []45for name in os.listdir('src/'):46 if name.endswith('Test.in.cc') or name.endswith('Test.cc'):47 suite = None48 for line in open('src/%s' % name):49 m = re.match('\s*CPPUNIT_TEST_SUITE\((.*)\);', line)50 if m:51 suite = m.group(1)52 continue53 m = re.match('\s*CPPUNIT_TEST\((.*)\);', line)54 if m:55 test = m.group(1)56 tests.append((suite, test))57 continue58print 'Running %d tests...' % len(tests)59ok = 060failed = 061suite_times = {}62test_times = {}63for (suite, test) in tests:64 start = time.time()65 process = subprocess.Popen(['./%s/test' % obj_dir,66 '-t', 'RAMCloud::%s::%s' % (suite, test)],67 stdout=subprocess.PIPE,68 stderr=subprocess.STDOUT)69 rc = None70 while True:71 rc = process.poll()72 now = time.time()73 if rc is not None:74 break75 if now - start > FAIL_AFTER_SECONDS:76 print "Killing %s::%s" % (suite, test)77 process.kill()78 break79 if rc != 0:80 output = process.stdout.read().strip()81 if output == (ignore % test):82 print "Ignored: RAMCloud::%s::%s" % (suite, test)83 continue84 if rc is None:85 why = ' by taking too long (over %ss)' % FAIL_AFTER_SECONDS86 elif rc == 1:87 why = '' # usual CPPUNIT failure88 elif rc > 1:89 why = ' with return value %d' % rc90 elif rc < 0:91 why = ' from signal %s' % signals[-rc]92 cfh = cppunit_fail_header % (suite, test)93 if output.startswith(cfh):94 output = output[len(cfh):]95 print '%s::%s failed%s%s\n' % (suite, test, why,96 ':\n%s' % output if output else '')97 failed += 198 else:99 if suite in suite_times:100 suite_times[suite] += now - start101 else:102 suite_times[suite] = now - start103 suite_test = '%s::%s' % (suite, test)104 if suite_test in test_times:105 test_times[suite_test] += now - start106 else:107 test_times[suite_test] = now - start108 ok += 1109print '%d tests passed, %d failed' % (ok, failed)110def print_timing(title, times, num=None):111 print title112 print '=' * len(title)113 l = times.items()114 l.sort(key=lambda x: x[1], reverse=True)115 if num is not None:116 l = l[:num]117 max_name_length = max([len(name) for name, t in l])118 for name, t in l:119 print '%s%s' % (name.ljust(max_name_length),120 ('%0.02fms' % (t * 1000)).rjust(8))121if len(sys.argv) > 1:122 print123 print 'Total time: %0.02fms' % (sum(suite_times.values()) * 1000)124 print125 print_timing('Suite Timing', suite_times)126 print...
test_adminka_API.py
Source:test_adminka_API.py
1import requests2from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterGradesInHomework3from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterSubjectsInHomework4from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterTypeDz5from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterStatusDz6from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterFormatAccess7from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterWeeks8from API.AdminPanel.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import TestFilterQuarter9# from API.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import TestFilterYears10from API.AdminPanel.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import TestTrainingFormat11from API.AdminPanel.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import TestFilterSchool12from API.AdminPanel.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import \13 TestFilterSubjectsInAssessmentsJournal14from API.AdminPanel.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import \15 TestFilterGradesInAssessmentsJournal16# from API.admin_panel_filters.test_001_filter_assessments_journal_tab_home_school import TestFilterUser17from API.AdminPanel.admin_panel_filters.test_002_filter_homework_tab_home_school import TestFilterLabels18from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterSchoolsChats19from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterGradesInChats20from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterSubjectsChats21from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterAccessChats22from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterLabelsChats23from API.AdminPanel.admin_panel_filters.test_003_filter_chats import TestFilterUserChats24def suite():25 suite_test = requests.TestSuite()26 suite_test.addTest(requests.makeSuite(TestFilterGradesInHomework))27 suite_test.addTest(requests.makeSuite(TestFilterSubjectsInHomework))28 suite_test.addTest(requests.makeSuite(TestFilterTypeDz))29 suite_test.addTest(requests.makeSuite(TestFilterStatusDz))30 suite_test.addTest(requests.makeSuite(TestFilterFormatAccess))31 suite_test.addTest(requests.makeSuite(TestFilterQuarter))32 # suite_test.addTest(requests.makeSuite(TestFilterYears))33 suite_test.addTest(requests.makeSuite(TestTrainingFormat))34 suite_test.addTest(requests.makeSuite(TestFilterSchool))35 suite_test.addTest(requests.makeSuite(TestFilterSubjectsInAssessmentsJournal))36 suite_test.addTest(requests.makeSuite(TestFilterGradesInAssessmentsJournal))37 # suite_test.addTest(requests.makeSuite(TestFilterUser))38 suite_test.addTest(requests.makeSuite(TestFilterLabels))39 suite_test.addTest(requests.makeSuite(TestFilterWeeks))40 suite_test.addTest(requests.makeSuite(TestFilterSchoolsChats))41 suite_test.addTest(requests.makeSuite(TestFilterGradesInChats))42 suite_test.addTest(requests.makeSuite(TestFilterSubjectsChats))43 suite_test.addTest(requests.makeSuite(TestFilterAccessChats))44 suite_test.addTest(requests.makeSuite(TestFilterLabelsChats))45 suite_test.addTest(requests.makeSuite(TestFilterUserChats))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!