Skip to content

Commit

Permalink
Fix: Use Version.major instead of .epoch for git log. (#48)
Browse files Browse the repository at this point in the history
* FIx: Use `Version.major` instead of `.epoch` for `git log`.

* Test: Add updated test for `get_log_string`
- Add test to simulate log_string for versions past 1.0.0

* Format: Passes lint tests

* Update tests/test_release_process.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Fix: Separate tests for `1.x.x`

* Test: Add tests for 2.0.0
- Comment some tests.

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
raynelfss and mtreinish authored Jul 30, 2024
1 parent cece9b5 commit dbac6aa
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 24 deletions.
6 changes: 3 additions & 3 deletions qiskit_bot/release_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"


Expand Down
178 changes: 157 additions & 21 deletions tests/test_release_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,30 +839,166 @@ def test_bump_minor_release_from_pending_patch_release_pr(self,

def test_get_log_string(self):
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()
),
)

@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
"""
# 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",
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 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
"""
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 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")
Expand Down

0 comments on commit dbac6aa

Please sign in to comment.