Skip to content

Commit

Permalink
Merge pull request #115 from Infleqtion/modular-coverage
Browse files Browse the repository at this point in the history
Improved modular coverage
  • Loading branch information
perlinm authored Jun 20, 2024
2 parents b81bb26 + c474d75 commit 9e7b139
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
29 changes: 1 addition & 28 deletions checks/coverage_.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
#!/usr/bin/env python3
import sys
from collections.abc import Iterable

import checks_superstaq
import pytest_


def run_modular(exclude: str | Iterable[str] = ("*_test.py",) + pytest_.EXCLUDE) -> int:
"""Check that each file is covered by its own data file."""

# start by identifying files that should be covered
tracked_files = checks_superstaq.check_utils.get_tracked_files("*.py")
coverage_files = checks_superstaq.check_utils.exclude_files(tracked_files, exclude)

# run checks on individual files
exit_codes = {}
for file in coverage_files:
exit_codes[file] = checks_superstaq.coverage_.run(file)

# print warnings for files that are not covered
for file, exit_code in exit_codes.items():
if exit_code:
checks_superstaq.check_utils.warning(f"Coverage failed for {file}.")

return sum(exit_codes.values())


if __name__ == "__main__":
if sys.argv[1:]:
# check coverage for the provided arguments
exit(checks_superstaq.coverage_.run(*sys.argv[1:]))

# check for modular coverage
exit(run_modular())
exit(checks_superstaq.coverage_.run(*sys.argv[1:], "--modular", exclude=pytest_.EXCLUDE))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ platformdirs = ">=4.0.0"
pymatching = ">=2.1.0"
sympy = ">=1.12"

checks-superstaq = { version = ">=0.5.0", optional = true }
checks-superstaq = { version = ">=0.5.19", optional = true }

[tool.poetry.extras]
dev = ["checks-superstaq"]
Expand Down

0 comments on commit 9e7b139

Please sign in to comment.