Path: blob/21.2-virgl/bin/gen_release_notes_test.py
4545 views
# Copyright © 2019,2021 Intel Corporation12# Permission is hereby granted, free of charge, to any person obtaining a copy3# of this software and associated documentation files (the "Software"), to deal4# in the Software without restriction, including without limitation the rights5# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6# copies of the Software, and to permit persons to whom the Software is7# furnished to do so, subject to the following conditions:89# The above copyright notice and this permission notice shall be included in10# all copies or substantial portions of the Software.1112# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE18# SOFTWARE.1920import sys21import textwrap22import typing2324import pytest2526# AsyncMock is new in 3.8, so if we're using an older version we need the27# backported version of mock28if sys.version_info >= (3, 8):29from unittest import mock30else:31import mock3233from .gen_release_notes import *343536@pytest.mark.parametrize(37'current, is_point, expected',38[39('19.2.0', True, '19.2.1'),40('19.3.6', True, '19.3.7'),41('20.0.0-rc4', False, '20.0.0'),42])43def test_next_version(current: str, is_point: bool, expected: str) -> None:44assert calculate_next_version(current, is_point) == expected454647@pytest.mark.parametrize(48'current, is_point, expected',49[50('19.3.6', True, '19.3.6'),51('20.0.0-rc4', False, '19.3.0'),52])53def test_previous_version(current: str, is_point: bool, expected: str) -> None:54assert calculate_previous_version(current, is_point) == expected555657@pytest.mark.asyncio58async def test_get_shortlog():59# Certainly not perfect, but it's something60version = '19.2.0'61out = await get_shortlog(version)62assert out636465@pytest.mark.asyncio66async def test_gather_commits():67# Certainly not perfect, but it's something68version = '19.2.0'69out = await gather_commits(version)70assert out717273@pytest.mark.asyncio74@pytest.mark.parametrize(75'content, bugs',76[77# It is important to have the title on a new line, as78# textwrap.dedent wont work otherwise.7980# Test the `Closes: #N` syntax81(82'''\83A commit8485It has a message in it8687Closes: #188''',89['1'],90),9192# Test the Full url93(94'''\95A commit with no body9697Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/345698''',99['3456'],100),101102# Test projects that are not mesa103(104'''\105A commit for libdrm106107Closes: https://gitlab.freedesktop.org/mesa/drm/-/3456108''',109[],110),111(112'''\113A commit for for something else completely114115Closes: https://github.com/Organiztion/project/1234116''',117[],118),119120# Test multiple issues on one line121(122'''\123Fix many bugs124125Closes: #1, #2126''',127['1', '2'],128),129130# Test multiple closes131(132'''\133Fix many bugs134135Closes: #1136Closes: #2137''',138['1', '2'],139),140(141'''\142With long form143144Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3456145Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3457146Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3458147''',148['3456', '3457', '3458'],149),150])151async def test_parse_issues(content: str, bugs: typing.List[str]) -> None:152mock_com = mock.AsyncMock(return_value=(textwrap.dedent(content).encode(), ''))153mock_p = mock.Mock()154mock_p.communicate = mock_com155mock_exec = mock.AsyncMock(return_value=mock_p)156157with mock.patch('bin.gen_release_notes.asyncio.create_subprocess_exec', mock_exec), \158mock.patch('bin.gen_release_notes.gather_commits', mock.AsyncMock(return_value='sha\n')):159ids = await parse_issues('1234 not used')160assert set(ids) == set(bugs)161162163