Skip to content

Commit 59114de

Browse files
committed
Fixed release unit test
1 parent c6b0653 commit 59114de

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

exasol/toolbox/nox/_release.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ReleaseTypes,
2020
Version,
2121
)
22-
from noxconfig import PROJECT_CONFIG
22+
import noxconfig
2323

2424

2525
def _create_parser() -> argparse.ArgumentParser:
@@ -91,7 +91,7 @@ def run(*args: str):
9191
run("git", "checkout", default_branch)
9292
run("git", "pull")
9393

94-
release_version = Version.from_poetry()
94+
release_version: Version = Version.from_poetry()
9595
print(f"release version: {release_version}")
9696

9797
if re.search(rf"{release_version}", run("git", "tag", "--list")):
@@ -103,8 +103,8 @@ def run(*args: str):
103103
run("git", "push", "origin", str(release_version))
104104

105105
if (
106-
hasattr(PROJECT_CONFIG, "create_major_version_tags")
107-
and PROJECT_CONFIG.create_major_version_tags
106+
hasattr(noxconfig.PROJECT_CONFIG, "create_major_version_tags")
107+
and noxconfig.PROJECT_CONFIG.create_major_version_tags
108108
):
109109
major_release_version = f"v{release_version.major}"
110110
run("git", "tag", "-f", str(major_release_version))
@@ -128,26 +128,26 @@ def prepare_release(session: Session) -> None:
128128
_ = _update_project_version(session, new_version)
129129

130130
changelogs = Changelogs(
131-
changes_path=PROJECT_CONFIG.doc / "changes",
132-
root_path=PROJECT_CONFIG.root,
131+
changes_path=noxconfig.PROJECT_CONFIG.doc / "changes",
132+
root_path=noxconfig.PROJECT_CONFIG.root,
133133
version=new_version,
134134
)
135135
changelogs.update_changelogs_for_release()
136136
changed_files = changelogs.get_changed_files()
137137

138-
pm = NoxTasks.plugin_manager(PROJECT_CONFIG)
138+
pm = NoxTasks.plugin_manager(noxconfig.PROJECT_CONFIG)
139139
pm.hook.prepare_release_update_version(
140-
session=session, config=PROJECT_CONFIG, version=new_version
140+
session=session, config=noxconfig.PROJECT_CONFIG, version=new_version
141141
)
142142

143143
if args.no_add:
144144
return
145145

146146
changed_files += [
147-
PROJECT_CONFIG.root / "pyproject.toml",
148-
PROJECT_CONFIG.version_file,
147+
noxconfig.PROJECT_CONFIG.root / "pyproject.toml",
148+
noxconfig.PROJECT_CONFIG.version_file,
149149
]
150-
results = pm.hook.prepare_release_add_files(session=session, config=PROJECT_CONFIG)
150+
results = pm.hook.prepare_release_add_files(session=session, config=noxconfig.PROJECT_CONFIG)
151151
changed_files += [f for plugin_response in results for f in plugin_response]
152152
_add_files_to_index(
153153
session,

test/unit/release_test.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from subprocess import CalledProcessError
22
from unittest.mock import (
33
MagicMock,
4-
patch,
4+
patch, call,
55
)
66

77
import pytest
@@ -10,12 +10,14 @@
1010
ReleaseError,
1111
_trigger_release,
1212
)
13+
from exasol.toolbox.util.version import Version
14+
import noxconfig
1315

1416

1517
@pytest.fixture(scope="class")
1618
def mock_from_poetry():
1719
with patch(
18-
"exasol.toolbox.nox._release.Version.from_poetry", return_value="0.3.0"
20+
"exasol.toolbox.nox._release.Version.from_poetry", return_value=Version(major=0,minor=3,patch=0)
1921
) as mock_obj:
2022
yield mock_obj
2123

@@ -40,6 +42,45 @@ def simulate_pass(args, **kwargs):
4042
result = _trigger_release()
4143
assert result == mock_from_poetry.return_value
4244

45+
46+
def test_creates_major_version_tag(self, mock_from_poetry):
47+
def simulate_pass(args, **kwargs):
48+
return self._get_subprocess_run_mock(args)
49+
50+
with patch("subprocess.run", side_effect=simulate_pass) as subprocess_mock:
51+
result = _trigger_release()
52+
assert subprocess_mock.mock_calls == [call(('git', 'remote', 'show', 'origin'), capture_output=True, text=True, check=True),
53+
call(('git', 'checkout', 'main'), capture_output=True, text=True, check=True),
54+
call(('git', 'pull'), capture_output=True, text=True, check=True),
55+
call(('git', 'tag', '--list'), capture_output=True, text=True, check=True),
56+
call(('gh', 'release', 'list'), capture_output=True, text=True, check=True),
57+
call(('git', 'tag', '0.3.0'), capture_output=True, text=True, check=True),
58+
call(('git', 'push', 'origin', '0.3.0'), capture_output=True, text=True, check=True),
59+
call(('git', 'tag', '-f', 'v0'), capture_output=True, text=True, check=True),
60+
call(('git', 'push', '-f', 'origin', 'v0'), capture_output=True, text=True, check=True)]
61+
assert result == mock_from_poetry.return_value
62+
63+
@pytest.fixture
64+
def mock_project_config(self, monkeypatch):
65+
class DummyConfig:
66+
pass
67+
monkeypatch.setattr(noxconfig, "PROJECT_CONFIG", DummyConfig())
68+
69+
def test_not_creates_major_version_tag(self, mock_from_poetry, mock_project_config):
70+
def simulate_pass(args, **kwargs):
71+
return self._get_subprocess_run_mock(args)
72+
73+
with patch("subprocess.run", side_effect=simulate_pass) as subprocess_mock:
74+
result = _trigger_release()
75+
assert subprocess_mock.mock_calls == [call(('git', 'remote', 'show', 'origin'), capture_output=True, text=True, check=True),
76+
call(('git', 'checkout', 'main'), capture_output=True, text=True, check=True),
77+
call(('git', 'pull'), capture_output=True, text=True, check=True),
78+
call(('git', 'tag', '--list'), capture_output=True, text=True, check=True),
79+
call(('gh', 'release', 'list'), capture_output=True, text=True, check=True),
80+
call(('git', 'tag', '0.3.0'), capture_output=True, text=True, check=True),
81+
call(('git', 'push', 'origin', '0.3.0'), capture_output=True, text=True, check=True)]
82+
assert result == mock_from_poetry.return_value
83+
4384
@pytest.mark.parametrize(
4485
"error_cmd",
4586
[

0 commit comments

Comments
 (0)