mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Reduce code duplication and some code coverage reporting improvements
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
4ebc2c3670
commit
5242d44474
12 changed files with 240 additions and 286 deletions
|
@ -48,6 +48,7 @@ env:
|
|||
COLUMNS: 190
|
||||
PIP_INDEX_URL: "https://pypi-proxy.saltstack.net/root/local/+simple/"
|
||||
PIP_EXTRA_INDEX_URL: "https://pypi.org/simple"
|
||||
GITHUB_ACTIONS_PIPELINE: "1"
|
||||
|
||||
jobs:
|
||||
|
||||
|
|
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
|
@ -2204,6 +2204,14 @@ jobs:
|
|||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
@ -2216,11 +2224,27 @@ jobs:
|
|||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Full Code Coverage HTML Report
|
||||
- name: Report Combined Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report
|
||||
|
||||
- name: Create Combined Code Coverage JSON Report
|
||||
run: |
|
||||
nox --force-color -e create-json-coverage-reports
|
||||
|
||||
- name: Upload Combined Code Coverage JSON Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-json-report
|
||||
path: artifacts/coverage/coverage.json
|
||||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Combined Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report
|
||||
|
||||
- name: Upload Full Code Coverage HTML Report
|
||||
- name: Upload Combined Code Coverage HTML Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-html-report
|
||||
|
|
28
.github/workflows/nightly.yml
vendored
28
.github/workflows/nightly.yml
vendored
|
@ -2265,6 +2265,14 @@ jobs:
|
|||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
@ -2277,11 +2285,27 @@ jobs:
|
|||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Full Code Coverage HTML Report
|
||||
- name: Report Combined Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report
|
||||
|
||||
- name: Create Combined Code Coverage JSON Report
|
||||
run: |
|
||||
nox --force-color -e create-json-coverage-reports
|
||||
|
||||
- name: Upload Combined Code Coverage JSON Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-json-report
|
||||
path: artifacts/coverage/coverage.json
|
||||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Combined Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report
|
||||
|
||||
- name: Upload Full Code Coverage HTML Report
|
||||
- name: Upload Combined Code Coverage HTML Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-html-report
|
||||
|
|
28
.github/workflows/scheduled.yml
vendored
28
.github/workflows/scheduled.yml
vendored
|
@ -2238,6 +2238,14 @@ jobs:
|
|||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
@ -2250,11 +2258,27 @@ jobs:
|
|||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Full Code Coverage HTML Report
|
||||
- name: Report Combined Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report
|
||||
|
||||
- name: Create Combined Code Coverage JSON Report
|
||||
run: |
|
||||
nox --force-color -e create-json-coverage-reports
|
||||
|
||||
- name: Upload Combined Code Coverage JSON Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-json-report
|
||||
path: artifacts/coverage/coverage.json
|
||||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Combined Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report
|
||||
|
||||
- name: Upload Full Code Coverage HTML Report
|
||||
- name: Upload Combined Code Coverage HTML Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-html-report
|
||||
|
|
28
.github/workflows/templates/ci.yml.jinja
vendored
28
.github/workflows/templates/ci.yml.jinja
vendored
|
@ -374,6 +374,14 @@
|
|||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Report Salt Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
||||
- name: Create Salt Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report -- salt
|
||||
|
@ -386,11 +394,27 @@
|
|||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Full Code Coverage HTML Report
|
||||
- name: Report Combined Code Coverage
|
||||
run: |
|
||||
nox --force-color -e coverage-report
|
||||
|
||||
- name: Create Combined Code Coverage JSON Report
|
||||
run: |
|
||||
nox --force-color -e create-json-coverage-reports
|
||||
|
||||
- name: Upload Combined Code Coverage JSON Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-json-report
|
||||
path: artifacts/coverage/coverage.json
|
||||
retention-days: 7
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Create Combined Code Coverage HTML Report
|
||||
run: |
|
||||
nox --force-color -e create-html-coverage-report
|
||||
|
||||
- name: Upload Full Code Coverage HTML Report
|
||||
- name: Upload Combined Code Coverage HTML Report
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: code-coverage-full-html-report
|
||||
|
|
12
.github/workflows/test-action-macos.yml
vendored
12
.github/workflows/test-action-macos.yml
vendored
|
@ -400,12 +400,6 @@ jobs:
|
|||
run: |
|
||||
python3 -m pip install 'nox==${{ inputs.nox-version }}'
|
||||
|
||||
- name: Combine Code Coverage
|
||||
if: ${{ inputs.skip-code-coverage == false }}
|
||||
continue-on-error: true
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
|
@ -494,12 +488,6 @@ jobs:
|
|||
run: |
|
||||
nox --force-color -e report-coverage -- salt
|
||||
|
||||
- name: Report Tests Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
continue-on-error: true
|
||||
run: |
|
||||
nox --force-color -e report-coverage -- tests
|
||||
|
||||
- name: Report Combined Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
continue-on-error: true
|
||||
|
|
12
.github/workflows/test-action.yml
vendored
12
.github/workflows/test-action.yml
vendored
|
@ -347,12 +347,6 @@ jobs:
|
|||
run: |
|
||||
python3 -m pip install 'nox==${{ inputs.nox-version }}'
|
||||
|
||||
- name: Combine Code Coverage
|
||||
if: ${{ inputs.skip-code-coverage == false }}
|
||||
continue-on-error: true
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
|
||||
- name: Create XML Coverage Reports
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
|
@ -441,12 +435,6 @@ jobs:
|
|||
run: |
|
||||
nox --force-color -e report-coverage -- salt
|
||||
|
||||
- name: Report Tests Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
continue-on-error: true
|
||||
run: |
|
||||
nox --force-color -e report-coverage -- tests
|
||||
|
||||
- name: Report Combined Code Coverage
|
||||
if: always() && inputs.skip-code-coverage == false && steps.download-coverage-artifacts.outcome == 'success'
|
||||
continue-on-error: true
|
||||
|
|
|
@ -173,10 +173,10 @@ jobs:
|
|||
-E SALT_REPO_DOMAIN_RELEASE -E SALT_REPO_DOMAIN_STAGING -E LATEST_SALT_RELEASE -E DOWNLOAD_TEST_PACKAGE_TYPE \
|
||||
--nox-session=${{ inputs.nox-session }}-pkgs --rerun-failures ${{ inputs.distro-slug }} -- download-pkgs
|
||||
|
||||
- name: Combine Coverage Reports
|
||||
- name: Create XML Coverage Reports
|
||||
if: always() && inputs.skip-code-coverage == false && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
tools --timestamps vm combine-coverage ${{ inputs.distro-slug }}
|
||||
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
|
||||
|
||||
- name: Download Test Run Artifacts
|
||||
id: download-artifacts-from-vm
|
||||
|
|
|
@ -166,10 +166,10 @@ jobs:
|
|||
run: |
|
||||
sudo chown -R "$(id -un)" .
|
||||
|
||||
- name: Combine Coverage Reports
|
||||
- name: Create XML Coverage Reports
|
||||
if: always() && inputs.skip-code-coverage == false && job.status != 'cancelled'
|
||||
run: |
|
||||
nox --force-color -e combine-coverage
|
||||
nox --force-color -e create-xml-coverage-reports
|
||||
|
||||
- name: Prepare Test Run Artifacts
|
||||
id: download-artifacts-from-vm
|
||||
|
|
|
@ -172,10 +172,10 @@ jobs:
|
|||
-E SALT_REPO_DOMAIN_RELEASE -E SALT_REPO_DOMAIN_STAGING -E LATEST_SALT_RELEASE -E DOWNLOAD_TEST_PACKAGE_TYPE \
|
||||
--nox-session=${{ inputs.nox-session }}-pkgs --rerun-failures ${{ inputs.distro-slug }} -- download-pkgs
|
||||
|
||||
- name: Combine Coverage Reports
|
||||
- name: Create XML Coverage Reports
|
||||
if: always() && inputs.skip-code-coverage == false && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'
|
||||
run: |
|
||||
tools --timestamps vm combine-coverage ${{ inputs.distro-slug }}
|
||||
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
|
||||
|
||||
- name: Download Test Run Artifacts
|
||||
id: download-artifacts-from-vm
|
||||
|
|
371
noxfile.py
371
noxfile.py
|
@ -6,7 +6,9 @@ Nox configuration script
|
|||
"""
|
||||
# pylint: disable=resource-leakage,3rd-party-module-not-gated
|
||||
|
||||
import contextlib
|
||||
import datetime
|
||||
import glob
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
|
@ -351,8 +353,6 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
|
|||
if env is None:
|
||||
env = {}
|
||||
|
||||
coverage_base_env = {}
|
||||
|
||||
sitecustomize_dir = session.run(
|
||||
"salt-factories", "--coverage", silent=True, log=True, stderr=None
|
||||
)
|
||||
|
@ -384,80 +384,36 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
|
|||
python_path_entries.insert(0, str(sitecustomize_dir))
|
||||
python_path_env_var = os.pathsep.join(python_path_entries)
|
||||
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
coverage_base_env["COVERAGE_FILE"] = COVERAGE_FILE
|
||||
|
||||
env.update(
|
||||
{
|
||||
# The updated python path so that sitecustomize is importable
|
||||
"PYTHONPATH": python_path_env_var,
|
||||
# Instruct sub processes to also run under coverage
|
||||
"COVERAGE_PROCESS_START": str(REPO_ROOT / ".coveragerc"),
|
||||
},
|
||||
**coverage_base_env,
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
"COVERAGE_FILE": COVERAGE_FILE,
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
session.run(*test_cmd, env=env)
|
||||
finally:
|
||||
if os.environ.get("GITHUB_ACTIONS_PIPELINE", "0") == "0":
|
||||
# Always combine and generate the XML coverage report
|
||||
try:
|
||||
session.run(
|
||||
"coverage",
|
||||
"combine",
|
||||
env=coverage_base_env,
|
||||
)
|
||||
except CommandFailed:
|
||||
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
||||
# exception
|
||||
pass
|
||||
# Generate report for tests code coverage
|
||||
session.run(
|
||||
"coverage",
|
||||
"xml",
|
||||
"-o",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("tests.xml").relative_to(REPO_ROOT)),
|
||||
"--omit=salt/*",
|
||||
"--include=tests/*,pkg/tests/*",
|
||||
env=coverage_base_env,
|
||||
)
|
||||
# Generate report for salt code coverage
|
||||
session.run(
|
||||
"coverage",
|
||||
"xml",
|
||||
"-o",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("salt.xml").relative_to(REPO_ROOT)),
|
||||
"--omit=tests/*,pkg/tests/*",
|
||||
"--include=salt/*",
|
||||
env=coverage_base_env,
|
||||
)
|
||||
# Generate html report for tests code coverage
|
||||
session.run(
|
||||
"coverage",
|
||||
"html",
|
||||
"-d",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("html").relative_to(REPO_ROOT)),
|
||||
"--omit=salt/*",
|
||||
"--include=tests/*,pkg/tests/*",
|
||||
env=coverage_base_env,
|
||||
)
|
||||
# Generate html report for salt code coverage
|
||||
session.run(
|
||||
"coverage",
|
||||
"html",
|
||||
"-d",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("html").relative_to(REPO_ROOT)),
|
||||
"--omit=tests/*,pkg/tests/*",
|
||||
"--include=salt/*",
|
||||
env=coverage_base_env,
|
||||
)
|
||||
session.run(*test_cmd, env=env)
|
||||
|
||||
|
||||
def _report_coverage(session):
|
||||
def _report_coverage(
|
||||
session,
|
||||
combine=True,
|
||||
cli_report=True,
|
||||
html_report=False,
|
||||
xml_report=False,
|
||||
json_report=False,
|
||||
):
|
||||
_install_coverage_requirement(session)
|
||||
|
||||
if not any([combine, cli_report, html_report, xml_report, json_report]):
|
||||
session.error(
|
||||
"At least one of combine, cli_report, html_report, xml_report, json_report needs to be True"
|
||||
)
|
||||
|
||||
env = {
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
|
@ -468,45 +424,56 @@ def _report_coverage(session):
|
|||
if session.posargs:
|
||||
report_section = session.posargs.pop(0)
|
||||
if report_section not in ("salt", "tests"):
|
||||
session.error("The report section can only be one of 'salt', 'tests'.")
|
||||
session.error(
|
||||
f"The report section can only be one of 'salt', 'tests', not: {report_section}"
|
||||
)
|
||||
if session.posargs:
|
||||
session.error(
|
||||
"Only one argument can be passed to the session, which is optional "
|
||||
"and is one of 'salt', 'tests'."
|
||||
)
|
||||
|
||||
# Always combine and generate the XML coverage report
|
||||
try:
|
||||
session.run("coverage", "combine", env=env)
|
||||
except CommandFailed:
|
||||
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
||||
# exception
|
||||
pass
|
||||
if combine is True:
|
||||
coverage_db_files = glob.glob(f"{COVERAGE_FILE}.*")
|
||||
if coverage_db_files:
|
||||
with contextlib.suppress(CommandFailed):
|
||||
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
||||
# exception
|
||||
session.run("coverage", "combine", env=env)
|
||||
elif os.path.exists(COVERAGE_FILE):
|
||||
session_warn(session, "Coverage files already combined.")
|
||||
|
||||
if not IS_WINDOWS:
|
||||
# The coverage file might have come from a windows machine, fix paths
|
||||
with sqlite3.connect(COVERAGE_FILE) as db:
|
||||
res = db.execute(r"SELECT * FROM file WHERE path LIKE '%salt\%'")
|
||||
if res.fetchone():
|
||||
session_warn(
|
||||
session,
|
||||
"Replacing backwards slashes with forward slashes on file "
|
||||
"paths in the coverage database",
|
||||
)
|
||||
db.execute(r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');")
|
||||
if os.path.exists(COVERAGE_FILE) and not IS_WINDOWS:
|
||||
# Some coverage files might have come from a windows machine, fix paths
|
||||
with sqlite3.connect(COVERAGE_FILE) as db:
|
||||
res = db.execute(r"SELECT * FROM file WHERE path LIKE '%salt\%'")
|
||||
if res.fetchone():
|
||||
session_warn(
|
||||
session,
|
||||
"Replacing backwards slashes with forward slashes on file "
|
||||
"paths in the coverage database",
|
||||
)
|
||||
db.execute(
|
||||
r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');"
|
||||
)
|
||||
|
||||
if not os.path.exists(COVERAGE_FILE):
|
||||
session.error("No coverage files found.")
|
||||
|
||||
if report_section == "salt":
|
||||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-salt.json"
|
||||
)
|
||||
json_coverage_file = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "salt.json"
|
||||
xml_coverage_file = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "salt.xml"
|
||||
html_coverage_dir = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "html" / "salt"
|
||||
cmd_args = [
|
||||
"--omit=tests/*,pkg/tests/*",
|
||||
"--include=salt/*",
|
||||
]
|
||||
|
||||
elif report_section == "tests":
|
||||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-tests.json"
|
||||
json_coverage_file = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "tests.json"
|
||||
xml_coverage_file = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "tests.xml"
|
||||
html_coverage_dir = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "html" / "tests"
|
||||
)
|
||||
cmd_args = [
|
||||
"--omit=salt/*",
|
||||
|
@ -516,25 +483,58 @@ def _report_coverage(session):
|
|||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage.json"
|
||||
)
|
||||
xml_coverage_file = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage.xml"
|
||||
html_coverage_dir = COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "html" / "full"
|
||||
cmd_args = [
|
||||
"--include=salt/*,tests/*,pkg/tests/*",
|
||||
]
|
||||
|
||||
session.run(
|
||||
"coverage",
|
||||
"report",
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
if cli_report:
|
||||
session.run(
|
||||
"coverage",
|
||||
"report",
|
||||
"--precision=2",
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
|
||||
session.run(
|
||||
"coverage",
|
||||
"json",
|
||||
"-o",
|
||||
str(json_coverage_file),
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
if html_report:
|
||||
session.run(
|
||||
"coverage",
|
||||
"html",
|
||||
"-d",
|
||||
str(html_coverage_dir),
|
||||
"--show-contexts",
|
||||
"--precision=2",
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
|
||||
if xml_report:
|
||||
try:
|
||||
session.run(
|
||||
"coverage",
|
||||
"xml",
|
||||
"-o",
|
||||
str(xml_coverage_file),
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
except CommandFailed:
|
||||
session_warn(
|
||||
session, "Failed to generate the source XML code coverage report"
|
||||
)
|
||||
|
||||
if json_report:
|
||||
session.run(
|
||||
"coverage",
|
||||
"json",
|
||||
"-o",
|
||||
str(json_coverage_file),
|
||||
"--show-contexts",
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
|
||||
|
||||
@nox.session(python=_PYTHON_VERSIONS, name="test-parametrized")
|
||||
|
@ -1208,7 +1208,12 @@ def ci_test_onedir_tcp(session):
|
|||
|
||||
@nox.session(python="3", name="report-coverage")
|
||||
def report_coverage(session):
|
||||
_report_coverage(session)
|
||||
_report_coverage(session, combine=True, cli_report=True)
|
||||
|
||||
|
||||
@nox.session(python="3", name="coverage-report")
|
||||
def coverage_report(session):
|
||||
_report_coverage(session, combine=True, cli_report=True)
|
||||
|
||||
|
||||
@nox.session(python=False, name="decompress-dependencies")
|
||||
|
@ -1335,20 +1340,7 @@ def pre_archive_cleanup(session, pkg):
|
|||
|
||||
@nox.session(python="3", name="combine-coverage")
|
||||
def combine_coverage(session):
|
||||
_install_coverage_requirement(session)
|
||||
env = {
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
"COVERAGE_FILE": str(COVERAGE_FILE),
|
||||
}
|
||||
|
||||
# Always combine and generate the XML coverage report
|
||||
try:
|
||||
session.run("coverage", "combine", env=env)
|
||||
except CommandFailed:
|
||||
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
||||
# exception
|
||||
pass
|
||||
_report_coverage(session, combine=True, cli_report=False)
|
||||
|
||||
|
||||
@nox.session(
|
||||
|
@ -1357,140 +1349,17 @@ def combine_coverage(session):
|
|||
venv_params=["--system-site-packages"],
|
||||
)
|
||||
def combine_coverage_onedir(session):
|
||||
_install_coverage_requirement(session)
|
||||
env = {
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
"COVERAGE_FILE": str(COVERAGE_FILE),
|
||||
}
|
||||
|
||||
# Always combine and generate the XML coverage report
|
||||
try:
|
||||
session.run("coverage", "combine", env=env)
|
||||
except CommandFailed:
|
||||
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
|
||||
# exception
|
||||
pass
|
||||
_report_coverage(session, combine=True, cli_report=False)
|
||||
|
||||
|
||||
@nox.session(python="3", name="create-html-coverage-report")
|
||||
def create_html_coverage_report(session):
|
||||
_install_coverage_requirement(session)
|
||||
env = {
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
"COVERAGE_FILE": str(COVERAGE_FILE),
|
||||
}
|
||||
|
||||
report_section = None
|
||||
if session.posargs:
|
||||
report_section = session.posargs.pop(0)
|
||||
if report_section not in ("salt", "tests"):
|
||||
session.error("The report section can only be one of 'salt', 'tests'.")
|
||||
if session.posargs:
|
||||
session.error(
|
||||
"Only one argument can be passed to the session, which is optional "
|
||||
"and is one of 'salt', 'tests'."
|
||||
)
|
||||
|
||||
if not IS_WINDOWS:
|
||||
# The coverage file might have come from a windows machine, fix paths
|
||||
with sqlite3.connect(COVERAGE_FILE) as db:
|
||||
res = db.execute(r"SELECT * FROM file WHERE path LIKE '%salt\%'")
|
||||
if res.fetchone():
|
||||
session_warn(
|
||||
session,
|
||||
"Replacing backwards slashes with forward slashes on file "
|
||||
"paths in the coverage database",
|
||||
)
|
||||
db.execute(r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');")
|
||||
|
||||
if report_section == "salt":
|
||||
report_dir = str(
|
||||
COVERAGE_OUTPUT_DIR.joinpath("html", "salt").relative_to(REPO_ROOT)
|
||||
)
|
||||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-salt.json"
|
||||
)
|
||||
cmd_args = [
|
||||
"--omit=tests/*,pkg/tests/*",
|
||||
"--include=salt/*",
|
||||
]
|
||||
|
||||
elif report_section == "tests":
|
||||
report_dir = str(
|
||||
COVERAGE_OUTPUT_DIR.joinpath("html", "tests").relative_to(REPO_ROOT)
|
||||
)
|
||||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-tests.json"
|
||||
)
|
||||
cmd_args = [
|
||||
"--omit=salt/*",
|
||||
"--include=tests/*,pkg/tests/*",
|
||||
]
|
||||
else:
|
||||
report_dir = str(
|
||||
COVERAGE_OUTPUT_DIR.joinpath("html", "full").relative_to(REPO_ROOT)
|
||||
)
|
||||
json_coverage_file = (
|
||||
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage.json"
|
||||
)
|
||||
cmd_args = [
|
||||
"--include=salt/*,tests/*,pkg/tests/*",
|
||||
]
|
||||
|
||||
# Generate html report for Salt and tests combined code coverage
|
||||
session.run(
|
||||
"coverage",
|
||||
"html",
|
||||
"-d",
|
||||
report_dir,
|
||||
"--show-contexts",
|
||||
*cmd_args,
|
||||
env=env,
|
||||
)
|
||||
|
||||
|
||||
def _create_xml_coverage_reports(session):
|
||||
_install_coverage_requirement(session)
|
||||
env = {
|
||||
# The full path to the .coverage data file. Makes sure we always write
|
||||
# them to the same directory
|
||||
"COVERAGE_FILE": str(COVERAGE_FILE),
|
||||
}
|
||||
|
||||
# Generate report for tests code coverage
|
||||
try:
|
||||
session.run(
|
||||
"coverage",
|
||||
"xml",
|
||||
"-o",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("tests.xml").relative_to(REPO_ROOT)),
|
||||
"--omit=salt/*",
|
||||
"--include=tests/*,pkg/tests/*",
|
||||
env=env,
|
||||
)
|
||||
except CommandFailed:
|
||||
session_warn(session, "Failed to generate the tests XML code coverage report")
|
||||
|
||||
# Generate report for salt code coverage
|
||||
try:
|
||||
session.run(
|
||||
"coverage",
|
||||
"xml",
|
||||
"-o",
|
||||
str(COVERAGE_OUTPUT_DIR.joinpath("salt.xml").relative_to(REPO_ROOT)),
|
||||
"--omit=tests/*,pkg/tests/*",
|
||||
"--include=salt/*",
|
||||
env=env,
|
||||
)
|
||||
except CommandFailed:
|
||||
session_warn(session, "Failed to generate the source XML code coverage report")
|
||||
_report_coverage(session, combine=True, cli_report=False, html_report=True)
|
||||
|
||||
|
||||
@nox.session(python="3", name="create-xml-coverage-reports")
|
||||
def create_xml_coverage_reports(session):
|
||||
_create_xml_coverage_reports(session)
|
||||
_report_coverage(session, combine=True, cli_report=False, xml_report=True)
|
||||
|
||||
|
||||
@nox.session(
|
||||
|
@ -1499,7 +1368,21 @@ def create_xml_coverage_reports(session):
|
|||
venv_params=["--system-site-packages"],
|
||||
)
|
||||
def create_xml_coverage_reports_onedir(session):
|
||||
_create_xml_coverage_reports(session)
|
||||
_report_coverage(session, combine=True, cli_report=False, xml_report=True)
|
||||
|
||||
|
||||
@nox.session(python="3", name="create-json-coverage-reports")
|
||||
def create_json_coverage_reports(session):
|
||||
_report_coverage(session, combine=True, cli_report=False, json_report=True)
|
||||
|
||||
|
||||
@nox.session(
|
||||
python=str(ONEDIR_PYTHON_PATH),
|
||||
name="create-json-coverage-reports-onedir",
|
||||
venv_params=["--system-site-packages"],
|
||||
)
|
||||
def create_json_coverage_reports_onedir(session):
|
||||
_report_coverage(session, combine=True, cli_report=False, json_report=True)
|
||||
|
||||
|
||||
class Tee:
|
||||
|
|
|
@ -1448,15 +1448,13 @@ class VM:
|
|||
"""
|
||||
Combine the code coverage databases
|
||||
"""
|
||||
return self.run_nox("combine-coverage-onedir", session_args=[self.name])
|
||||
return self.run_nox("combine-coverage-onedir")
|
||||
|
||||
def create_xml_coverage_reports(self):
|
||||
"""
|
||||
Create XML coverage reports
|
||||
"""
|
||||
return self.run_nox(
|
||||
"create-xml-coverage-reports-onedir", session_args=[self.name]
|
||||
)
|
||||
return self.run_nox("create-xml-coverage-reports-onedir")
|
||||
|
||||
def compress_dependencies(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue