示例#1
0
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
示例#2
0
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
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
def doCssCheck(fileContent, level = 2):
    checker = doCheck(fileContent)
    return checker.errors()
示例#7
0
def doCssTextCheck(text, fileName = ''):
    checker = doCheck(text, fileName)
    return checker.errors()
示例#8
0
def doCssTextCheck(text, fileName=''):
    checker = doCheck(text, fileName)
    return checker.errors()
示例#9
0
def doCssCheck(fileContent, level=2):
    checker = doCheck(fileContent)
    return checker.errors()