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