Skip to content

Commit 4b7297f

Browse files
committed
add coverage
1 parent 3dd5856 commit 4b7297f

File tree

9 files changed

+235
-3
lines changed

9 files changed

+235
-3
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ omit = [
179179
]
180180

181181
[tool.coverage.paths]
182-
hatch = ["src", "*/hatch/src"]
183-
hatchling = ["backend/src", "*/hatch/backend/src"]
182+
hatch = ["src/hatch", "*/hatch/src/hatch"]
183+
hatchling = ["backend/src/hatchling", "*/hatch/backend/src/hatchling"]
184184
tests = ["tests", "*/hatch/tests"]
185185

186186
[tool.coverage.report]

src/hatch/template/files_default.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,20 @@ def __init__(self, template_config: dict, plugin_config: dict):
136136
137137
[tool.hatch.envs.default]
138138
dependencies = [
139+
"coverage[toml]>=6.5",
139140
"pytest",
140141
]
141142
[tool.hatch.envs.default.scripts]
142143
test = "pytest {{args:tests}}"
144+
test-cov = "coverage run -m pytest {{args:tests}}"
145+
cov-report = [
146+
"- coverage combine",
147+
"coverage report",
148+
]
149+
cov = [
150+
"test-cov",
151+
"cov-report",
152+
]
143153
144154
[[tool.hatch.envs.all.matrix]]
145155
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -192,7 +202,26 @@ def __init__(self, template_config: dict, plugin_config: dict):
192202
]
193203
194204
[tool.ruff.isort]
195-
known-first-party = ["{template_config['package_name']}"]"""
205+
known-first-party = ["{template_config['package_name']}"]
206+
207+
[tool.coverage.run]
208+
source_pkgs = ["{template_config['package_name']}", "tests"]
209+
branch = true
210+
parallel = true
211+
omit = [
212+
"{package_location}{template_config['package_name']}/__about__.py",
213+
]
214+
215+
[tool.coverage.paths]
216+
{template_config['package_name']} = ["{package_location}{template_config['package_name']}", "*/{template_config['project_name_normalized']}/{package_location}{template_config['package_name']}"]
217+
tests = ["tests", "*/{template_config['project_name_normalized']}/tests"]
218+
219+
[tool.coverage.report]
220+
exclude_lines = [
221+
"no cov",
222+
"if __name__ == .__main__.:",
223+
"if TYPE_CHECKING:",
224+
]""" # noqa: E501
196225

197226
super().__init__(
198227
Path('pyproject.toml'),

tests/helpers/templates/new/default.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,20 @@ def get_files(**kwargs):
106106
107107
[tool.hatch.envs.default]
108108
dependencies = [
109+
"coverage[toml]>=6.5",
109110
"pytest",
110111
]
111112
[tool.hatch.envs.default.scripts]
112113
test = "pytest {{args:tests}}"
114+
test-cov = "coverage run -m pytest {{args:tests}}"
115+
cov-report = [
116+
"- coverage combine",
117+
"coverage report",
118+
]
119+
cov = [
120+
"test-cov",
121+
"cov-report",
122+
]
113123
114124
[[tool.hatch.envs.all.matrix]]
115125
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -163,6 +173,25 @@ def get_files(**kwargs):
163173
164174
[tool.ruff.isort]
165175
known-first-party = ["{kwargs['package_name']}"]
176+
177+
[tool.coverage.run]
178+
source_pkgs = ["{kwargs['package_name']}", "tests"]
179+
branch = true
180+
parallel = true
181+
omit = [
182+
"src/{kwargs['package_name']}/__about__.py",
183+
]
184+
185+
[tool.coverage.paths]
186+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
187+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
188+
189+
[tool.coverage.report]
190+
exclude_lines = [
191+
"no cov",
192+
"if __name__ == .__main__.:",
193+
"if TYPE_CHECKING:",
194+
]
166195
""",
167196
),
168197
]

tests/helpers/templates/new/feature_cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,20 @@ def {kwargs['package_name']}(ctx: click.Context):
141141
142142
[tool.hatch.envs.default]
143143
dependencies = [
144+
"coverage[toml]>=6.5",
144145
"pytest",
145146
]
146147
[tool.hatch.envs.default.scripts]
147148
test = "pytest {{args:tests}}"
149+
test-cov = "coverage run -m pytest {{args:tests}}"
150+
cov-report = [
151+
"- coverage combine",
152+
"coverage report",
153+
]
154+
cov = [
155+
"test-cov",
156+
"cov-report",
157+
]
148158
149159
[[tool.hatch.envs.all.matrix]]
150160
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -198,6 +208,25 @@ def {kwargs['package_name']}(ctx: click.Context):
198208
199209
[tool.ruff.isort]
200210
known-first-party = ["{kwargs['package_name']}"]
211+
212+
[tool.coverage.run]
213+
source_pkgs = ["{kwargs['package_name']}", "tests"]
214+
branch = true
215+
parallel = true
216+
omit = [
217+
"src/{kwargs['package_name']}/__about__.py",
218+
]
219+
220+
[tool.coverage.paths]
221+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
222+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
223+
224+
[tool.coverage.report]
225+
exclude_lines = [
226+
"no cov",
227+
"if __name__ == .__main__.:",
228+
"if TYPE_CHECKING:",
229+
]
201230
""",
202231
),
203232
]

tests/helpers/templates/new/feature_no_src_layout.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,20 @@ def get_files(**kwargs):
106106
107107
[tool.hatch.envs.default]
108108
dependencies = [
109+
"coverage[toml]>=6.5",
109110
"pytest",
110111
]
111112
[tool.hatch.envs.default.scripts]
112113
test = "pytest {{args:tests}}"
114+
test-cov = "coverage run -m pytest {{args:tests}}"
115+
cov-report = [
116+
"- coverage combine",
117+
"coverage report",
118+
]
119+
cov = [
120+
"test-cov",
121+
"cov-report",
122+
]
113123
114124
[[tool.hatch.envs.all.matrix]]
115125
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -163,6 +173,25 @@ def get_files(**kwargs):
163173
164174
[tool.ruff.isort]
165175
known-first-party = ["{kwargs['package_name']}"]
176+
177+
[tool.coverage.run]
178+
source_pkgs = ["{kwargs['package_name']}", "tests"]
179+
branch = true
180+
parallel = true
181+
omit = [
182+
"{kwargs['package_name']}/__about__.py",
183+
]
184+
185+
[tool.coverage.paths]
186+
{kwargs['package_name']} = ["{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/{kwargs['package_name']}"]
187+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
188+
189+
[tool.coverage.report]
190+
exclude_lines = [
191+
"no cov",
192+
"if __name__ == .__main__.:",
193+
"if TYPE_CHECKING:",
194+
]
166195
""",
167196
),
168197
]

tests/helpers/templates/new/licenses_empty.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,20 @@ def get_files(**kwargs):
6969
7070
[tool.hatch.envs.default]
7171
dependencies = [
72+
"coverage[toml]>=6.5",
7273
"pytest",
7374
]
7475
[tool.hatch.envs.default.scripts]
7576
test = "pytest {{args:tests}}"
77+
test-cov = "coverage run -m pytest {{args:tests}}"
78+
cov-report = [
79+
"- coverage combine",
80+
"coverage report",
81+
]
82+
cov = [
83+
"test-cov",
84+
"cov-report",
85+
]
7686
7787
[[tool.hatch.envs.all.matrix]]
7888
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -126,6 +136,25 @@ def get_files(**kwargs):
126136
127137
[tool.ruff.isort]
128138
known-first-party = ["{kwargs['package_name']}"]
139+
140+
[tool.coverage.run]
141+
source_pkgs = ["{kwargs['package_name']}", "tests"]
142+
branch = true
143+
parallel = true
144+
omit = [
145+
"src/{kwargs['package_name']}/__about__.py",
146+
]
147+
148+
[tool.coverage.paths]
149+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
150+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
151+
152+
[tool.coverage.report]
153+
exclude_lines = [
154+
"no cov",
155+
"if __name__ == .__main__.:",
156+
"if TYPE_CHECKING:",
157+
]
129158
""",
130159
),
131160
]

tests/helpers/templates/new/licenses_multiple.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,20 @@ def get_files(**kwargs):
109109
110110
[tool.hatch.envs.default]
111111
dependencies = [
112+
"coverage[toml]>=6.5",
112113
"pytest",
113114
]
114115
[tool.hatch.envs.default.scripts]
115116
test = "pytest {{args:tests}}"
117+
test-cov = "coverage run -m pytest {{args:tests}}"
118+
cov-report = [
119+
"- coverage combine",
120+
"coverage report",
121+
]
122+
cov = [
123+
"test-cov",
124+
"cov-report",
125+
]
116126
117127
[[tool.hatch.envs.all.matrix]]
118128
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -166,6 +176,25 @@ def get_files(**kwargs):
166176
167177
[tool.ruff.isort]
168178
known-first-party = ["{kwargs['package_name']}"]
179+
180+
[tool.coverage.run]
181+
source_pkgs = ["{kwargs['package_name']}", "tests"]
182+
branch = true
183+
parallel = true
184+
omit = [
185+
"src/{kwargs['package_name']}/__about__.py",
186+
]
187+
188+
[tool.coverage.paths]
189+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
190+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
191+
192+
[tool.coverage.report]
193+
exclude_lines = [
194+
"no cov",
195+
"if __name__ == .__main__.:",
196+
"if TYPE_CHECKING:",
197+
]
169198
""",
170199
),
171200
]

tests/helpers/templates/new/projects_urls_empty.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ def get_files(**kwargs):
101101
102102
[tool.hatch.envs.default]
103103
dependencies = [
104+
"coverage[toml]>=6.5",
104105
"pytest",
105106
]
106107
[tool.hatch.envs.default.scripts]
107108
test = "pytest {{args:tests}}"
109+
test-cov = "coverage run -m pytest {{args:tests}}"
110+
cov-report = [
111+
"- coverage combine",
112+
"coverage report",
113+
]
114+
cov = [
115+
"test-cov",
116+
"cov-report",
117+
]
108118
109119
[[tool.hatch.envs.all.matrix]]
110120
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -158,6 +168,25 @@ def get_files(**kwargs):
158168
159169
[tool.ruff.isort]
160170
known-first-party = ["{kwargs['package_name']}"]
171+
172+
[tool.coverage.run]
173+
source_pkgs = ["{kwargs['package_name']}", "tests"]
174+
branch = true
175+
parallel = true
176+
omit = [
177+
"src/{kwargs['package_name']}/__about__.py",
178+
]
179+
180+
[tool.coverage.paths]
181+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
182+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
183+
184+
[tool.coverage.report]
185+
exclude_lines = [
186+
"no cov",
187+
"if __name__ == .__main__.:",
188+
"if TYPE_CHECKING:",
189+
]
161190
""",
162191
),
163192
]

tests/helpers/templates/new/projects_urls_space_in_label.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,20 @@ def get_files(**kwargs):
104104
105105
[tool.hatch.envs.default]
106106
dependencies = [
107+
"coverage[toml]>=6.5",
107108
"pytest",
108109
]
109110
[tool.hatch.envs.default.scripts]
110111
test = "pytest {{args:tests}}"
112+
test-cov = "coverage run -m pytest {{args:tests}}"
113+
cov-report = [
114+
"- coverage combine",
115+
"coverage report",
116+
]
117+
cov = [
118+
"test-cov",
119+
"cov-report",
120+
]
111121
112122
[[tool.hatch.envs.all.matrix]]
113123
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
@@ -161,6 +171,25 @@ def get_files(**kwargs):
161171
162172
[tool.ruff.isort]
163173
known-first-party = ["{kwargs['package_name']}"]
174+
175+
[tool.coverage.run]
176+
source_pkgs = ["{kwargs['package_name']}", "tests"]
177+
branch = true
178+
parallel = true
179+
omit = [
180+
"src/{kwargs['package_name']}/__about__.py",
181+
]
182+
183+
[tool.coverage.paths]
184+
{kwargs['package_name']} = ["src/{kwargs['package_name']}", "*/{kwargs['project_name_normalized']}/src/{kwargs['package_name']}"]
185+
tests = ["tests", "*/{kwargs['project_name_normalized']}/tests"]
186+
187+
[tool.coverage.report]
188+
exclude_lines = [
189+
"no cov",
190+
"if __name__ == .__main__.:",
191+
"if TYPE_CHECKING:",
192+
]
164193
""",
165194
),
166195
]

0 commit comments

Comments
 (0)