Best Python code snippet using tempest_python
check_logs.py
Source:check_logs.py
...63 if not whitelisted:64 had_errors = True65 print(line)66 return had_errors67def collect_url_logs(url):68 page = urllib2.urlopen(url)69 content = page.read()70 logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content)71 return logs72def main(opts):73 if opts.directory and opts.url or not (opts.directory or opts.url):74 print("Must provide exactly one of -d or -u")75 exit(1)76 print("Checking logs...")77 WHITELIST_FILE = os.path.join(78 os.path.abspath(os.path.dirname(os.path.dirname(__file__))),79 "etc", "whitelist.yaml")80 file_matcher = re.compile(r".*screen-([\w-]+)\.log")81 files = []82 if opts.directory:83 d = opts.directory84 for f in os.listdir(d):85 files.append(os.path.join(d, f))86 files_to_process = []87 for f in files:88 m = file_matcher.match(f)89 if m:90 files_to_process.append((m.group(1), f))91 url_matcher = re.compile(r".*screen-([\w-]+)\.txt\.gz")92 urls = []93 if opts.url:94 for logfile in collect_url_logs(opts.url):95 urls.append("%s/%s" % (opts.url, logfile))96 urls_to_process = []97 for u in urls:98 m = url_matcher.match(u)99 if m:100 urls_to_process.append((m.group(1), u))101 whitelists = {}102 with open(WHITELIST_FILE) as stream:103 loaded = yaml.safe_load(stream)104 if loaded:105 for (name, l) in loaded.iteritems():106 for w in l:107 assert 'module' in w, 'no module in %s' % name108 assert 'message' in w, 'no message in %s' % name...
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!!