Files
cacti/tests/tools/test_changed_python_coverage.py
Thomas Vincent e2a5f32ee9 fix(ci): [develop] harden dependency installs and Docker build boundaries (#8294)
* security(ci): constrain dependency installs and container build boundaries

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(docker): retain shipped runtime libraries in build context

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(tooling): quote gettext paths and honor Docker base selection

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(auth): use certificate expiry truth in rendering assertions

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(tooling): finish Docker layer and regex scan findings

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(ci): preserve documentation badge anchors without alternation

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(ci): preserve contributor badges and enforce Python coverage

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: share changed-code coverage contracts and enforce shell policy

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* fix(ci): enforce private review files and run path regressions

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test: measure changed gettext shell coverage

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test: pin coverage to the reviewed PR revision

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-14 22:52:37 -04:00

35 lines
1.4 KiB
Python

"""Guard against missing coverage files and rounded threshold failures.
Copyright (C) 2004-2026 The Cacti Group. GPL-2.0-or-later.
"""
import unittest
from unittest.mock import patch
import check_changed_python_coverage as gate
class ChangedPythonCoverageTest(unittest.TestCase):
def test_missing_changed_file_fails(self):
result = gate.measure({'scripts/a.py': {1}}, {'files': {}})
self.assertFalse(gate.passes(result, 80))
def test_old_covered_lines_do_not_inflate_changed_coverage(self):
result = gate.measure({'scripts/a.py': {3, 4}}, {'files': {
'scripts/a.py': {'executed_lines': [1, 2, 3], 'missing_lines': [4]}}})
self.assertEqual(result['covered'], 1)
self.assertEqual(result['executable'], 2)
self.assertFalse(gate.passes(result, 80))
def test_threshold_is_not_rounded_up(self):
self.assertFalse(gate.passes({'covered': 7999, 'executable': 10000, 'files': {}}, 80))
self.assertTrue(gate.passes({'covered': 80, 'executable': 100, 'files': {}}, 80))
def test_deletions_do_not_require_added_line_coverage(self):
diff = ('diff --git a/scripts/a.py b/scripts/a.py\n+++ b/scripts/a.py\n'
'@@ -3 +2,0 @@\n-return True\n')
with patch.object(gate.subprocess, 'check_output', side_effect=['base', diff]):
self.assertEqual(gate.added_lines('HEAD^'), {})
if __name__ == '__main__':
unittest.main()