1# Copyright © 2019 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 21from unittest import mock 22 23import pytest 24 25from . import post_version 26 27 28@mock.patch('bin.post_version.subprocess.run', mock.Mock()) 29class TestUpdateCalendar: 30 31 @pytest.fixture(autouse=True) 32 def mock_sideffects(self) -> None: 33 """Mock out side effects.""" 34 with mock.patch('bin.post_version.subprocess.run', mock.Mock()), \ 35 mock.patch('bin.post_version.pathlib', mock.MagicMock()): 36 yield 37 38 def test_basic(self): 39 data = [ 40 ['20.3', '2021-01-13', '20.3.3', 'Dylan Baker', None], 41 [None, '2021-01-27', '20.3.4', 'Dylan Baker', None], 42 ] 43 44 m = mock.Mock() 45 with mock.patch('bin.post_version.csv.reader', mock.Mock(return_value=data.copy())), \ 46 mock.patch('bin.post_version.csv.writer', mock.Mock(return_value=m)): 47 post_version.update_calendar('20.3.3') 48 49 m.writerows.assert_called_with([data[1]]) 50 51 def test_two_releases(self): 52 data = [ 53 ['20.3', '2021-01-13', '20.3.3', 'Dylan Baker', None], 54 [None, '2021-01-27', '20.3.4', 'Dylan Baker', None], 55 ['21.0', '2021-01-13', '21.0.0', 'Dylan Baker', None], 56 [None, '2021-01-13', '21.0.1', 'Dylan Baker', None], 57 ] 58 59 m = mock.Mock() 60 with mock.patch('bin.post_version.csv.reader', mock.Mock(return_value=data.copy())), \ 61 mock.patch('bin.post_version.csv.writer', mock.Mock(return_value=m)): 62 post_version.update_calendar('20.3.3') 63 64 d = data.copy() 65 del d[0] 66 d[0][0] = '20.3' 67 m.writerows.assert_called_with(d) 68