Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Nov 27, 2022
1 parent 3dd5856 commit e9ac1f4
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ omit = [
]

[tool.coverage.paths]
hatch = ["src", "*/hatch/src"]
hatchling = ["backend/src", "*/hatch/backend/src"]
hatch = ["src/hatch", "*/hatch/src/hatch"]
hatchling = ["backend/src/hatchling", "*/hatch/backend/src/hatchling"]
tests = ["tests", "*/hatch/tests"]

[tool.coverage.report]
Expand Down
31 changes: 30 additions & 1 deletion src/hatch/template/files_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,20 @@ def __init__(self, template_config: dict, plugin_config: dict):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -192,7 +202,26 @@ def __init__(self, template_config: dict, plugin_config: dict):
]
[tool.ruff.isort]
known-first-party = ["{template_config['package_name']}"]"""
known-first-party = ["{template_config['package_name']}"]
[tool.coverage.run]
source_pkgs = ["{template_config['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"{package_location}{template_config['package_name']}/__about__.py",
]
[tool.coverage.paths]
{template_config['package_name']} = ["{package_location}{template_config['package_name']}", "*/{template_config['project_name_normalized']}/{package_location}{template_config['package_name']}"]
tests = ["tests", "*/{template_config['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]""" # noqa: E501

super().__init__(
Path('pyproject.toml'),
Expand Down
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -163,6 +173,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/feature_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,20 @@ def {kwargs['package_name']}(ctx: click.Context):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -198,6 +208,25 @@ def {kwargs['package_name']}(ctx: click.Context):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/feature_no_src_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -163,6 +173,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/licenses_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -126,6 +136,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/licenses_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -166,6 +176,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/projects_urls_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -158,6 +168,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]
31 changes: 30 additions & 1 deletion tests/helpers/templates/new/projects_urls_space_in_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,20 @@ def get_files(**kwargs):
[tool.hatch.envs.default]
dependencies = [
"coverage[toml]>=6.5",
"pytest",
]
[tool.hatch.envs.default.scripts]
test = "pytest {{args:tests}}"
test-cov = "coverage run -m pytest {{args:tests}}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]
[[tool.hatch.envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
Expand Down Expand Up @@ -161,6 +171,25 @@ def get_files(**kwargs):
[tool.ruff.isort]
known-first-party = ["{kwargs['package_name']}"]
""",
[tool.coverage.run]
source_pkgs = ["{kwargs['package_name']}", "tests"]
branch = true
parallel = true
omit = [
"src/{kwargs['package_name']}/__about__.py",
]
[tool.coverage.paths]
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
""", # noqa: E501
),
]

0 comments on commit e9ac1f4

Please sign in to comment.