Completed
Push — master ( f0fc46...b442ce )
by Gonzalo
9s
created

test_argument_parser_valid()   A

Complexity

Conditions 3

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Copyright (c) The Spyder Development Team
4
#
5
# Licensed under the terms of the MIT License
6
# (See LICENSE.txt for details)
7
# -----------------------------------------------------------------------------
8
"""Tests changelog output."""
9
10
# Standard library imports
11
import os
12
import sys
13
import tempfile
14
15
# Third party imports
16
from mock import patch
17
import pytest
18
19
# Local imports
20
from loghub.main import create_changelog, parse_arguments
21
22
REPO = 'spyder-ide/loghub'
23
TEST_TOKEN = os.environ.get('TEST_TOKEN', '').replace('x', '')
24
TEST_USER = os.environ.get('TEST_USER', '').replace('x', '')
25
TEST_PASS = os.environ.get('TEST_CODE', '').replace('x', '')
26
TEST_MILESTONE = 'test-milestone'
27
TEST_TAG = 'v0.1.2'
28
NOT_ON_CI = os.environ.get('CIRCLECI') != 'true'
29
30
31
# --- Tests
32
# -----------------------------------------------------------------------------
33
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
34
def test_changelog():
35
    log = create_changelog(
36
        repo=REPO,
37
        token=TEST_TOKEN,
38
        milestone=TEST_MILESTONE,
39
        branch='master',
40
        output_format='changelog')
41
    expected = '''## Version <RELEASE_VERSION> (2016-12-05)
42
43
### Issues Closed
44
45
* [Issue 26](https://github.com/spyder-ide/loghub/issues/26) - Test number 2
46
* [Issue 24](https://github.com/spyder-ide/loghub/issues/24) - Issue test
47
48
In this release 2 issues were closed.
49
50
### Pull Requests Merged
51
52
* [PR 25](https://github.com/spyder-ide/loghub/pull/25) - PR: Add tests folder
53
54
In this release 1 pull request was closed.
55
'''
56
    print([log])
57
    print([expected])
58
    assert log == expected
59
60
61
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
62
def test_changelog_release():
63
    log = create_changelog(
64
        repo=REPO,
65
        token=TEST_TOKEN,
66
        milestone=TEST_MILESTONE,
67
        branch='master',
68
        output_format='release')
69
    expected = '''## Version <RELEASE_VERSION> (2016-12-05)
70
71
### Issues Closed
72
73
* Issue #26 - Test number 2
74
* Issue #24 - Issue test
75
76
In this release 2 issues were closed.
77
78
### Pull Requests Merged
79
80
* PR #25 - PR: Add tests folder
81
82
In this release 1 pull request was closed.
83
'''
84
    print([log])
85
    print([expected])
86
    assert log == expected
87
88
89
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
90
def test_changelog_release_branch():
91
    log = create_changelog(
92
        repo=REPO,
93
        token=TEST_TOKEN,
94
        milestone=TEST_MILESTONE,
95
        branch='test-branch',
96
        output_format='release')
97
    expected = '''## Version <RELEASE_VERSION> (2016-12-05)
98
99
### Issues Closed
100
101
* Issue #26 - Test number 2
102
* Issue #24 - Issue test
103
104
In this release 2 issues were closed.
105
106
### Pull Requests Merged
107
108
* PR #33 - PR: Test change
109
110
In this release 1 pull request was closed.
111
'''
112
    print([log])
113
    print([expected])
114
    assert log == expected
115
116
117
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
118
def test_changelog_release_groups():
119
    issue_label_groups = [{'label': 'type:bug', 'name': 'Bugs fixed'}]
120
    log = create_changelog(
121
        repo=REPO,
122
        token=TEST_TOKEN,
123
        milestone=TEST_MILESTONE,
124
        branch='test-branch',
125
        output_format='release',
126
        issue_label_groups=issue_label_groups)
127
    expected = '''## Version <RELEASE_VERSION> (2016-12-05)
128
129
### Issues Closed
130
131
#### Bugs fixed
132
133
* [Issue 26](https://github.com/spyder-ide/loghub/issues/26) - Test number 2
134
135
In this release 1 issue was closed.
136
137
### Pull Requests Merged
138
139
* [PR 33](https://github.com/spyder-ide/loghub/pull/33) - PR: Test change
140
141
In this release 1 pull request was closed.
142
'''
143
    print([log])
144
    print([expected])
145
    assert log == expected
146
147
148
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
149
def test_changelog_template():
150
    template = '''{%   for i in issues -%}
151
* Issue #{{ i['number'] }} - {{ i['title'] }}
152
{%   endfor %}'''
153
    desc, path = tempfile.mkstemp()
154
    with open(path, 'w') as f:
155
        f.write(template)
156
157
    log = create_changelog(
158
        repo=REPO,
159
        token=TEST_TOKEN,
160
        milestone=TEST_MILESTONE,
161
        template_file=path)
162
    expected = '* Issue #26 - Test number 2\n* Issue #24 - Issue test\n'
163
    print([log])
164
    print([expected])
165
    assert log == expected
166
167
168
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
169
def test_argument_parser_invalid():
170
    args = ['prog']
171
    with pytest.raises(SystemExit):
172
        with patch.object(sys, 'argv', args):
173
            parse_arguments(skip=True)
174
175
176
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
177
def test_argument_parser_valid():
178
    args = ['prog', 'spyder-ide/loghub', '-ilg', 'type:bug', 'Bugs fixed']
179
    with patch.object(sys, 'argv', args):
180
        options = parse_arguments()
181
    assert options.issue_label_groups == [['type:bug', 'Bugs fixed']]
182