Skip to content

Commit fb5fa27

Browse files
committed
test(fixtures): update repo definitions & improve reusability & maintenance
1 parent 673da68 commit fb5fa27

File tree

9 files changed

+797
-158
lines changed

9 files changed

+797
-158
lines changed

tests/const.py

Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import git
44

5+
import semantic_release
56
from semantic_release.cli.commands.main import Cli
67

78
A_FULL_VERSION_STRING = "1.11.567"
@@ -12,7 +13,7 @@
1213
EXAMPLE_REPO_NAME = "example_repo"
1314
EXAMPLE_HVCS_DOMAIN = "example.com"
1415

15-
MAIN_PROG_NAME = str(__import__("semantic_release").__name__).replace("_", "-")
16+
MAIN_PROG_NAME = str(semantic_release.__name__).replace("_", "-")
1617
SUCCESS_EXIT_CODE = 0
1718

1819
CHANGELOG_SUBCMD = Cli.SubCmds.CHANGELOG.name.lower()
@@ -27,58 +28,41 @@
2728

2829
COMMIT_MESSAGE = "{version}\n\nAutomatically generated by python-semantic-release\n"
2930

31+
ANGULAR_COMMITS_CHORE = ("ci: added a commit lint job\n",)
3032
# Different in-scope commits that produce a certain release type
31-
ANGULAR_COMMITS_PATCH = [
32-
"fix: something annoying\n",
33-
"fixup the bugfix\n",
34-
"oops it broke again\n",
35-
"fix\n",
36-
"fix\n",
37-
"fix\n",
38-
"fix\n",
39-
"fix: release the bugfix-fix\n",
40-
]
41-
ANGULAR_COMMITS_MINOR = [
42-
"feat: something special\n",
43-
"fix: needed a tweak\n",
44-
"tweaked again\n",
45-
"tweaked again\n",
46-
"tweaked again\n",
47-
"fix\n",
48-
"fix\n",
33+
ANGULAR_COMMITS_PATCH = (
34+
*ANGULAR_COMMITS_CHORE,
35+
"fix: fixed voltage in the flux capacitor\n",
36+
)
37+
ANGULAR_COMMITS_MINOR = (
38+
*ANGULAR_COMMITS_PATCH,
4939
"feat: last minute rush order\n",
50-
]
40+
)
5141
# Take previous commits and insert a breaking change
52-
ANGULAR_COMMITS_MAJOR = ANGULAR_COMMITS_MINOR.copy()
53-
ANGULAR_COMMITS_MAJOR.insert(
54-
4, "fix!: big change\n\nBREAKING CHANGE: reworked something for previous feature\n"
42+
ANGULAR_COMMITS_MAJOR = (
43+
*ANGULAR_COMMITS_MINOR,
44+
"fix!: big change\n\nBREAKING CHANGE: reworked something for previous feature\n",
5545
)
5646

57-
EMOJI_COMMITS_PATCH = [
58-
":bug: something annoying\n",
59-
"fixup the bugfix\n",
60-
"oops it broke again\n",
61-
"fix\n",
62-
"fix\n",
63-
"fix\n",
64-
"fix\n",
65-
"fix\n",
66-
":bug: release the bugfix-fix\n",
67-
]
68-
EMOJI_COMMITS_MINOR = [
69-
":sparkles: something special\n",
47+
EMOJI_COMMITS_CHORE = (
48+
":broom: updated lint & code style\n",
49+
":none: updated ci pipeline\n",
50+
)
51+
52+
EMOJI_COMMITS_PATCH = (
53+
*EMOJI_COMMITS_CHORE,
54+
":bug: fixed voltage in the flux capacitor\n",
55+
)
56+
EMOJI_COMMITS_MINOR = (
57+
*EMOJI_COMMITS_PATCH,
7058
":sparkles::pencil: docs for something special\n",
71-
":bug: needed a tweak\n",
72-
"tweaked again\n",
73-
"tweaked again\n",
74-
"tweaked again\n",
75-
"fix\n",
76-
"fix\n",
7759
# Emoji in description should not be used to evaluate change type
78-
":sparkles: last minute rush order\n\n:boom: Good thing we're 10x developers",
79-
]
80-
EMOJI_COMMITS_MAJOR = EMOJI_COMMITS_MINOR.copy()
81-
EMOJI_COMMITS_MAJOR.insert(4, ":boom: Move to the blockchain")
60+
":sparkles: last minute rush order\n\n:boom: Good thing we're 10x developers\n",
61+
)
62+
EMOJI_COMMITS_MAJOR = (
63+
*EMOJI_COMMITS_MINOR,
64+
":boom: Move to the blockchain\n",
65+
)
8266

8367
# Note - the scipy commit fixtures for commits that should evaluate to the various scopes
8468
# are in tests/fixtures/scipy
@@ -293,12 +277,15 @@ def _read_long_description():
293277

294278
EXAMPLE_RELEASE_NOTES_TEMPLATE = r"""
295279
## What's Changed
296-
{% for type_, commits in release["elements"] | dictsort %}
297-
### {{ type_ | capitalize }}
298-
{%- if type_ != "unknown" %}
299-
{% for commit in commits %}
300-
* {{ commit.commit.summary.rstrip() }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
301-
{%- endfor %}{% endif %}{% endfor %}
280+
{% for type_, commits in release["elements"] | dictsort
281+
%}{{ "### %s" | format(type_ | title)
282+
}}{% if type_ != "unknown"
283+
%}{% for commit in commits
284+
%}{{ "* %s" | format(commit.descriptions[0] | trim)
285+
}}{% endfor
286+
%}{% endif
287+
%}{% endfor
288+
%}
302289
""".lstrip() # noqa: E501
303290

304291
RELEASE_NOTES = "# Release Notes"

tests/fixtures/commit_parsers.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
EmojiParserOptions,
88
)
99

10+
from tests.const import (
11+
ANGULAR_COMMITS_CHORE,
12+
ANGULAR_COMMITS_MAJOR,
13+
ANGULAR_COMMITS_MINOR,
14+
ANGULAR_COMMITS_PATCH,
15+
EMOJI_COMMITS_CHORE,
16+
EMOJI_COMMITS_MAJOR,
17+
EMOJI_COMMITS_MINOR,
18+
EMOJI_COMMITS_PATCH,
19+
)
20+
1021
# Note scipy defined in ./scipy.py as already used there
1122

1223

@@ -32,3 +43,43 @@ def default_emoji_parser_options(
3243
default_emoji_parser: EmojiCommitParser,
3344
) -> EmojiParserOptions:
3445
return default_emoji_parser.get_default_options()
46+
47+
48+
@pytest.fixture(scope="session")
49+
def angular_major_commits():
50+
return ANGULAR_COMMITS_MAJOR
51+
52+
53+
@pytest.fixture(scope="session")
54+
def angular_minor_commits():
55+
return ANGULAR_COMMITS_MINOR
56+
57+
58+
@pytest.fixture(scope="session")
59+
def angular_patch_commits():
60+
return ANGULAR_COMMITS_PATCH
61+
62+
63+
@pytest.fixture(scope="session")
64+
def angular_chore_commits():
65+
return ANGULAR_COMMITS_CHORE
66+
67+
68+
@pytest.fixture(scope="session")
69+
def emoji_major_commits():
70+
return EMOJI_COMMITS_MAJOR
71+
72+
73+
@pytest.fixture(scope="session")
74+
def emoji_minor_commits():
75+
return EMOJI_COMMITS_MINOR
76+
77+
78+
@pytest.fixture(scope="session")
79+
def emoji_patch_commits():
80+
return EMOJI_COMMITS_PATCH
81+
82+
83+
@pytest.fixture(scope="session")
84+
def emoji_chore_commits():
85+
return EMOJI_COMMITS_CHORE

tests/fixtures/example_project.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
ExProjectDir = Path
4141

42+
class GetWheelFileFn(Protocol):
43+
def __call__(self, version_str: str) -> Path: ...
44+
4245
class SetFlagFn(Protocol):
4346
def __call__(self, flag: bool) -> None: ...
4447

@@ -73,6 +76,11 @@ def setup_py_file() -> Path:
7376
return Path("setup.py")
7477

7578

79+
@pytest.fixture(scope="session")
80+
def dist_dir() -> Path:
81+
return Path("dist")
82+
83+
7684
@pytest.fixture(scope="session")
7785
def changelog_md_file() -> Path:
7886
return Path("CHANGELOG.md")
@@ -98,6 +106,14 @@ def default_rst_changelog_insertion_flag() -> str:
98106
return f"..{os.linesep} version list"
99107

100108

109+
@pytest.fixture(scope="session")
110+
def get_wheel_file(dist_dir: Path) -> GetWheelFileFn:
111+
def _get_wheel_file(version_str: str) -> Path:
112+
return dist_dir / f"{EXAMPLE_PROJECT_NAME}-{version_str}-py3-none-any.whl"
113+
114+
return _get_wheel_file
115+
116+
101117
@pytest.fixture
102118
def example_project_dir(tmp_path: Path) -> ExProjectDir:
103119
return tmp_path.resolve()
@@ -248,6 +264,22 @@ def example_setup_py(
248264
return example_project_dir / setup_py_file
249265

250266

267+
@pytest.fixture
268+
def example_dist_dir(
269+
example_project_dir: ExProjectDir,
270+
dist_dir: Path,
271+
) -> Path:
272+
return example_project_dir / dist_dir
273+
274+
275+
@pytest.fixture
276+
def example_project_wheel_file(
277+
example_dist_dir: Path,
278+
get_wheel_file: GetWheelFileFn,
279+
) -> Path:
280+
return example_dist_dir / get_wheel_file(EXAMPLE_PROJECT_VERSION)
281+
282+
251283
# Note this is just the path and the content may change
252284
@pytest.fixture
253285
def example_changelog_md(

tests/fixtures/git_repo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from functools import reduce
45
from pathlib import Path
56
from textwrap import dedent
@@ -33,6 +34,7 @@
3334
from tests.conftest import TeardownCachedDirFn
3435
from tests.fixtures.example_project import (
3536
ExProjectDir,
37+
GetWheelFileFn,
3638
UpdatePyprojectTomlFn,
3739
UseCustomParserFn,
3840
UseHvcsFn,
@@ -271,6 +273,7 @@ def build_configured_base_repo( # noqa: C901
271273
use_custom_parser: UseCustomParserFn,
272274
example_git_https_url: str,
273275
update_pyproject_toml: UpdatePyprojectTomlFn,
276+
get_wheel_file: GetWheelFileFn,
274277
) -> BuildRepoFn:
275278
"""
276279
This fixture is intended to simplify repo scenario building by initially
@@ -326,6 +329,28 @@ def _build_configured_base_repo( # noqa: C901
326329
"tool.semantic_release.tag_format", tag_format_str
327330
)
328331

332+
# Set the build_command to create a wheel file (using the build_command_env version variable)
333+
build_result_file = (
334+
get_wheel_file("$NEW_VERSION")
335+
if sys.platform != "win32"
336+
else get_wheel_file("$Env:NEW_VERSION")
337+
)
338+
update_pyproject_toml(
339+
# NOTE: must work in both bash and Powershell
340+
"tool.semantic_release.build_command",
341+
dedent(
342+
f"""\
343+
mkdir -p "{build_result_file.parent}"
344+
touch "{build_result_file}"
345+
"""
346+
if sys.platform != "win32"
347+
else f"""\
348+
mkdir {build_result_file.parent} > $null
349+
New-Item -ItemType file -Path "{build_result_file}" -Force | Select-Object OriginalPath
350+
"""
351+
),
352+
)
353+
329354
# Apply configurations to pyproject.toml
330355
if extra_configs is not None:
331356
for key, value in extra_configs.items():

0 commit comments

Comments
 (0)