Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/bin/gen_release_notes_test.py
4545 views
1
# Copyright © 2019,2021 Intel Corporation
2
3
# Permission is hereby granted, free of charge, to any person obtaining a copy
4
# of this software and associated documentation files (the "Software"), to deal
5
# in the Software without restriction, including without limitation the rights
6
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
# copies of the Software, and to permit persons to whom the Software is
8
# furnished to do so, subject to the following conditions:
9
10
# The above copyright notice and this permission notice shall be included in
11
# all copies or substantial portions of the Software.
12
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
# SOFTWARE.
20
21
import sys
22
import textwrap
23
import typing
24
25
import pytest
26
27
# AsyncMock is new in 3.8, so if we're using an older version we need the
28
# backported version of mock
29
if sys.version_info >= (3, 8):
30
from unittest import mock
31
else:
32
import mock
33
34
from .gen_release_notes import *
35
36
37
@pytest.mark.parametrize(
38
'current, is_point, expected',
39
[
40
('19.2.0', True, '19.2.1'),
41
('19.3.6', True, '19.3.7'),
42
('20.0.0-rc4', False, '20.0.0'),
43
])
44
def test_next_version(current: str, is_point: bool, expected: str) -> None:
45
assert calculate_next_version(current, is_point) == expected
46
47
48
@pytest.mark.parametrize(
49
'current, is_point, expected',
50
[
51
('19.3.6', True, '19.3.6'),
52
('20.0.0-rc4', False, '19.3.0'),
53
])
54
def test_previous_version(current: str, is_point: bool, expected: str) -> None:
55
assert calculate_previous_version(current, is_point) == expected
56
57
58
@pytest.mark.asyncio
59
async def test_get_shortlog():
60
# Certainly not perfect, but it's something
61
version = '19.2.0'
62
out = await get_shortlog(version)
63
assert out
64
65
66
@pytest.mark.asyncio
67
async def test_gather_commits():
68
# Certainly not perfect, but it's something
69
version = '19.2.0'
70
out = await gather_commits(version)
71
assert out
72
73
74
@pytest.mark.asyncio
75
@pytest.mark.parametrize(
76
'content, bugs',
77
[
78
# It is important to have the title on a new line, as
79
# textwrap.dedent wont work otherwise.
80
81
# Test the `Closes: #N` syntax
82
(
83
'''\
84
A commit
85
86
It has a message in it
87
88
Closes: #1
89
''',
90
['1'],
91
),
92
93
# Test the Full url
94
(
95
'''\
96
A commit with no body
97
98
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3456
99
''',
100
['3456'],
101
),
102
103
# Test projects that are not mesa
104
(
105
'''\
106
A commit for libdrm
107
108
Closes: https://gitlab.freedesktop.org/mesa/drm/-/3456
109
''',
110
[],
111
),
112
(
113
'''\
114
A commit for for something else completely
115
116
Closes: https://github.com/Organiztion/project/1234
117
''',
118
[],
119
),
120
121
# Test multiple issues on one line
122
(
123
'''\
124
Fix many bugs
125
126
Closes: #1, #2
127
''',
128
['1', '2'],
129
),
130
131
# Test multiple closes
132
(
133
'''\
134
Fix many bugs
135
136
Closes: #1
137
Closes: #2
138
''',
139
['1', '2'],
140
),
141
(
142
'''\
143
With long form
144
145
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3456
146
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3457
147
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3458
148
''',
149
['3456', '3457', '3458'],
150
),
151
])
152
async def test_parse_issues(content: str, bugs: typing.List[str]) -> None:
153
mock_com = mock.AsyncMock(return_value=(textwrap.dedent(content).encode(), ''))
154
mock_p = mock.Mock()
155
mock_p.communicate = mock_com
156
mock_exec = mock.AsyncMock(return_value=mock_p)
157
158
with mock.patch('bin.gen_release_notes.asyncio.create_subprocess_exec', mock_exec), \
159
mock.patch('bin.gen_release_notes.gather_commits', mock.AsyncMock(return_value='sha\n')):
160
ids = await parse_issues('1234 not used')
161
assert set(ids) == set(bugs)
162
163