How to use print_config_dict method in localstack

Best Python code snippet using localstack_python

sweeper.py

Source:sweeper.py Github

copy

Full Screen

...74 cfg[key] = value75 idx = idx // num_combinations_of_list76 return cfg77 78 def print_config_dict(self, config_dict):79 cfg_json = json.dumps(config_dict, indent=2)80 print(cfg_json, end='\n')81def unfinished_index(exp, file_name='log.txt', runs=1, max_line_length=10000):82 '''83 Find unfinished config indexes based on the existence of time info in the log file84 '''85 # Read config files86 config_file = f'./configs/{exp}.json'87 sweeper = Sweeper(config_file)88 # Read a list of logs89 print(f'[{exp}]: ', end=' ')90 for i in range(runs * sweeper.config_dicts['num_combinations']):91 log_file = f'./logs/{exp}/{i+1}/{file_name}'92 try:93 with open(log_file, 'r') as f:94 # Get last line95 try:96 f.seek(-max_line_length, os.SEEK_END)97 except IOError:98 # either file is too small, or too many lines requested99 f.seek(0)100 last_line = f.readlines()[-1]101 # Get time info in last line102 try:103 t = float(last_line.split(' ')[-2])104 except:105 print(i+1, end=', ')106 continue107 except:108 print(i+1, end=', ')109 continue110 print()111def time_info(exp, file_name='log.txt', runs=1, nbins=10, max_line_length=10000):112 time_list = []113 # Read config file114 config_file = f'./configs/{exp}.json'115 sweeper = Sweeper(config_file)116 # Read a list of logs117 for i in range(runs * sweeper.config_dicts['num_combinations']):118 log_file = f'./logs/{exp}/{i+1}/{file_name}'119 try:120 with open(log_file, 'r') as f:121 # Get last line122 try:123 f.seek(-max_line_length, os.SEEK_END)124 except IOError:125 # either file is too small, or too many lines requested126 f.seek(0)127 last_line = f.readlines()[-1]128 # Get time info in last line129 try:130 t = float(last_line.split(' ')[-2])131 time_list.append(t)132 except:133 print('No time info in file: '+log_file)134 continue135 except:136 continue137 138 if len(time_list) > 0:139 time_list = np.array(time_list)140 print(f'{exp} max time: {np.max(time_list):.2f} minutes')141 print(f'{exp} mean time: {np.mean(time_list):.2f} minutes')142 print(f'{exp} min time: {np.min(time_list):.2f} minutes')143 144 # Plot histogram of time distribution145 from utils.helper import make_dir146 make_dir(f'./logs/{exp}/0/')147 num, bins, patches = plt.hist(time_list, nbins)148 plt.xlabel('Time (min)')149 plt.ylabel('Counts in the bin')150 plt.savefig(f'./logs/{exp}/0/time_info.png')151 # plt.show()152 plt.clf() # clear figure153 plt.cla() # clear axis154 plt.close() # close window155 else:156 print(f'{exp}: no time info!')157 158def memory_info(exp, file_name='log.txt', runs=1, nbins=10, max_line_length=10000):159 mem_list = []160 # Read config file161 config_file = f'./configs/{exp}.json'162 sweeper = Sweeper(config_file)163 # Read a list of logs164 for i in range(runs * sweeper.config_dicts['num_combinations']):165 log_file = f'./logs/{exp}/{i+1}/{file_name}'166 try:167 with open(log_file, 'r') as f:168 # Get last line169 try:170 f.seek(-max_line_length, os.SEEK_END)171 except IOError:172 # either file is too small, or too many lines requested173 f.seek(0)174 last_second_line = f.readlines()[-2]175 # Get memory info in last line176 try:177 m = float(last_second_line.split(' ')[-2])178 mem_list.append(m)179 except:180 print('No memory info in file: '+log_file)181 continue182 except:183 continue184 185 if len(mem_list) > 0:186 mem_list = np.array(mem_list)187 print(f'{exp} max memory: {np.max(mem_list):.2f} MB')188 print(f'{exp} mean memory: {np.mean(mem_list):.2f} MB')189 print(f'{exp} min memory: {np.min(mem_list):.2f} MB')190 191 # Plot histogram of time distribution192 from utils.helper import make_dir193 make_dir(f'./logs/{exp}/0/')194 num, bins, patches = plt.hist(mem_list, nbins)195 plt.xlabel('Memory (MB)')196 plt.ylabel('Counts in the bin')197 plt.savefig(f'./logs/{exp}/0/memory_info.png')198 # plt.show()199 plt.clf() # clear figure200 plt.cla() # clear axis201 plt.close() # close window202 else:203 print(f'{exp}: no memory info!')204if __name__ == "__main__":205 for agent_config in os.listdir('./configs/'):206 if not '.json' in agent_config:207 continue208 config_file = os.path.join('./configs/', agent_config)209 sweeper = Sweeper(config_file)210 # sweeper.print_config_dict(sweeper.config_dicts)211 # sweeper.print_config_dict(sweeper.generate_config_for_idx(213))...

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 localstack 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