9
9
from pathlib import Path
10
10
from subprocess import CalledProcessError
11
11
from unittest .mock import call
12
- from unittest .mock import MagicMock
13
- from unittest .mock import patch
14
- from unittest .mock import PropertyMock
15
12
16
13
import pytest
17
- from pytest import fixture
18
14
19
15
from jupyter_releaser import changelog
20
- from jupyter_releaser import cli
21
- from jupyter_releaser import npm
22
- from jupyter_releaser import python
23
16
from jupyter_releaser import util
24
17
from jupyter_releaser .tests .util import CHANGELOG_ENTRY
25
- from jupyter_releaser .tests .util import create_npm_package
26
- from jupyter_releaser .tests .util import create_python_package
27
18
from jupyter_releaser .tests .util import get_log
28
19
from jupyter_releaser .tests .util import HTML_URL
29
20
from jupyter_releaser .tests .util import mock_changelog_entry
30
21
from jupyter_releaser .tests .util import MockHTTPResponse
31
22
from jupyter_releaser .tests .util import MockRequestResponse
32
23
from jupyter_releaser .tests .util import PR_ENTRY
33
24
from jupyter_releaser .tests .util import REPO_DATA
34
- from jupyter_releaser .tests .util import TOML_CONFIG
35
25
from jupyter_releaser .tests .util import VERSION_SPEC
36
26
from jupyter_releaser .util import bump_version
37
27
from jupyter_releaser .util import normalize_path
@@ -58,6 +48,38 @@ def test_prep_git_pr(py_package, runner):
58
48
assert util .get_branch () == "foo" , util .get_branch ()
59
49
60
50
51
+ def test_prep_git_tag (py_package , runner ):
52
+ tag = "v0.1"
53
+ util .run (f"git tag { tag } " )
54
+ result = runner (
55
+ ["prep-git" , "--git-url" , py_package ],
56
+ env = dict (GITHUB_ACTIONS = "" , RH_REF = f"refs/tags/{ tag } " , RH_BRANCH = tag ),
57
+ )
58
+
59
+ log = get_log ()
60
+ assert "before-prep-git" not in log
61
+ assert "after-prep-git" in log
62
+
63
+ os .chdir (util .CHECKOUT_NAME )
64
+ assert util .get_branch () == tag , util .get_branch ()
65
+
66
+
67
+ def test_prep_git_slashes (py_package , runner ):
68
+ branch = "a/b/c"
69
+ util .run (f"git checkout -b { branch } foo" )
70
+ result = runner (
71
+ ["prep-git" , "--git-url" , py_package ],
72
+ env = dict (GITHUB_ACTIONS = "" , RH_REF = f"refs/heads/{ branch } " , RH_BRANCH = branch ),
73
+ )
74
+
75
+ log = get_log ()
76
+ assert "before-prep-git" not in log
77
+ assert "after-prep-git" in log
78
+
79
+ os .chdir (util .CHECKOUT_NAME )
80
+ assert util .get_branch () == branch , util .get_branch ()
81
+
82
+
61
83
def test_prep_git_full (py_package , tmp_path , mocker , runner ):
62
84
"""Full GitHub Actions simulation (Push)"""
63
85
@@ -239,6 +261,37 @@ def test_build_changelog_backport(py_package, mocker, runner, open_mock):
239
261
run ("pre-commit run -a" )
240
262
241
263
264
+ def test_build_changelog_slashes (py_package , mocker , runner , open_mock ):
265
+ branch = "a/b/c"
266
+ util .run (f"git checkout -b { branch } foo" )
267
+ env = dict (RH_REF = f"refs/heads/{ branch } " , RH_BRANCH = branch )
268
+ run ("pre-commit run -a" )
269
+
270
+ changelog_path = "CHANGELOG.md"
271
+
272
+ runner (["prep-git" , "--git-url" , py_package ], env = env )
273
+ runner (["bump-version" , "--version-spec" , VERSION_SPEC ], env = env )
274
+
275
+ mocked_gen = mocker .patch ("jupyter_releaser.changelog.generate_activity_md" )
276
+ mocked_gen .return_value = CHANGELOG_ENTRY
277
+ runner (["build-changelog" , "--changelog-path" , changelog_path ], env = env )
278
+
279
+ log = get_log ()
280
+ assert "before-build-changelog" in log
281
+ assert "after-build-changelog" in log
282
+
283
+ changelog_path = Path (util .CHECKOUT_NAME ) / "CHANGELOG.md"
284
+ text = changelog_path .read_text (encoding = "utf-8" )
285
+ assert changelog .START_MARKER in text
286
+ assert changelog .END_MARKER in text
287
+ assert PR_ENTRY in text
288
+
289
+ assert len (re .findall (changelog .START_MARKER , text )) == 1
290
+ assert len (re .findall (changelog .END_MARKER , text )) == 1
291
+
292
+ run ("pre-commit run -a" )
293
+
294
+
242
295
def test_draft_changelog_full (py_package , mocker , runner , open_mock , git_prep ):
243
296
mock_changelog_entry (py_package , runner , mocker )
244
297
runner (["draft-changelog" , "--version-spec" , VERSION_SPEC ])
@@ -476,7 +529,7 @@ def test_extract_dist_py(py_package, runner, mocker, open_mock, tmp_path, git_pr
476
529
shutil .move (f"{ util .CHECKOUT_NAME } /dist" , "staging" )
477
530
478
531
def helper (path , ** kwargs ):
479
- return MockRequestResponse (f"staging/dist/{ path } " )
532
+ return MockRequestResponse (f"{ py_package } / staging/dist/{ path } " )
480
533
481
534
get_mock = mocker .patch ("requests.get" , side_effect = helper )
482
535
@@ -519,7 +572,7 @@ def test_extract_dist_npm(npm_dist, runner, mocker, open_mock, tmp_path):
519
572
shutil .move (f"{ util .CHECKOUT_NAME } /dist" , "staging" )
520
573
521
574
def helper (path , ** kwargs ):
522
- return MockRequestResponse (f"staging/dist/{ path } " )
575
+ return MockRequestResponse (f"{ npm_dist } / staging/dist/{ path } " )
523
576
524
577
get_mock = mocker .patch ("requests.get" , side_effect = helper )
525
578
0 commit comments