xref: /aosp_15_r20/external/mesa3d/bin/post_version_test.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker# Copyright © 2019 Intel Corporation
2*61046927SAndroid Build Coastguard Worker
3*61046927SAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person obtaining a copy
4*61046927SAndroid Build Coastguard Worker# of this software and associated documentation files (the "Software"), to deal
5*61046927SAndroid Build Coastguard Worker# in the Software without restriction, including without limitation the rights
6*61046927SAndroid Build Coastguard Worker# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*61046927SAndroid Build Coastguard Worker# copies of the Software, and to permit persons to whom the Software is
8*61046927SAndroid Build Coastguard Worker# furnished to do so, subject to the following conditions:
9*61046927SAndroid Build Coastguard Worker
10*61046927SAndroid Build Coastguard Worker# The above copyright notice and this permission notice shall be included in
11*61046927SAndroid Build Coastguard Worker# all copies or substantial portions of the Software.
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*61046927SAndroid Build Coastguard Worker# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*61046927SAndroid Build Coastguard Worker# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*61046927SAndroid Build Coastguard Worker# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*61046927SAndroid Build Coastguard Worker# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*61046927SAndroid Build Coastguard Worker# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19*61046927SAndroid Build Coastguard Worker# SOFTWARE.
20*61046927SAndroid Build Coastguard Worker
21*61046927SAndroid Build Coastguard Workerfrom unittest import mock
22*61046927SAndroid Build Coastguard Worker
23*61046927SAndroid Build Coastguard Workerimport pytest
24*61046927SAndroid Build Coastguard Worker
25*61046927SAndroid Build Coastguard Workerfrom . import post_version
26*61046927SAndroid Build Coastguard Worker
27*61046927SAndroid Build Coastguard Worker
28*61046927SAndroid Build Coastguard Worker@mock.patch('bin.post_version.subprocess.run', mock.Mock())
29*61046927SAndroid Build Coastguard Workerclass TestUpdateCalendar:
30*61046927SAndroid Build Coastguard Worker
31*61046927SAndroid Build Coastguard Worker    @pytest.fixture(autouse=True)
32*61046927SAndroid Build Coastguard Worker    def mock_sideffects(self) -> None:
33*61046927SAndroid Build Coastguard Worker        """Mock out side effects."""
34*61046927SAndroid Build Coastguard Worker        with mock.patch('bin.post_version.subprocess.run', mock.Mock()), \
35*61046927SAndroid Build Coastguard Worker                mock.patch('bin.post_version.pathlib', mock.MagicMock()):
36*61046927SAndroid Build Coastguard Worker            yield
37*61046927SAndroid Build Coastguard Worker
38*61046927SAndroid Build Coastguard Worker    def test_basic(self):
39*61046927SAndroid Build Coastguard Worker        data = [
40*61046927SAndroid Build Coastguard Worker            ['20.3', '2021-01-13', '20.3.3', 'Dylan Baker', None],
41*61046927SAndroid Build Coastguard Worker            [None,   '2021-01-27', '20.3.4', 'Dylan Baker', None],
42*61046927SAndroid Build Coastguard Worker        ]
43*61046927SAndroid Build Coastguard Worker
44*61046927SAndroid Build Coastguard Worker        m = mock.Mock()
45*61046927SAndroid Build Coastguard Worker        with mock.patch('bin.post_version.csv.reader', mock.Mock(return_value=data.copy())), \
46*61046927SAndroid Build Coastguard Worker                mock.patch('bin.post_version.csv.writer', mock.Mock(return_value=m)):
47*61046927SAndroid Build Coastguard Worker            post_version.update_calendar('20.3.3')
48*61046927SAndroid Build Coastguard Worker
49*61046927SAndroid Build Coastguard Worker            m.writerows.assert_called_with([data[1]])
50*61046927SAndroid Build Coastguard Worker
51*61046927SAndroid Build Coastguard Worker    def test_two_releases(self):
52*61046927SAndroid Build Coastguard Worker        data = [
53*61046927SAndroid Build Coastguard Worker            ['20.3', '2021-01-13', '20.3.3', 'Dylan Baker', None],
54*61046927SAndroid Build Coastguard Worker            [None,   '2021-01-27', '20.3.4', 'Dylan Baker', None],
55*61046927SAndroid Build Coastguard Worker            ['21.0', '2021-01-13', '21.0.0', 'Dylan Baker', None],
56*61046927SAndroid Build Coastguard Worker            [None,   '2021-01-13', '21.0.1', 'Dylan Baker', None],
57*61046927SAndroid Build Coastguard Worker        ]
58*61046927SAndroid Build Coastguard Worker
59*61046927SAndroid Build Coastguard Worker        m = mock.Mock()
60*61046927SAndroid Build Coastguard Worker        with mock.patch('bin.post_version.csv.reader', mock.Mock(return_value=data.copy())), \
61*61046927SAndroid Build Coastguard Worker                mock.patch('bin.post_version.csv.writer', mock.Mock(return_value=m)):
62*61046927SAndroid Build Coastguard Worker            post_version.update_calendar('20.3.3')
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard Worker            d = data.copy()
65*61046927SAndroid Build Coastguard Worker            del d[0]
66*61046927SAndroid Build Coastguard Worker            d[0][0] = '20.3'
67*61046927SAndroid Build Coastguard Worker            m.writerows.assert_called_with(d)
68