• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 20332790708

18 Dec 2025 09:48AM UTC coverage: 64.992% (-15.3%) from 80.295%
20332790708

Pull #22949

github

web-flow
Merge f730a56cd into 407284c67
Pull Request #22949: Add experimental uv resolver for Python lockfiles

54 of 97 new or added lines in 5 files covered. (55.67%)

8270 existing lines in 295 files now uncovered.

48990 of 75379 relevant lines covered (64.99%)

1.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.0
/src/python/pants/backend/tools/trivy/testutil.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
import json
1✔
4

5
from pants.core.goals.lint import LintResult
1✔
6

7
trivy_config = """
1✔
8
format: json
9
"""
10

11

12
def assert_trivy_output(
1✔
13
    result: LintResult,
14
    expected_exit_code: int,
15
    target: str,
16
    scanner_type: str,
17
    expected_error_count: int,
18
):
19
    """Assert that the output of Trivy matches our expectations.
20

21
    For checking the error count, we assert that there are _at least_ as many errors as specified,
22
    since new ones are found as time goes on and we don't want the tests to suddenly break
23
    """
24
    if result.exit_code != expected_exit_code:
1✔
25
        raise AssertionError(
×
26
            f"Trivy process had incorrect exit code, expected={expected_exit_code}, actual={result.exit_code}, stdout={result.stdout}, stderr={result.stderr}"
27
        )
28

29
    try:
1✔
30
        report = json.loads(result.stdout)
1✔
31
    except json.decoder.JSONDecodeError as e:
×
32
        raise AssertionError(
×
33
            f"Trivy output could not be parsed as JSON, stdout={result.stdout=}, stderr={result.stderr}"
34
        ) from e
35

36
    findings_by_target = {res["Target"]: res for res in report["Results"]}
1✔
37
    assert target in findings_by_target, (
1✔
38
        f"Did not find expected file in results, target={target} files={list(findings_by_target.keys())}"
39
    )
40

41
    if scanner_type == "config":
1✔
42
        found_count = findings_by_target[target]["MisconfSummary"]["Failures"]
1✔
43
        assert found_count >= expected_error_count, (
1✔
44
            f"Did not find expected failure count actual={found_count} expected={expected_error_count}"
45
        )
UNCOV
46
    elif scanner_type == "image":
×
UNCOV
47
        found_count = len(findings_by_target[target]["Vulnerabilities"])
×
UNCOV
48
        assert found_count >= expected_error_count, (
×
49
            f"Did not find expected vulnerabilities found={found_count} expected={expected_error_count}"
50
        )
51

52

53
def assert_trivy_success(result: LintResult):
1✔
UNCOV
54
    if result.exit_code != 0:
×
55
        raise AssertionError(f"Trivy process was not successful, stdout={result.stdout}")
×
56

UNCOV
57
    try:
×
UNCOV
58
        json.loads(result.stdout)
×
59
    except json.decoder.JSONDecodeError as e:
×
60
        raise AssertionError(
×
61
            f"Trivy output could not be parsed as JSON, stdout={result.stdout}, stderr={result.stderr}"
62
        ) from e
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc