1313from packaging .version import parse
1414from pathlib import Path
1515
16- from util import add_certificate
17-
1816MAIN_REPO_SWAGGER = 'https://github.com/Azure/azure-rest-api-specs/tree/main'
1917PR_URL = 'https://github.com/Azure/azure-rest-api-specs/pull/'
2018FAILED_RESULT = []
@@ -54,10 +52,6 @@ def print_call(cmd):
5452 sp .call (cmd , shell = True )
5553
5654
57- def start_test_proxy ():
58- print_check ('pwsh {}/eng/common/testproxy/docker-start-proxy.ps1 \" start\" ' .format (os .getenv ('SDK_REPO' )))
59-
60-
6155def version_sort (versions : List [str ]) -> List [str ]:
6256 versions_package = [parse (version ) for version in versions ]
6357 versions_package .sort ()
@@ -231,67 +225,8 @@ def bot_analysis(self):
231225 self .bot_warning += 'Need to add track2 config.'
232226
233227
234- def sdk_code_path (service_name , sdk_name ) -> str :
235- return str (Path (os .getenv ('SDK_REPO' ) + f'/sdk/{ service_name } /{ sdk_name } ' ))
236-
237-
238- @return_origin_path
239- def install_package_locally (service_name , sdk_name ):
240- os .chdir (sdk_code_path (service_name , sdk_name ))
241- print_check ('pip install -e .' )
242- print_exec ('pip install -r dev_requirements.txt' )
243-
244-
245- @return_origin_path
246- def run_test_proc (sdk_name , service_name , sdk_folder ):
247- # run test
248- if os .getenv ('SKIP_COVERAGE' ) in ('true' , 'yes' ):
249- return SKIP_TEXT
250-
251- coverage_path = '' .join ([os .getenv ('SDK_REPO' ), '/sdk/' , sdk_folder ])
252- service_path = coverage_path .split ('/azure/mgmt' )[0 ]
253- os .chdir (sdk_code_path (service_name , sdk_name ))
254- try :
255- print_check (f'pytest --collect-only' )
256- except :
257- print ('live test run done, do not find any test !!!' )
258- return '-, -, -, -\n '
259- if os .path .exists (coverage_path + '/operations' ) and os .path .exists (coverage_path + '/models' ):
260- operations_path = coverage_path + '/operations'
261- models_path = coverage_path + '/models'
262- try :
263- start_time = int (time .time ())
264- print_check (f'pytest tests -s --cov={ operations_path } --cov={ models_path } >result.txt' , path = service_path )
265- cost_time = int (time .time ()) - start_time
266- my_print (f'{ service_name } play_back cost { cost_time } seconds({ cost_time // 60 } minutes)' )
267- except Exception as e :
268- print (f'{ service_name } test ERROR' )
269- return '-, 0, 0, 0\n '
270- else :
271- try :
272- print_check (f'pytest tests -s >result.txt' , path = service_path )
273- except Exception as e :
274- return '-, 0, 0, 0\n '
275- if os .path .exists (service_path + '/result.txt' ):
276- return get_test_result (service_path + '/result.txt' )
277-
278-
279- def run_test (sdk_name , service_name , sdk_folder ):
280- install_package_locally (service_name , sdk_name )
281- test_result = run_test_proc (sdk_name , service_name , sdk_folder )
282- return test_result
283-
284-
285- def clean_test_env ():
286- for item in ("SSL_CERT_DIR" , "REQUESTS_CA_BUNDLE" ):
287- if os .getenv (item ):
288- os .environ .pop (item )
289-
290-
291228def sdk_info_from_pypi (sdk_info : List [Dict [str , str ]], cli_dependency ):
292229 all_sdk_status = []
293- add_certificate ()
294- start_test_proxy ()
295230 for package in sdk_info :
296231 sdk_name = package ['package_name' ]
297232 if sdk_name in cli_dependency .keys ():
@@ -306,41 +241,13 @@ def sdk_info_from_pypi(sdk_info: List[Dict[str, str]], cli_dependency):
306241 readme_link = readme_link , rm_link = rm_link , cli_version = cli_version , multi_api = multi_api )
307242 sdk_folder = package ['sdk_folder' ]
308243 text_to_write = pypi_ins .write_to_list (sdk_folder )
309- service_name = package ['service_name' ]
310244 if pypi_ins .pypi_link != 'NA' :
311- test_result = SKIP_TEXT
312- try :
313- test_result = run_test (sdk_name , service_name , sdk_folder )
314- except :
315- print (f'[Error] fail to play back test recordings: { sdk_name } ' )
316- text_to_write += test_result
317- all_sdk_status .append (text_to_write )
318-
319- clean_test_env ()
245+ all_sdk_status .append (text_to_write + SKIP_TEXT )
246+
320247 my_print (f'total pypi package kinds: { len (all_sdk_status )} ' )
321248 return all_sdk_status
322249
323250
324- def get_test_result (txt_path ):
325- with open (txt_path , 'r+' ) as f :
326- coverage = ' - '
327- for line in f .readlines ():
328- if 'TOTAL' in line :
329- coverage = line .split ()[3 ]
330- if '=====' in line and ('passed' in line or 'failed' in line or 'skipped' in line ):
331- # print(line)
332- passed , failed , skipped = 0 , 0 , 0
333- if 'passed' in line :
334- passed = re .findall ('(\d{1,2}) passed' , line )[0 ]
335- if 'failed' in line :
336- failed = re .findall ('(\d{1,2}) failed' , line )[0 ]
337- if 'skipped' in line :
338- skipped = re .findall ('(\d{1,2}) skipped' , line )[0 ]
339- # print(f'{passed} {failed} {skipped}')
340-
341- return f'{ coverage } , { passed } , { failed } , { skipped } \n '
342-
343-
344251def write_to_csv (sdk_status_list , csv_name ):
345252 with open (csv_name , 'w' ) as file_out :
346253 file_out .write ('foler/package name,'
0 commit comments