Best Python code snippet using avocado_python
trans_content.py
Source:trans_content.py
1# 该ç¨åºçç®çæ¯å°ä¹åå¨typechoä¸çå客å
容è¿ç§»å°hexoä¸æ¥2# è¾å
¥ï¼3# 1. typechoä¸å¯¼åºçdatæ ¼å¼å¤ä»½æ件4# 2. 个人å¤ä»½çææå客çmarkdownåæ5# è¾åºï¼6# 1. å¨_postæ件夹ä¸å建ææçå客ï¼å¹¶å°æ¶é´å客ä¸çæ¶é´é
置为typechoä¸åå¸çæ¶é´7# æè·¯ï¼8# æ举ææmarkdownæ件ï¼æ¾å°datæ件ä¸å
¶å¯¹åºçä½ç½®ï¼ç¶åè·å对åºçæ¶é´æ³ï¼åå
¥å°æ°åå¸çå客å
容ä¸9import re10import os11import time12from absl import app, flags13flags.DEFINE_bool('force', False, 'force to rewrite output')14flags.DEFINE_bool('test', False, 'output all match results to a text file for test')15FLAGS = flags.FLAGS16def search(dat_text, title):17 content = ''18 typecho_title = ''19 try:20 title = title.replace('[', '\[')21 title = title.replace(']', '\]')22 content = re.search(title + '\ *(\[([\u4e00-\u9fa5_a-zA-Z]|\+)*\]){0,1}\ *[0-9]*<!--markdown-->', dat_text).group()23 except:24 print("Can't find content for title: {}".format(title))25 if content == '':26 try:27 content = re.search('([\u4e00-\u9fa5_a-zA-Z0-9]|\s|'+"""ï¼"""+ ')*[0-9]*<!--markdown--># ' + title, dat_text).group().rstrip('[0-9]')28 except:29 print("Can't find content for title: {}".format(title))30 31 if typecho_title == '':32 try:33 typecho_title = re.search('([\u4e00-\u9fa5_a-zA-Z0-9]|\s|'+"""ï¼"""+ ')*', content).group()34 except:35 typecho_title = "None"36 37 timestamp = int()38 try:39 timestamp = re.search('[0-9]{10}<!--markdown-->', content).group()[:10]40 except:41 timestamp = 042 return title, timestamp43cates = [44 'C#',45 'Code',46 'Diary',47 'Haskell',48 'Others',49 'Server'50]51contests = [52 'Codeforces Contest',53 'kick start'54]55def file_iterator():56 base_path = '../../'57 for cate in cates:58 dir_path = base_path + cate + '/'59 for md_file in os.listdir( dir_path ):60 if md_file.endswith('.md'):61 yield md_file, cate, dir_path + md_file62 if cate=='Code':63 for contest in contests:64 deeper_dir_path = dir_path + contest + '/'65 for md_file in os.listdir( deeper_dir_path ):66 if md_file.endswith('.md'):67 yield md_file, cate, deeper_dir_path + md_file68def file_title(file_path):69 md_file = open(file_path, 'r')70 md_content = md_file.read()71 title = 'Error'72 try:73 title = re.search('^# ([\u4e00-\u9fa5_a-zA-Z0-9]|\ |\[|\]|\ |'+"""ï¼"""+ ')*', md_content).group()[2:]74 except:75 print("[*] Error: Can't find tilte for {}".format(file_path))76 return title.strip(), md_content77def suc(title, timestamp):78 if title and title!='' and title!='Error' and timestamp and timestamp != 0:79 return True80 return False81def main(argv):82 dat = open('20210121_songer.xyz_60097668497b7.dat', 'r')83 dat_text = dat.read()84 test_output = None85 if FLAGS.test:86 test_output = open('test_output_suc.tsv', 'w')87 test_output.write('title\ttypecho_title\ttime\tdir\n')88 89 test_output_fail = open('test_output_fail.tsv', 'w')90 test_output_fail.write('title\ttypecho_title\ttime\tdir\n')91 skip_cnt = suc_cnt = 092 draft_cnt = skip_draft_cnt = 093 for md_file, cate, file_path in file_iterator():94 title, content = file_title(file_path)95 typecho_title, timestamp = search(dat_text, title)96 typecho_title = typecho_title.replace('\[', '[')97 typecho_title = typecho_title.replace('\]', ']')98 if FLAGS.test:99 output_str = "{}\t{}\t{}\t{}\n".format(100 title,101 typecho_title,102 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(timestamp))),103 file_path104 )105 if suc(typecho_title, timestamp):106 test_output.write(output_str)107 else:108 test_output_fail.write(output_str)109 else:110 if suc(typecho_title, timestamp):111 output_path = '../source/_posts/{}/{}.md'.format(cate, typecho_title)112 if os.path.isfile(output_path) and not FLAGS.force:113 skip_cnt += 1114 continue115 output_file = open(output_path, 'w')116 output_str = '---\n' + \117 'title: \"{}\"\n'.format(typecho_title) + \118 'date: {}\n'.format(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(timestamp)))) + \119 'tags: \n' + \120 '---\n\n' + content.replace('https://oi-songer.github.io', '/images/')121 output_file.write(output_str)122 suc_cnt += 1123 else:124 output_path = '../source/_drafts/{}/{}.md'.format(cate, typecho_title)125 if os.path.isfile(output_path) and not FLAGS.force:126 skip_draft_cnt += 1127 continue128 output_file = open(output_path, 'w')129 output_str = '---\n' + \130 'title: \"{}\"\n'.format(typecho_title) + \131 'tags: \n' + \132 '---\n\n' + content133 output_file.write(output_str)134 draft_cnt += 1135 print("finsiehd.")136 print("post: suc[{}], skip[{}]".format(suc_cnt, skip_cnt))137 print("draft: suc[{}], skip[{}]".format(draft_cnt, skip_draft_cnt))138if __name__=="__main__":...
test_basic_mochitest_plain.py
Source:test_basic_mochitest_plain.py
...30 assert log_level == WARNING31 lines = filter_action('test_status', lines)32 assert len(lines) == 133 assert lines[0]['status'] == 'PASS'34def test_output_fail(runtests):35 from runtests import build_obj36 status, lines = runtests('test_fail.html')37 assert status == 138 tbpl_status, log_level = get_mozharness_status(lines, status)39 assert tbpl_status == TBPL_WARNING40 assert log_level == WARNING41 lines = filter_action('test_status', lines)42 # If we are running with a build_obj, the failed status will be43 # logged a second time at the end of the run.44 if build_obj:45 assert len(lines) == 246 else:47 assert len(lines) == 148 assert lines[0]['status'] == 'FAIL'...
test_reftest_output.py
Source:test_reftest_output.py
...15 assert log_level in (INFO, WARNING)16 test_end = filter_action('test_end', lines)17 assert len(test_end) == 318 assert all(t['status'] == 'PASS' for t in test_end)19def test_output_fail(runtests):20 status, lines = runtests('reftest-fail.list')21 assert status == 022 tbpl_status, log_level = get_mozharness_status(lines, status)23 assert tbpl_status == TBPL_WARNING24 assert log_level == WARNING25 test_end = filter_action('test_end', lines)26 assert len(test_end) == 327 assert all(t['status'] == 'FAIL' for t in test_end)28if __name__ == '__main__':...
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!!