def _runPylintOnAllSources(args, testDirs): print("\nRunning pylint on python tests") if not "PYLINT_ENABLED" in os.environ or os.environ["PYLINT_ENABLED"] != '1': print("Pylint is disabled.\n") return 0 from testutils import getApiDir, getTestSuiteName pylintOptions = ["--persistent=n", "--score=n"] if args.pylint_rcfile: pylintOptions.append("--rcfile=%s" % (args.pylint_rcfile)) testDisableOption = ("missing-docstring, invalid-name, duplicate-code, too-many-public-methods, " "too-few-public-methods, c-extension-no-member") genDisableOption = ("missing-docstring, invalid-name, no-self-use, duplicate-code, line-too-long, " "singleton-comparison, too-many-instance-attributes, too-many-arguments, " "too-many-public-methods, too-few-public-methods, too-many-locals, too-many-branches, " "too-many-statements, unneeded-not, superfluous-parens, len-as-condition, " "import-self, misplaced-comparison-constant, invalid-unary-operand-type, " "c-extension-no-member") genPylintOptions = list(pylintOptions) genPylintOptions.append("--ignore=api.py") apiDisableOption = ("missing-docstring, unused-import, line-too-long") apiPylintOptions = list(pylintOptions) apiPylintOptions.append("--ignore-patterns=^.*\\.py(?<!^api\\.py)$") for testDir in testDirs: testSources = [os.path.join(testDir, child) for child in os.listdir(testDir) if child.endswith(".py")] apiDir = getApiDir(testDir) if os.path.isdir(apiDir): apiSources = [os.path.join(apiDir, child) for child in os.listdir(apiDir) if child.endswith(".py") or os.path.isdir(os.path.join(apiDir, child))] testSuiteName = getTestSuiteName(testDir) print(testSuiteName) print(" test files...") pylintResult = _runPylint(testSources, pylintOptions, testDisableOption) if pylintResult != 0: return pylintResult sys.path.append(apiDir) print(" generated files...") # except api.py files pylintResult = _runPylint(apiSources, genPylintOptions, genDisableOption) if pylintResult != 0: return pylintResult print(" generated api.py files...") pylintResult = _runPylint(apiSources, apiPylintOptions, apiDisableOption) if pylintResult != 0: return pylintResult sys.path.remove(apiDir) print("Pylint done.\n") return 0
def _runMypyOnAllSources(args, testDirs, runtimePath, testutilsPath): print("\nRunning mypy on python tests") if not "MYPY_ENABLED" in os.environ or os.environ["MYPY_ENABLED"] != '1': print("Mypy is disabled.\n") return 0 from testutils import TEST_ARGS, getApiDir, getTestSuiteName from mypy import api os.environ["MYPYPATH"] = runtimePath + os.pathsep + testutilsPath mypyCacheDir = os.path.join(TEST_ARGS["build_dir"], ".mypy_cache") mypyArgs = [] mypyArgs.append(f"--cache-dir={mypyCacheDir}") if args.mypy_config_file: mypyArgs.append(f"--config-file={args.mypy_config_file}") mypyArgs.append("--no-strict-optional" ) # Item "None" of "Optional[Blob]" has no attribute "..." for testDir in testDirs: apiDir = getApiDir(testDir) testSuiteName = getTestSuiteName(testDir) print(testSuiteName + " ... ", end='', flush=True) mypyArgsForTest = list(mypyArgs) _loadMypyExtraArgsFile(testDir, mypyArgsForTest) if os.path.exists(apiDir): mypyArgsForTest.append(apiDir) mypyArgsForTest.append(testDir) mypyResult = api.run(mypyArgsForTest) if mypyResult[2] != 0: print("FAILED!") if mypyResult[0]: print("Type checking report:") print(mypyResult[0]) if mypyResult[1]: print("Error report:") print(mypyResult[1]) return mypyResult[2] else: print(mypyResult[0], end='') print("Mypy done.\n") return 0