File: public_bindings.py

package info (click to toggle)
pytorch 2.6.0%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 161,672 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (36 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations

from typing import Any
from warnings import warn

from tools.testing.target_determination.heuristics.interface import (
    HeuristicInterface,
    TestPrioritizations,
)
from tools.testing.target_determination.heuristics.utils import query_changed_files
from tools.testing.test_run import TestRun


class PublicBindings(HeuristicInterface):
    # Literally just a heuristic for test_public_bindings.  Pretty much anything
    # that changes the public API can affect this testp
    test_public_bindings = "test_public_bindings"
    additional_files = ["test/allowlist_for_publicAPI.json"]

    def __init__(self, **kwargs: dict[str, Any]) -> None:
        super().__init__(**kwargs)

    def get_prediction_confidence(self, tests: list[str]) -> TestPrioritizations:
        test_ratings = {}
        try:
            changed_files = query_changed_files()
        except Exception as e:
            warn(f"Can't query changed test files due to {e}")
            changed_files = []

        if any(
            file.startswith("torch/") or file in self.additional_files
            for file in changed_files
        ):
            test_ratings[TestRun(self.test_public_bindings)] = 1.0
        return TestPrioritizations(tests, test_ratings)