How to use logBlock method in fMBT

Best Python code snippet using fMBT_python

test_coverage.py

Source:test_coverage.py Github

copy

Full Screen

1from __future__ import print_function2import sys3import re4import os5def countArgs(argsSpec):6 result = 07 parentCount = 08 for curCh in argsSpec:9 if curCh == '(':10 parentCount += 111 elif curCh == ')':12 parentCount -= 113 elif curCh == ',' and parentCount == 0:14 result += 115 return result16def validateLogParams(fileName, fileData):17 logBlock = None18 for curLine in fileData.split('\n'):19 if re.match('^\s*(?:ngx|vod)_log_(?:debug|error)', curLine):20 logBlock = ''21 if logBlock == None:22 continue23 logBlock += curLine.strip()24 if logBlock.count('(') > logBlock.count(')'):25 continue26 logMessage = logBlock[logBlock.find('"'):logBlock.rfind('"')]27 args = logBlock[logBlock.rfind('"'):]28 if countArgs(args) != logMessage.count('%') + logMessage.count('%*'):29 print(logBlock)30 logBlock = None31if len(sys.argv) < 2:32 print('Usage:\n\tpython %s <nginx-vod code root> [<error log file>]' % os.path.basename(__file__))33 sys.exit(1)34nginxVodRoot = sys.argv[1]35errorLog = None36if len(sys.argv) > 2:37 errorLog = sys.argv[2]38logMessages = []39logPrefixes = set([])40for root, dirs, files in os.walk(nginxVodRoot):41 for name in files:42 if os.path.splitext(name)[1] != '.c':43 continue44 fileData = open(os.path.join(root, name), 'rb').read()45 validateLogParams(name, fileData)46 for curLog in re.findall('(?:ngx|vod)_log_(?:debug|error)[^\(]*\([^\)]+\)', fileData):47 logMessage = curLog.split(',')[3].strip()48 if logMessage.endswith('")'):49 logMessage = logMessage[:-1]50 if logMessage.endswith('"'):51 logMessage = logMessage[:-1]52 if logMessage.startswith('"'):53 logMessage = logMessage[1:]54 if logMessage == 'const char *fmt':55 continue56 # add the log message57 logPrefix = logMessage.split('%')[0]58 logMessages.append((logPrefix, logMessage))59 logPrefixes.add(logPrefix)60 # validate the function name in the log line matches the actual function61 linePos = fileData.find(curLog)62 functionNames = re.findall('^[a-z0-9_]+\(', fileData[:linePos], re.MULTILINE)63 realFunction = functionNames[-1]64 if realFunction.endswith('('):65 realFunction = realFunction[:-1]66 logFunction = logMessage.split(':')[0]67 if logFunction.startswith('"'):68 logFunction = logFunction[1:]69 if realFunction != logFunction:70 print('log function mismatch %s' % logMessage)71 72if errorLog == None:73 sys.exit(0)74 75errorLogData = open(errorLog, 'rb').read()76foundPrefixes = {}77for logPrefix in logPrefixes:78 logPos = errorLogData.find(logPrefix)79 if logPos > 0:80 foundPrefixes[logPrefix] = errorLogData[(errorLogData.rfind('\n', 0, logPos) + 1):errorLogData.find('\n', logPos)]81print('not covered:')82for logPrefix, logMessage in logMessages:83 if not foundPrefixes.has_key(logPrefix):84 print('\t' + logMessage)85print('covered:')86for curLine in foundPrefixes.values():...

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