|
1
|
|
|
from datetime import date |
|
2
|
|
|
import shlex |
|
3
|
|
|
import textwrap |
|
4
|
|
|
from pathlib import Path |
|
5
|
|
|
|
|
6
|
|
|
from plumbum.cmd import git |
|
|
|
|
|
|
7
|
|
|
import pytest |
|
8
|
|
|
import responses |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
import changes |
|
11
|
|
|
from changes.commands import stage, publish |
|
12
|
|
|
from .conftest import github_merge_commit, ISSUE_URL, LABEL_URL, PULL_REQUEST_JSON, BUG_LABEL_JSON, RELEASES_URL |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
@pytest.fixture |
|
16
|
|
|
def answer_prompts(mocker): |
|
17
|
|
|
prompt = mocker.patch( |
|
18
|
|
|
'changes.commands.publish.click.confirm', |
|
19
|
|
|
autospec=True, |
|
20
|
|
|
) |
|
21
|
|
|
prompt.side_effect = [ |
|
22
|
|
|
'y' |
|
23
|
|
|
] |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def test_publish_no_staged_release( |
|
27
|
|
|
capsys, |
|
28
|
|
|
configured |
|
29
|
|
|
): |
|
30
|
|
|
changes.initialise() |
|
31
|
|
|
publish.publish() |
|
32
|
|
|
|
|
33
|
|
|
expected_output = textwrap.dedent( |
|
34
|
|
|
"""\ |
|
35
|
|
|
No staged release to publish... |
|
36
|
|
|
""" |
|
37
|
|
|
) |
|
38
|
|
|
out, _ = capsys.readouterr() |
|
39
|
|
|
assert expected_output == out |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
@responses.activate |
|
43
|
|
|
def test_publish( |
|
44
|
|
|
capsys, |
|
45
|
|
|
configured, |
|
46
|
|
|
answer_prompts, |
|
|
|
|
|
|
47
|
|
|
): |
|
48
|
|
|
|
|
49
|
|
|
github_merge_commit(111) |
|
50
|
|
|
responses.add( |
|
51
|
|
|
responses.GET, |
|
52
|
|
|
ISSUE_URL, |
|
53
|
|
|
json=PULL_REQUEST_JSON, |
|
54
|
|
|
status=200, |
|
55
|
|
|
content_type='application/json' |
|
56
|
|
|
) |
|
57
|
|
|
responses.add( |
|
58
|
|
|
responses.GET, |
|
59
|
|
|
LABEL_URL, |
|
60
|
|
|
json=BUG_LABEL_JSON, |
|
61
|
|
|
status=200, |
|
62
|
|
|
content_type='application/json' |
|
63
|
|
|
) |
|
64
|
|
|
responses.add( |
|
65
|
|
|
responses.POST, |
|
66
|
|
|
RELEASES_URL, |
|
67
|
|
|
json={'upload_url': 'foo'}, |
|
68
|
|
|
status=200, |
|
69
|
|
|
content_type='application/json' |
|
70
|
|
|
) |
|
71
|
|
|
|
|
72
|
|
|
changes.initialise() |
|
73
|
|
|
stage.stage( |
|
74
|
|
|
draft=False, |
|
75
|
|
|
release_name='Icarus', |
|
76
|
|
|
release_description='The first flight' |
|
77
|
|
|
) |
|
78
|
|
|
|
|
79
|
|
|
release_notes_path = Path('docs').joinpath('releases').joinpath('0.0.2-2017-11-06-Icarus.md') |
|
|
|
|
|
|
80
|
|
|
assert release_notes_path.exists() |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
publish.publish() |
|
83
|
|
|
|
|
84
|
|
|
pre = textwrap.dedent( |
|
85
|
|
|
"""\ |
|
86
|
|
|
Staging [fix] release for version 0.0.2... |
|
87
|
|
|
Running: bumpversion --verbose --allow-dirty --no-commit --no-tag patch... |
|
|
|
|
|
|
88
|
|
|
Generating Release... |
|
89
|
|
|
Writing release notes to {release_notes_path}... |
|
90
|
|
|
Publishing release 0.0.2... |
|
91
|
|
|
Running: git add version.txt .bumpversion.cfg {release_notes_path}... |
|
92
|
|
|
Running: git commit --message="# 0.0.2 ({release_date}) Icarus |
|
93
|
|
|
""".format( |
|
94
|
|
|
release_notes_path=release_notes_path, |
|
95
|
|
|
release_date=date.today().isoformat(), |
|
96
|
|
|
) |
|
97
|
|
|
).splitlines() |
|
98
|
|
|
|
|
99
|
|
|
expected_release_notes_content = [ |
|
100
|
|
|
'The first flight', |
|
101
|
|
|
'## Bug', |
|
102
|
|
|
' ', |
|
103
|
|
|
'* #111 The title of the pull request', |
|
104
|
|
|
' ', |
|
105
|
|
|
] |
|
106
|
|
|
|
|
107
|
|
|
post = textwrap.dedent( |
|
108
|
|
|
"""\ |
|
109
|
|
|
"... |
|
110
|
|
|
Running: git tag 0.0.2... |
|
111
|
|
|
Running: git push --tags... |
|
112
|
|
|
Creating GitHub Release... |
|
113
|
|
|
Published release 0.0.2... |
|
114
|
|
|
""" |
|
115
|
|
|
).splitlines() |
|
116
|
|
|
|
|
117
|
|
|
out, _ = capsys.readouterr() |
|
118
|
|
|
|
|
119
|
|
|
assert pre + expected_release_notes_content + post == out.splitlines() |
|
120
|
|
|
|
|
121
|
|
|
last_commit = git(shlex.split('show --name-only')) |
|
122
|
|
|
expected_files = [ |
|
123
|
|
|
'version.txt', |
|
124
|
|
|
'.bumpversion.cfg', |
|
125
|
|
|
release_notes_path, |
|
126
|
|
|
] |
|
127
|
|
|
assert [ |
|
128
|
|
|
expected_file |
|
129
|
|
|
for expected_file in expected_files |
|
130
|
|
|
if str(expected_file) in last_commit |
|
131
|
|
|
] |
|
132
|
|
|
|
|
133
|
|
|
assert '0.0.2' in git(shlex.split('tag --list')) |
|
134
|
|
|
|
|
135
|
|
|
assert release_notes_path.exists() |
|
|
|
|
|
|
136
|
|
|
expected_release_notes = [ |
|
137
|
|
|
'# 0.0.2 ({}) Icarus'.format(date.today().isoformat()), |
|
138
|
|
|
'The first flight', |
|
139
|
|
|
'## Bug', |
|
140
|
|
|
' ', |
|
141
|
|
|
'* #111 The title of the pull request', |
|
142
|
|
|
' ', |
|
143
|
|
|
] |
|
144
|
|
|
assert expected_release_notes == release_notes_path.read_text().splitlines() |
|
|
|
|
|
|
145
|
|
|
|
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__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.