1
|
|
|
import shlex |
2
|
|
|
import textwrap |
3
|
|
|
from pathlib import Path |
4
|
|
|
|
5
|
|
|
from plumbum.cmd import git |
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
import responses |
|
|
|
|
8
|
|
|
|
9
|
|
|
from changes.commands import init, stage, publish |
10
|
|
|
from .conftest import github_merge_commit, ISSUE_URL, LABEL_URL, PULL_REQUEST_JSON, BUG_LABEL_JSON |
|
|
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
@pytest.fixture |
14
|
|
|
def answer_prompts(mocker): |
15
|
|
|
prompt = mocker.patch( |
16
|
|
|
'changes.commands.publish.click.confirm', |
17
|
|
|
autospec=True, |
18
|
|
|
) |
19
|
|
|
prompt.side_effect = [ |
20
|
|
|
'y' |
21
|
|
|
] |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
def test_publish_no_staged_release( |
25
|
|
|
capsys, |
26
|
|
|
configured |
27
|
|
|
): |
28
|
|
|
init.init() |
29
|
|
|
publish.publish() |
30
|
|
|
|
31
|
|
|
expected_output = textwrap.dedent( |
32
|
|
|
"""\ |
33
|
|
|
No staged release to publish... |
34
|
|
|
""" |
35
|
|
|
) |
36
|
|
|
out, _ = capsys.readouterr() |
37
|
|
|
assert expected_output == out |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
@responses.activate |
41
|
|
|
def test_publish( |
42
|
|
|
capsys, |
43
|
|
|
configured, |
44
|
|
|
answer_prompts, |
|
|
|
|
45
|
|
|
): |
46
|
|
|
|
47
|
|
|
github_merge_commit(111) |
48
|
|
|
responses.add( |
49
|
|
|
responses.GET, |
50
|
|
|
ISSUE_URL.format('111'), |
51
|
|
|
json=PULL_REQUEST_JSON, |
52
|
|
|
status=200, |
53
|
|
|
content_type='application/json' |
54
|
|
|
) |
55
|
|
|
responses.add( |
56
|
|
|
responses.GET, |
57
|
|
|
LABEL_URL, |
58
|
|
|
json=BUG_LABEL_JSON, |
59
|
|
|
status=200, |
60
|
|
|
content_type='application/json' |
61
|
|
|
) |
62
|
|
|
|
63
|
|
|
init.init() |
64
|
|
|
stage.stage( |
65
|
|
|
draft=False, |
66
|
|
|
release_name='Icarus', |
67
|
|
|
release_description='The first flight' |
68
|
|
|
) |
69
|
|
|
publish.publish() |
70
|
|
|
|
71
|
|
|
release_notes_path = Path('docs').joinpath('releases').joinpath('0.0.2.md') |
72
|
|
|
|
73
|
|
|
pre = textwrap.dedent( |
74
|
|
|
"""\ |
75
|
|
|
Staging [fix] release for version 0.0.2... |
76
|
|
|
Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... |
|
|
|
|
77
|
|
|
Generating Release... |
78
|
|
|
Writing release notes to {release_notes_path}... |
79
|
|
|
Publishing release 0.0.2... |
80
|
|
|
Running: git add version.txt .bumpversion.cfg {release_notes_path}... |
81
|
|
|
Running: git commit --message="# 0.0.2 (2017-10-29) Icarus |
82
|
|
|
""".format( |
83
|
|
|
release_notes_path=release_notes_path, |
84
|
|
|
) |
85
|
|
|
).splitlines() |
86
|
|
|
|
87
|
|
|
expected_release_notes_content = [ |
88
|
|
|
'The first flight', |
89
|
|
|
'## Bug', |
90
|
|
|
' ', |
91
|
|
|
'* #111 The title of the pull request', |
92
|
|
|
' ', |
93
|
|
|
] |
94
|
|
|
|
95
|
|
|
post = textwrap.dedent( |
96
|
|
|
"""\ |
97
|
|
|
"... |
98
|
|
|
Running: git tag 0.0.2... |
99
|
|
|
Running: git push --tags... |
100
|
|
|
Creating GitHub Releases... |
101
|
|
|
Published release 0.0.2... |
102
|
|
|
Verifying release 0.0.2... |
103
|
|
|
👍 Release verified... |
104
|
|
|
""" |
105
|
|
|
).splitlines() |
106
|
|
|
|
107
|
|
|
out, _ = capsys.readouterr() |
108
|
|
|
|
109
|
|
|
assert pre + expected_release_notes_content + post == out.splitlines() |
110
|
|
|
|
111
|
|
|
last_commit = git(shlex.split('show --name-only')) |
112
|
|
|
expected_files = [ |
113
|
|
|
'version.txt', |
114
|
|
|
'.bumpversion.cfg', |
115
|
|
|
release_notes_path, |
116
|
|
|
] |
117
|
|
|
assert [ |
118
|
|
|
expected_file |
119
|
|
|
for expected_file in expected_files |
120
|
|
|
if str(expected_file) in last_commit |
121
|
|
|
] |
122
|
|
|
|
123
|
|
|
# verify tag creation |
124
|
|
|
assert '0.0.2' in git(shlex.split('tag --list')) |
125
|
|
|
|
126
|
|
|
# verify remote pushed |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
# patch releases api call |
130
|
|
|
# patch release api verification call |
131
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.py
files in your module folders. Make sure that you place one file in each sub-folder.