From 0b58bf131c37cc4b3e8bc3f3e252cd7f7d4b081e Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Mon, 29 Jul 2024 16:35:52 -0400 Subject: [PATCH 1/6] FIx: Use `Version.major` instead of `.epoch` for `git log`. --- qiskit_bot/release_process.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qiskit_bot/release_process.py b/qiskit_bot/release_process.py index 06afee7..3d17c22 100644 --- a/qiskit_bot/release_process.py +++ b/qiskit_bot/release_process.py @@ -226,7 +226,7 @@ def _get_log_string(version_obj, version_number, repo): # If a patch release log between 0.A.X..0.A.X-1 elif version_obj.micro > 0: old_version = ( - f"{version_obj.epoch}.{version_obj.minor}." + f"{version_obj.major}.{version_obj.minor}." f"{version_obj.micro - 1}" ) # If a major version log between X.0.0..x-1.y.z @@ -240,9 +240,9 @@ def _get_log_string(version_obj, version_number, repo): if tag_version.major == previous_major: old_version = tag break - # If a minor release log between 0.X.0..0.X-1.0 + # If a minor release log between Y.X.0..Y.X-1.0 else: - old_version = f"{version_obj.epoch}.{version_obj.minor - 1}.0" + old_version = f"{version_obj.major}.{version_obj.minor - 1}.0" return f"{version_number}...{old_version}" From d47fba0778822ad26168b7cb910a5305605d1b8a Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Tue, 30 Jul 2024 13:51:31 -0400 Subject: [PATCH 2/6] Test: Add updated test for `get_log_string` - Add test to simulate log_string for versions past 1.0.0 --- tests/test_release_process.py | 93 ++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/tests/test_release_process.py b/tests/test_release_process.py index fd7072c..74c29c9 100644 --- a/tests/test_release_process.py +++ b/tests/test_release_process.py @@ -837,32 +837,81 @@ def test_bump_minor_release_from_pending_patch_release_pr(self, existing_pull_mock.edit.assert_called_once_with( body='Fake old body\nqiskit-terra==0.16.0') - def test_get_log_string(self): + @unittest.mock.patch.object(release_process, 'git') + def test_get_log_string(self, git_mock): version_obj = parse("0.10.2") - self.assertEqual('0.10.2...0.10.1', - release_process._get_log_string( - version_obj, - "0.10.2", - unittest.mock.MagicMock() - )) + self.assertEqual( + "0.10.2...0.10.1", + release_process._get_log_string( + version_obj, "0.10.2", unittest.mock.MagicMock() + ), + ) version_obj = parse("0.3.0") - self.assertEqual('0.3.0...0.2.0', - release_process._get_log_string( - version_obj, - "0.3.0", - unittest.mock.MagicMock())) + self.assertEqual( + "0.3.0...0.2.0", + release_process._get_log_string( + version_obj, "0.3.0", unittest.mock.MagicMock() + ), + ) version_obj = parse("0.3.25") - self.assertEqual('0.3.25...0.3.24', - release_process._get_log_string( - version_obj, - "0.3.25", - unittest.mock.MagicMock())) + self.assertEqual( + "0.3.25...0.3.24", + release_process._get_log_string( + version_obj, "0.3.25", unittest.mock.MagicMock() + ), + ) version_obj = parse("0.25.0") - self.assertEqual('0.25.0...0.24.0', - release_process._get_log_string( - version_obj, - "0.25.0", - unittest.mock.MagicMock())) + self.assertEqual( + "0.25.0...0.24.0", + release_process._get_log_string( + version_obj, "0.25.0", unittest.mock.MagicMock() + ), + ) + # Tests for >= 1.x.x + self.useFixture( + fake_meta.FakeMetaRepo(self.temp_dir, "1.1.0", terra_version="1.1.1") + ) + # Mock tags for 0.45-1.1.1 + git_mock.get_tags.return_value = """0.46.2 + 1.1.1 + 0.46.2 + 1.1.1 + 1.1.0 + 1.1.0rc1 + 0.46.1 + 1.0.2 + 1.0.1 + 1.0.0 + 1.0.0rc1 + 0.46.0 + 0.45.3 + 0.45.2 + 1.0.0b1 + 0.45.1 + 0.45.0 + """ + mock_repo = unittest.mock.MagicMock() + mock_repo.name = "qiskit" + mock_repo.repo_name = "Qiskit/qiskit" + mock_repo.repo_config = {"optional_package": False} + mock_repo.local_path = self.temp_dir.path + print(mock_repo.local_path) + print(mock_repo.gh_repo.get_tags()) + version_obj = parse("1.0.0") + self.assertEqual( + "1.0.0...0.46.2", + release_process._get_log_string(version_obj, "1.0.0", mock_repo), + ) + version_obj = parse("1.1.0") + self.assertEqual( + "1.1.0...1.0.0", + release_process._get_log_string(version_obj, "1.1.0", mock_repo), + ) + version_obj = parse("1.1.1") + self.assertEqual( + "1.1.1...1.1.0", + release_process._get_log_string(version_obj, "1.1.1", mock_repo), + ) def test_get_log_string_prerelease(self): version_obj = parse("0.25.0rc1") From f16ca2e4f893e8917bc57032e99b3504b45e90f3 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Tue, 30 Jul 2024 13:55:20 -0400 Subject: [PATCH 3/6] Format: Passes lint tests --- tests/test_release_process.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_release_process.py b/tests/test_release_process.py index 74c29c9..b8a25b6 100644 --- a/tests/test_release_process.py +++ b/tests/test_release_process.py @@ -869,7 +869,8 @@ def test_get_log_string(self, git_mock): ) # Tests for >= 1.x.x self.useFixture( - fake_meta.FakeMetaRepo(self.temp_dir, "1.1.0", terra_version="1.1.1") + fake_meta.FakeMetaRepo(self.temp_dir, "1.1.0", + terra_version="1.1.1") ) # Mock tags for 0.45-1.1.1 git_mock.get_tags.return_value = """0.46.2 From 4bcfafc28cb9f757452e9dac12bced4e1b09c462 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> Date: Tue, 30 Jul 2024 13:56:29 -0400 Subject: [PATCH 4/6] Update tests/test_release_process.py Co-authored-by: Matthew Treinish --- tests/test_release_process.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_release_process.py b/tests/test_release_process.py index b8a25b6..19af07d 100644 --- a/tests/test_release_process.py +++ b/tests/test_release_process.py @@ -896,8 +896,6 @@ def test_get_log_string(self, git_mock): mock_repo.repo_name = "Qiskit/qiskit" mock_repo.repo_config = {"optional_package": False} mock_repo.local_path = self.temp_dir.path - print(mock_repo.local_path) - print(mock_repo.gh_repo.get_tags()) version_obj = parse("1.0.0") self.assertEqual( "1.0.0...0.46.2", From cb4558b527a7a90ab4d4890d34bae65d5d5d8f73 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Tue, 30 Jul 2024 14:20:48 -0400 Subject: [PATCH 5/6] Fix: Separate tests for `1.x.x` --- tests/test_release_process.py | 70 +++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/tests/test_release_process.py b/tests/test_release_process.py index 19af07d..8425628 100644 --- a/tests/test_release_process.py +++ b/tests/test_release_process.py @@ -837,8 +837,7 @@ def test_bump_minor_release_from_pending_patch_release_pr(self, existing_pull_mock.edit.assert_called_once_with( body='Fake old body\nqiskit-terra==0.16.0') - @unittest.mock.patch.object(release_process, 'git') - def test_get_log_string(self, git_mock): + def test_get_log_string(self): version_obj = parse("0.10.2") self.assertEqual( "0.10.2...0.10.1", @@ -867,30 +866,61 @@ def test_get_log_string(self, git_mock): version_obj, "0.25.0", unittest.mock.MagicMock() ), ) + + @unittest.mock.patch.object(release_process, 'git') + def test_get_log_string_major_1_0_0(self, git_mock): + # Tests for >= 1.x.x + self.useFixture( + fake_meta.FakeMetaRepo(self.temp_dir, "1.0.0", + terra_version="1.0.0") + ) + # Mock tags for 1.0.0-0.45.0 + git_mock.get_tags.return_value = """1.0.0 +1.0.0rc1 +0.46.0 +0.45.3 +0.45.2 +1.0.0b1 +0.45.1 +0.45.0 +""" + mock_repo = unittest.mock.MagicMock() + mock_repo.name = "qiskit" + mock_repo.repo_name = "Qiskit/qiskit" + mock_repo.repo_config = {"optional_package": False} + mock_repo.local_path = self.temp_dir.path + version_obj = parse("1.0.0") + self.assertEqual( + "1.0.0...0.46.0", + release_process._get_log_string(version_obj, "1.0.0", mock_repo), + ) + + @unittest.mock.patch.object(release_process, 'git') + def test_get_log_string_post_1_x_x(self, git_mock): # Tests for >= 1.x.x self.useFixture( fake_meta.FakeMetaRepo(self.temp_dir, "1.1.0", terra_version="1.1.1") ) - # Mock tags for 0.45-1.1.1 + # Mock tags for 1.1.1-0.45.0 git_mock.get_tags.return_value = """0.46.2 - 1.1.1 - 0.46.2 - 1.1.1 - 1.1.0 - 1.1.0rc1 - 0.46.1 - 1.0.2 - 1.0.1 - 1.0.0 - 1.0.0rc1 - 0.46.0 - 0.45.3 - 0.45.2 - 1.0.0b1 - 0.45.1 - 0.45.0 - """ +1.1.1 +0.46.2 +1.1.1 +1.1.0 +1.1.0rc1 +0.46.1 +1.0.2 +1.0.1 +1.0.0 +1.0.0rc1 +0.46.0 +0.45.3 +0.45.2 +1.0.0b1 +0.45.1 +0.45.0 +""" mock_repo = unittest.mock.MagicMock() mock_repo.name = "qiskit" mock_repo.repo_name = "Qiskit/qiskit" From 1fd91acbb2d4b0b35b8f1771b811481cf500df19 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Tue, 30 Jul 2024 17:23:25 -0400 Subject: [PATCH 6/6] Test: Add tests for 2.0.0 - Comment some tests. --- tests/test_release_process.py | 68 ++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/tests/test_release_process.py b/tests/test_release_process.py index 8425628..e822677 100644 --- a/tests/test_release_process.py +++ b/tests/test_release_process.py @@ -884,11 +884,14 @@ def test_get_log_string_major_1_0_0(self, git_mock): 0.45.1 0.45.0 """ + # Prepare mock repo mock_repo = unittest.mock.MagicMock() mock_repo.name = "qiskit" mock_repo.repo_name = "Qiskit/qiskit" mock_repo.repo_config = {"optional_package": False} mock_repo.local_path = self.temp_dir.path + + # Test for major release 1.0.0 version_obj = parse("1.0.0") self.assertEqual( "1.0.0...0.46.0", @@ -926,22 +929,77 @@ def test_get_log_string_post_1_x_x(self, git_mock): mock_repo.repo_name = "Qiskit/qiskit" mock_repo.repo_config = {"optional_package": False} mock_repo.local_path = self.temp_dir.path - version_obj = parse("1.0.0") - self.assertEqual( - "1.0.0...0.46.2", - release_process._get_log_string(version_obj, "1.0.0", mock_repo), - ) + + # Test minor release 1.1.0 version_obj = parse("1.1.0") self.assertEqual( "1.1.0...1.0.0", release_process._get_log_string(version_obj, "1.1.0", mock_repo), ) + + # Test bugfix release 1.1.1 version_obj = parse("1.1.1") self.assertEqual( "1.1.1...1.1.0", release_process._get_log_string(version_obj, "1.1.1", mock_repo), ) + @unittest.mock.patch.object(release_process, 'git') + def test_get_log_string_post_2_x_x(self, git_mock): + # Tests for >= 2.x.x + self.useFixture( + fake_meta.FakeMetaRepo(self.temp_dir, "1.1.0", + terra_version="1.1.1") + ) + # Mock tags for 2.0.0rc1-1.3.0rc1 + git_mock.get_tags.return_value = """2.0.0 +2.0.0.rc1 +1.4.0 +1.4.0rc1 +1.3.2 +1.3.1 +1.3.0 +1.2.2 +1.3.0rc1 +""" + # Prepare mock repository + mock_repo = unittest.mock.MagicMock() + mock_repo.name = "qiskit" + mock_repo.repo_name = "Qiskit/qiskit" + mock_repo.repo_config = {"optional_package": False} + mock_repo.local_path = self.temp_dir.path + + # Test for release candidate 1.4.0rc1 + version_obj = parse("1.4.0rc1") + self.assertEqual( + "1.4.0rc1...1.3.0", + release_process._get_log_string(version_obj, "1.4.0rc1", + mock_repo), + ) + + # Test for minor release 1.4.0 + version_obj = parse("1.4.0") + self.assertEqual( + "1.4.0...1.3.0", + release_process._get_log_string(version_obj, "1.4.0", mock_repo), + ) + + # Test for major release candidate 2.0.0rc1 + version_obj = parse("2.0.0rc1") + self.assertEqual( + "2.0.0rc1...1.4.0", + release_process._get_log_string(version_obj, "2.0.0rc1", + mock_repo), + ) + + # Test for major release 2.0.0 + version_obj = parse("2.0.0") + self.assertEqual( + "2.0.0...1.4.0", + release_process._get_log_string(version_obj, "2.0.0", + mock_repo), + ) + def test_get_log_string_prerelease(self): version_obj = parse("0.25.0rc1") self.assertEqual('0.25.0rc1...0.24.0',