How to use case1 method in yandex-tank

Best Python code snippet using yandex-tank

main.py

Source:main.py Github

copy

Full Screen

1'''2Creating a date differential program...3'''4import logging5import datetime6def dateDifferential():7 logging.debug('Initializing dateCalculator...')8 logging.debug('Setting format...')9 format = ('%Y %B %d %I:%M:%S:%f %p')10 logging.debug('\nThis program takes the difference of the first date entered MINUS the second date entered...')11 logging.debug('Taking inputs...')12 dateTime1 = input('\nPlease a BASE DATE in the following format: YYYY mmmm dd h:m:s:ms AM/PM (e.g. 1968 June 25 06:21:12:999999 PM).')13 dateTime2 = input('Please a COMPARISON DATE in the following format: YYYY mmmm dd h:m:s:ms AM/PM (e.g. 2016 September 25 06:24:14:12342 PM).')14 logging.debug('\nProcessing BASE DATE...')15 dateTime1 = datetime.datetime.strptime(dateTime1, format)16 logging.debug(f'Value of generated datetime object: {dateTime1}')17 logging.debug('\nProcessing COMPARISON DATE...')18 dateTime2 = datetime.datetime.strptime(dateTime2, format)19 logging.debug(f'Value of generated datetime object: {dateTime2}')20 logging.debug('\nProcessing Date Differential...')21 if isinstance(dateTime1, datetime.datetime) and isinstance(dateTime2, datetime.datetime):22 logging.debug('Subtracting the two dates...')23 dateDifference = dateTime2 - dateTime124 logging.info('Manually calculate from total_seconds to get values with decimals (days/seconds/microseconds are ambiguous and include rounding-off of other components (e.g. hour))...')25 logging.info(dateDifference)26 secondsDiff = dateDifference.total_seconds()27 logging.debug('\nPresenting the difference in days/hours/minutes/seconds/microseconds/in a sentence (NA if unavailable)...')28 logging.debug('Setting up list for cleaner code...')29 listRes = [secondsDiff / 86400, secondsDiff / 3600, secondsDiff / 60, secondsDiff, secondsDiff * 1000000]30 logging.info(f'\ni. Total number of days (including fractions of days) {listRes[0]}')31 logging.info(f'ii. Total number of hours (including fractions of hours) {listRes[1]}')32 logging.info(f'iii. Total number of minutes (including fractions of minutes) {listRes[2]}')33 logging.info(f'iv. Total number of seconds (including fractions of seconds) {listRes[3]}')34 logging.info(f'v. Total number of microseconds (including fractions of microseconds) {listRes[4]}') # per documentation (in range(1000000))35 # Prepare List...36 dateDifference = str(dateDifference)37 dateDifference = dateDifference.split(':') # len 3 or 4...38 dateDiffFrontApend = []39 dateDiffBackAppend = []40 # Append List41 if dateDifference[0].find(',') != -1 and dateDifference[-1].find('.') != -1:42 dateDiffFrontApend = dateDifference[-1].split('.')43 dateDiffBackAppend = dateDifference[0].split(',')44 dDBAstep1 = dateDiffBackAppend[0]45 dDBAstep2 = dDBAstep1.split(' ')[0]46 dDBAotherNumbstep1 = dateDiffBackAppend[1].strip(' ')47 dateDiffBackAppend = [dDBAstep2, dDBAotherNumbstep1]48 elif dateDifference[-1].find('.') != -1:49 dateDiffFrontApend = dateDifference[-1].split('.')50 elif dateDifference[0].find(',') != -1:51 dateDiffBackAppend = dateDifference[0].split(',')52 dDBAstep1 = dateDiffBackAppend[0]53 dDBAstep2 = dDBAstep1.split(',')[0]54 dDBAstep3 = dDBAstep2.split(' ')[0]55 # workaround if no microseconds56 if dateDifference[-1].find('.') == -1:57 dateDiffBackAppend = [dDBAstep3, dateDiffBackAppend[1]]58 else:59 dateDiffBackAppend = [dDBAstep3, dDBAstep1.split(',')[1]]60 # Number List61 listNumbers = []62 if dateDifference[0].find(',') != -1 and dateDifference[-1].find('.') != -1:63 listNumbers = [int(dateDiffBackAppend[0]), int(dateDiffBackAppend[1]), int(dateDifference[1]), int(dateDiffFrontApend[0]), int(dateDiffFrontApend[1])]64 listLabel = [f' {listNumbers[0]} days', f' {listNumbers[1]} hours', f' {listNumbers[2]} minutes', f' {listNumbers[3]} seconds', f' {listNumbers[4]} microseconds']65 res = [idx for idx, val in enumerate(listNumbers) if val != 0] # Geeks for Geeks66 if len([x for x in listNumbers if x!=0]) == 0:67 logging.info(f'vi. The difference is NA. BASE Date and COMPARISON Date are both equal.')68 elif len([x for x in listNumbers if x!=0]) == 1:69 logging.info(f'vi. The difference is {listLabel[res[0]]}.')70 elif len([x for x in listNumbers if x!=0]) == 2:71 logging.info(f'vi. The difference is {listLabel[res[0]]}, and {listLabel[res[1]]}.')72 elif len([x for x in listNumbers if x!=0]) == 3:73 logging.info(f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, and {listLabel[res[2]]}.')74 elif len([x for x in listNumbers if x!=0]) == 4:75 logging.info(f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, {listLabel[res[2]]}, and {listLabel[res[3]]}.')76 elif len([x for x in listNumbers if x!=0]) == 5:77 logging.info(f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, {listLabel[res[2]]}, {listLabel[res[3]]}, and {listLabel[res[4]]}.')78 elif dateDifference[-1].find('.') != -1:79 listNumbers = [0, int(dateDifference[0]), int(dateDifference[1]), int(dateDiffFrontApend[0]), int(dateDiffFrontApend[1])]80 listLabel = [f' {listNumbers[0]} days', f' {listNumbers[1]} hours', f' {listNumbers[2]} minutes', f' {listNumbers[3]} seconds', f' {listNumbers[4]} microseconds']81 res = [idx for idx, val in enumerate(listNumbers) if val != 0] # Geeks for Geeks82 if len([x for x in listNumbers if x != 0]) == 0:83 logging.info(f'vi. The difference is NA. BASE Date and COMPARISON Date are both equal.')84 elif len([x for x in listNumbers if x != 0]) == 1:85 logging.info(f'vi. The difference is {listLabel[res[0]]}.')86 elif len([x for x in listNumbers if x != 0]) == 2:87 logging.info(f'vi. The difference is {listLabel[res[0]]}, and {listLabel[res[1]]}.')88 elif len([x for x in listNumbers if x != 0]) == 3:89 logging.info(90 f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, and {listLabel[res[2]]}.')91 elif len([x for x in listNumbers if x != 0]) == 4:92 logging.info(93 f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, {listLabel[res[2]]}, and {listLabel[res[3]]}.')94 elif dateDifference[0].find(',') != -1:95 listNumbers = [int(dateDiffBackAppend[0]), int(dateDiffBackAppend[1]), int(dateDifference[1]), int(dateDifference[2]), 0]96 listLabel = [f' {listNumbers[0]} days', f' {listNumbers[1]} hours', f' {listNumbers[2]} minutes', f' {listNumbers[3]} seconds', f' {listNumbers[4]} microseconds']97 res = [idx for idx, val in enumerate(listNumbers) if val != 0] # Geeks for Geeks98 if len([x for x in listNumbers if x != 0]) == 0:99 logging.info(f'vi. The difference is NA. BASE Date and COMPARISON Date are both equal.')100 elif len([x for x in listNumbers if x != 0]) == 1:101 logging.info(f'vi. The difference is {listLabel[res[0]]}.')102 elif len([x for x in listNumbers if x != 0]) == 2:103 logging.info(f'vi. The difference is {listLabel[res[0]]}, and {listLabel[res[1]]}.')104 elif len([x for x in listNumbers if x != 0]) == 3:105 logging.info(106 f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, and {listLabel[res[2]]}.')107 elif len([x for x in listNumbers if x != 0]) == 4:108 logging.info(109 f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, {listLabel[res[2]]}, and {listLabel[res[3]]}.')110 elif len(dateDifference) == 3:111 listNumbers = [0, int(dateDifference[0]), int(dateDifference[1]), int(dateDifference[2]), 0]112 listLabel = [f' {listNumbers[0]} days', f' {listNumbers[1]} hours', f' {listNumbers[2]} minutes', f' {listNumbers[3]} seconds', f' {listNumbers[4]} microseconds']113 res = [idx for idx, val in enumerate(listNumbers) if val != 0] # Geeks for Geeks114 if len([x for x in listNumbers if x!=0]) == 0:115 logging.info(f'vi. The difference is NA. BASE Date and COMPARISON Date are both equal.')116 elif len([x for x in listNumbers if x!=0]) == 1:117 logging.info(f'vi. The difference is {listLabel[res[0]]}.')118 elif len([x for x in listNumbers if x!=0]) == 2:119 logging.info(f'vi. The difference is {listLabel[res[0]]}, and {listLabel[res[1]]}.')120 elif len([x for x in listNumbers if x!=0]) == 3:121 logging.info(f'vi. The difference is {listLabel[res[0]]}, {listLabel[res[1]]}, and {listLabel[res[2]]}.')122 # Scrap the first idea...123 '''124 # Case 1: No Days... (with or without microseconds)125 if len(dateDifference.split(':')) == 3:126 case1 = dateDifference.split(':')127 # Case 1a: No microseconds128 if case1[2].find('.') == -1:129 # Inner-most case, ALL ZERO.130 if int(case1[2]) == int(case1[1]) == int(case1[0]) == 0: # 0 0 0131 logging.info('BASE Date is the same as COMPARISON Date. No Change.')132 elif int(case1[1]) == int(case1[0]) == 0: # 0 0 1133 logging.info(f'The difference is {int(case1[2])} seconds.')134 elif int(case1[2]) == int(case1[0]) == 0: # 0 1 0135 logging.info(f'The difference is {int(case1[1])} minutes.')136 elif int(case1[2]) == int(case1[1]) == 0: # 1 0 0137 logging.info(f'The difference is {int(case1[0])} hours.')138 elif int(case1[0]) == 0: # 0 1 1139 logging.info(f'The difference is {int(case1[1])} minutes, and {int(case1[2])} seconds.')140 elif int(case1[1]) == 0: # 1 0 1141 logging.info(f'The difference is {int(case1[0])} hours, and {int(case1[2])} seconds.')142 elif int(case1[2]) == 0: # 1 1 0143 logging.info(f'The difference is {int(case1[0])} hours, and {int(case1[1])} minutes.')144 else: # 1 1 1145 logging.info(f'The difference is {int(case1[0])} hours, {int(case1[1])} minutes, and {int(case1[2])} seconds.')146 # Case 1b: No microseconds147 elif case1[2].find('.') != -1:148 caseMicro = case1[2].split('.')149 if int(caseMicro[1]) == int(caseMicro[0]) == int(case1[1]) == int(case1[0]) == 0: # 0 0 0 0150 logging.info('BASE Date is the same as COMPARISON Date. No Change.')151 elif int(caseMicro[0]) == int(case1[1]) == int(case1[0]) == 0: # 0 0 0 1152 logging.info(f'The difference is {int(caseMicro[1])} microseconds.')153 elif int(case1[1]) == int(case1[0]) == 0: # 0 0 1154 logging.info(f'The difference is {int(caseMicro[0])} seconds, and {int(caseMicro[1])} microseconds.')155 elif int(case1[2]) == int(case1[0]) == 0: # 0 1 0156 logging.info(f'The difference is {int(case1[1])} minutes, and {int(caseMicro[1])} microseconds.')157 elif int(case1[2]) == int(case1[1]) == 0: # 1 0 0158 logging.info(f'The difference is {int(case1[0])} hours, and {int(caseMicro[1])} microseconds.')159 elif int(case1[0]) == 0: # 0 1 1160 logging.info(f'The difference is {int(case1[1])} minutes {int(caseMicro[0])} seconds, and {int(caseMicro[1])} microseconds.')161 elif int(case1[1]) == 0: # 1 0 1162 logging.info(f'The difference is {int(case1[0])} hours {int(caseMicro[0])} seconds, and {int(caseMicro[1])} microseconds.')163 elif int(case1[2]) == 0: # 1 1 0164 logging.info(f'The difference is {int(case1[0])} hours {int(case1[1])} minutes, and {int(caseMicro[1])} microseconds.')165 else: # 1 1 1166 logging.info(167 f'The difference is {int(case1[0])} hours, {int(case1[1])} minutes, {int(caseMicro[0])} seconds, and {int(caseMicro[1])} microseconds.')168 elif len(dateDifference.split(':')) == 4:169 '''170 else:171 raise ValueError('Wrong input for BASE DATE or COMPARISON DATE. (Please follow the format of the example above), please try again...')172 return dateDifference173def main():174 logging.basicConfig(format='%(message)s', level=logging.INFO)175 logging.debug('initializing...')176 try:177 dateDifferential()178 except ValueError as wrongInput:179 logging.info(f'\nError: {wrongInput}')180 logging.error(ValueError)181 except Exception as errorGeneral:182 logging.info(f'\nException: {errorGeneral}')183 logging.exception(Exception)184#########################185if __name__ == '__main__':...

Full Screen

Full Screen

normalize_cases

Source:normalize_cases Github

copy

Full Screen

1#!/usr/bin/env python2"""3Remove uninteresting diffs between cases by changing the4first to be more like the second.5This is for debugging purposes and meant to assist the user6when they want to run case_diff.7"""8from standard_script_setup import *9from CIME.utils import expect, run_cmd_no_fail10import argparse, sys, os, glob11###############################################################################12def parse_command_line(args, description):13###############################################################################14 parser = argparse.ArgumentParser(15 usage="""\n{0} case1 case216OR17{0} --help18\033[1mEXAMPLES:\033[0m19 > {0} case1 case220""".format(os.path.basename(args[0])),21description=description,22formatter_class=argparse.ArgumentDefaultsHelpFormatter23)24 CIME.utils.setup_standard_logging_options(parser)25 parser.add_argument("case1", help="First case. This one will be changed")26 parser.add_argument("case2", help="Second case. This one will not be changed")27 args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)28 return args.case1, args.case229###############################################################################30def normalize_cases(case1, case2):31###############################################################################32 # gunzip all logs33 for case_dir in [case1, case2]:34 for log_dir in ["bld", "run"]:35 gzips = glob.glob(os.path.join(case_dir, log_dir, "*.gz"))36 if (gzips):37 run_cmd_no_fail("gunzip -f {}".format(" ".join(gzips)))38 # Change case1 to be as if it had same test-id as case239 test_id1 = run_cmd_no_fail("./xmlquery --value TEST_TESTID", from_dir=case1)40 test_id2 = run_cmd_no_fail("./xmlquery --value TEST_TESTID", from_dir=case2)41 run_cmd_no_fail("for item in $(find -type f); do sed -i 's/{}/{}/g' $item; done".format(test_id1, test_id2),42 from_dir=case1)43 # Change case1 to look as if it is was built/run at exact same time as case244 for log_dir in ["bld", "run"]:45 case1_lids = set()46 for logfile in glob.glob("{}/{}/*.bldlog.*".format(case1, log_dir)):47 case1_lids.add(logfile.split(".")[-1])48 case2_lids = set()49 for logfile in glob.glob("{}/{}/*.bldlog.*".format(case2, log_dir)):50 case2_lids.add(logfile.split(".")[-1])51 case1_lids = list(sorted(case1_lids))52 case2_lids = list(sorted(case2_lids))53 for case1_lid, case2_lid in zip(case1_lids, case2_lids):54 run_cmd_no_fail("for item in $(find -type f); do sed -i 's/{}/{}/g' $item; done".format(case1_lid, case2_lid),55 from_dir=case1)56 for case1_lid, case2_lid in zip(case1_lids, case2_lids):57 files_needing_rename = run_cmd_no_fail('find -depth -name "*.{}"'.format(case1_lid), from_dir=case1).splitlines()58 for file_needing_rename in files_needing_rename:59 expect(file_needing_rename.endswith(case1_lid), "broken")60 new_name = file_needing_rename.rstrip(case1_lid) + case2_lid61 os.rename(os.path.join(case1, file_needing_rename), os.path.join(case1, new_name))62 # Normalize CIMEROOT63 case1_root = run_cmd_no_fail("./xmlquery --value CIMEROOT", from_dir=case1)64 case2_root = run_cmd_no_fail("./xmlquery --value CIMEROOT", from_dir=case2)65 if (case1_root != case2_root):66 run_cmd_no_fail("for item in $(find -type f); do sed -i 's:{}:{}:g' $item; done".format(case1_root, case2_root),67 from_dir=case1)68###############################################################################69def _main_func(description):70###############################################################################71 case1, case2 = parse_command_line(sys.argv, description)72 normalize_cases(case1, case2)73###############################################################################74if (__name__ == "__main__"):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful