Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/tools/tools/repohooks/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 3 kB image not shown  

Quelle  run_tests   Sprache: unbekannt

 
Spracherkennung für: vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

#!/usr/bin/env python3
# Copyright 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Wrapper to run analyzers & tests with the right settings."""

import functools
import os
from pathlib import Path
import shlex
import subprocess
import sys
from typing import List


ROOT_DIR = Path(__file__).resolve().parent


def log_cmd(cmd: str, argv: list[str]) -> None:
    """Log a debug message to make history easier to track."""
    print("+", cmd, shlex.join(str(x) for x in argv), file=sys.stderr)


@functools.lru_cache()
def is_ci() -> bool:
    """Whether we're running in our CI system."""
    return os.getenv("LUCI_CQ") == "yes"


def run_pytest(argv: List[str]) -> int:
    """Returns the exit code from pytest."""
    if is_ci():
        argv = ["-m", "not skip_cq"] + argv

    log_cmd("pytest", argv)
    return subprocess.run(
        [sys.executable, "-m", "pytest"] + argv,
        check=False,
        cwd=ROOT_DIR,
    ).returncode


def run_black() -> int:
    """Returns the exit code from black."""
    argv = ["--version"]
    log_cmd("black", argv)
    subprocess.run(
        [sys.executable, "-m", "black"] + argv,
        check=True,
        cwd=ROOT_DIR,
    )

    # Black by default only matches .py files.  We have to list standalone
    # scripts manually.
    extra_programs = [
        "run_tests",
        "tools/cpplint.py-update",
    ]
    argv = ["--diff", "--check", ROOT_DIR] + extra_programs
    log_cmd("black", argv)
    return subprocess.run(
        [sys.executable, "-m", "black"] + argv,
        check=False,
        cwd=ROOT_DIR,
    ).returncode


def run_pylint() -> int:
    """Returns the exit code from pylint."""
    argv = ["--version"]
    log_cmd("pylint", argv)
    subprocess.run(
        [sys.executable, "-m", "pylint"] + argv,
        check=True,
        cwd=ROOT_DIR,
    )

    argv = [
        "--rc-file=tools/pylintrc",
        "pre-upload.py",
        "run_tests",
        "rh/*.py",
        "tools/*.py",
        "tools/cpplint.py-update",
    ]
    log_cmd("pylint", argv)
    return subprocess.run(
        [sys.executable, "-m", "pylint"] + argv,
        check=False,
        cwd=ROOT_DIR,
    ).returncode


def main(argv):
    """The main entry."""
    checks = (
        functools.partial(run_pytest, argv),
        run_black,
        run_pylint,
    )
    # Run all the tests all the time to get full feedback.  Don't exit on the
    # first error as that makes it more difficult to iterate in the CQ.
    return 1 if sum(c() for c in checks) else 0


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))

[Dauer der Verarbeitung: 0.28 Sekunden, vorverarbeitet 2026-06-27]