def checkCssFileByOpm(filePath): fileContent = open(filePath).read() checker = doCheck(fileContent, filePath) if checker.hasError(): reporter = ReporterUtil.getReporter('text', checker) reporter.doReport() print reporter.export() return False return True
def runUnitTests(): global fileCounter filePath = realpath(__file__, '../unit') start = datetime.datetime.now() for filename in os.listdir(filePath): if filename == 'asserts.py' or filename == 'helper.py' or filename.startswith('_'): continue if filename.endswith('.py'): doCheckWithPythonFile(filename) continue if not filename.endswith('.css'): continue testFileName = realpath(filePath, filename) fileContent = open(testFileName).read() checker = doCheck(fileContent, filename) styleSheet = checker.getStyleSheet() testErrorSet = styleSheet.getRuleSetBySelector('@unit-test-expecteds') if testErrorSet is None: print 'no @unit-test-expecteds in %s' % testFileName continue expectedErrors = testErrorSet.getRules() if expectedErrors is None: print 'no error instance in @unit-test-expecteds, %s' % testFileName continue fileCounter = fileCounter + 1 logs = {} errors = {} warnings = {} fillDicts(logs, warnings, errors, expectedErrors) realLogs, realWarnings, realErrors = checker.errors() checkUnitTestResult(logs, realLogs, '2', filename) checkUnitTestResult(warnings, realWarnings, '1', filename) checkUnitTestResult(errors, realErrors, '0', filename) end = datetime.datetime.now() delta = (end - start).microseconds / 1000 print '[UnitTest] error: %s, pass: %s, in %s files, costs %s ms' % (errorCounter, okCounter, fileCounter, delta)
def runTestsInDir(filePath, module): global fileCounter for filename in os.listdir(filePath): if (os.path.isdir(os.path.join(filePath, filename))): runTestsInDir(os.path.join(filePath, filename), module + filename + '.') continue if filename == 'asserts.py' or filename == 'helper.py' or filename.startswith( '_'): continue if filename.endswith('.py'): doCheckWithPythonFile(filename, module) continue if not filename.endswith('.css'): continue testFileName = realpath(filePath, filename) fileContent = open(testFileName).read() checker = doCheck(fileContent, filename) styleSheet = checker.getStyleSheet() testErrorSet = styleSheet.getRuleSetBySelector('@unit-test-expecteds') if testErrorSet is None: console.error('no @unit-test-expecteds in %s' % testFileName) continue expectedErrors = testErrorSet.getRules() if expectedErrors is None: console.error('no error instance in @unit-test-expecteds, %s' % testFileName) continue fileCounter = fileCounter + 1 logs = {} errors = {} warnings = {} fillDicts(logs, warnings, errors, expectedErrors) realLogs, realWarnings, realErrors = checker.errors() checkUnitTestResult(logs, realLogs, '2', filename) checkUnitTestResult(warnings, realWarnings, '1', filename) checkUnitTestResult(errors, realErrors, '0', filename)
def runTestsInDir(filePath, module): global fileCounter for filename in os.listdir(filePath): if (os.path.isdir(os.path.join(filePath, filename))): runTestsInDir(os.path.join(filePath, filename), module + filename + '.') continue if filename == 'asserts.py' or filename == 'helper.py' or filename.startswith('_'): continue if filename.endswith('.py'): doCheckWithPythonFile(filename, module) continue if not filename.endswith('.css'): continue testFileName = realpath(filePath, filename) fileContent = open(testFileName).read() checker = doCheck(fileContent, filename) styleSheet = checker.getStyleSheet() testErrorSet = styleSheet.getRuleSetBySelector('@unit-test-expecteds') if testErrorSet is None: console.error('no @unit-test-expecteds in %s' % testFileName) continue expectedErrors = testErrorSet.getRules() if expectedErrors is None: console.error('no error instance in @unit-test-expecteds, %s' % testFileName) continue fileCounter = fileCounter + 1 logs = {} errors = {} warnings = {} fillDicts(logs, warnings, errors, expectedErrors) realLogs, realWarnings, realErrors = checker.errors() checkUnitTestResult(logs, realLogs, '2', filename) checkUnitTestResult(warnings, realWarnings, '1', filename) checkUnitTestResult(errors, realErrors, '0', filename)
def doCssCheck(fileContent, level = 2): checker = doCheck(fileContent) return checker.errors()
def doCssTextCheck(text, fileName = ''): checker = doCheck(text, fileName) return checker.errors()
def doCssTextCheck(text, fileName=''): checker = doCheck(text, fileName) return checker.errors()
def doCssCheck(fileContent, level=2): checker = doCheck(fileContent) return checker.errors()