Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Aug 8, 2024
1 parent 4e786da commit 1fb9b78
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
26 changes: 13 additions & 13 deletions bert_e/tests/test_bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def initialize_git_repo(repo, username, usermail):
create_branch(repo, 'development/' + major_minor,
'stabilization/' + full_version, file_=True,
do_push=False)
create_branch(repo, f'development/{major}', f'development/{major_minor}',
create_branch(repo, f'development/{major}',
f'development/{major_minor}',
file_=True, do_push=False)
if major != 6 and major != 10:
repo.cmd('git tag %s.%s.%s', major, minor, micro - 1)
Expand Down Expand Up @@ -725,7 +726,6 @@ def test_major_development_branch(self):
})
self.finalize_cascade(branches, tags, destination, fixver)


def test_retry_handler(self):
class DummyError(Exception):
pass
Expand Down Expand Up @@ -1530,7 +1530,8 @@ def test_merge_without_integration_prs(self):
for branch in integration_branches[:-1]:
sha = self.gitrepo.cmd(f'git rev-parse origin/{branch}').rstrip()
self.set_build_status(sha, 'SUCCESSFUL')
sha1_w_10 = self.gitrepo.cmd(f'git rev-parse origin/{integration_branches[-1]}').rstrip()
sha1_w_10 = self.gitrepo.cmd(
f'git rev-parse origin/{integration_branches[-1]}').rstrip()
self.set_build_status(sha1=sha1_w_10, state='INPROGRESS')
if self.args.git_host == 'github':
pr.add_comment('@%s approve' % (self.args.robot_username))
Expand Down Expand Up @@ -4421,7 +4422,7 @@ def test_stabilization_and_dev_branch_addition(self):
'development/5.1 stabilization/5.1.4')

if not self.args.disable_queues:
self.gitrepo.cmd('git push origin :q/4.3 :q/4 :q/5 :q/10.0 :q/10 ')
self.gitrepo.cmd('git push origin :q/4.3 :q/4 :q/5 :q/10.0 :q/10')

with self.assertRaises(exns.BranchHistoryMismatch):
self.handle(pr.id, options=self.bypass_all, backtrace=True)
Expand Down Expand Up @@ -4877,13 +4878,14 @@ def test_set_bot_status(self):
self.handle(pr.id, settings=settings, options=self.bypass_all)

def test_dev_major_only(self):
"""Test Bert-E's capability to handle a gitwaterflow with a development/x branch."""
"""Test Bert-E's capability to handle a development/x branch."""
# create a development/4 branch
pr = self.create_pr('bugfix/TEST-01', 'development/4.3')
self.handle(pr.id, options=self.bypass_all)
pr = self.create_pr('bugfix/TEST-02', 'stabilization/4.3.18')
self.handle(pr.id, options=self.bypass_all)


class TestQueueing(RepositoryTests):
"""Tests which validate all things related to the merge queue.
Expand Down Expand Up @@ -5656,9 +5658,8 @@ def test_system_nominal_case(self):
self.gitrepo.cmd('git add abc')
self.gitrepo.cmd('git commit -m "add new file"')
self.gitrepo.cmd('git push origin')
sha1_w_10_0 = self.gitrepo \
.cmd('git rev-parse w/10.0/bugfix/TEST-00001') \
.rstrip()
sha1_w_10_0 = self.gitrepo.cmd(
'git rev-parse w/10.0/bugfix/TEST-00001').rstrip()

with self.assertRaises(exns.Queued):
self.handle(pr.id, options=self.bypass_all, backtrace=True)
Expand All @@ -5668,9 +5669,8 @@ def test_system_nominal_case(self):
self.gitrepo.cmd('git fetch')
self.gitrepo.cmd('git checkout w/10/bugfix/TEST-00001')
self.gitrepo.cmd('git pull')
sha1_w_10 = self.gitrepo \
.cmd('git rev-parse w/10/bugfix/TEST-00001') \
.rstrip()
sha1_w_10 = self.gitrepo.cmd(
'git rev-parse w/10/bugfix/TEST-00001').rstrip()

# check expected branches exist
self.gitrepo.cmd('git fetch --prune')
Expand Down Expand Up @@ -7390,7 +7390,7 @@ def test_job_force_merge_queues(self):
self.assertEqual(sha1_q_10_0, sha1_dev_10_0)

def test_job_force_merge_queues_with_hotfix(self):
self.init_berte(options=self.bypass_all, skip_queue_when_not_needed=True)
self.init_berte(options=self.bypass_all)

# When queues are disabled, Bert-E should respond with 'NotMyJob'
self.process_job(
Expand Down Expand Up @@ -7485,7 +7485,7 @@ def test_job_delete_queues(self):
self.assertTrue(self.berte.task_queue.empty())

def test_job_delete_queues_with_hotfix(self):
self.init_berte(options=self.bypass_all, skip_queue_when_not_needed=True)
self.init_berte(options=self.bypass_all)

# When queues are disabled, Bert-E should respond with 'NotMyJob'
self.process_job(
Expand Down
10 changes: 8 additions & 2 deletions bert_e/tests/unit/test_sorted.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

from functools import cmp_to_key
from collections import OrderedDict
from bert_e.workflow.gitwaterflow.branches import DevelopmentBranch, StabilizationBranch, HotfixBranch, compare_branches
from bert_e.workflow.gitwaterflow.branches import (
DevelopmentBranch,
StabilizationBranch,
HotfixBranch,
compare_branches
)


def test_sorted_with_branches():
Expand All @@ -27,5 +32,6 @@ def test_sorted_with_branches():
HotfixBranch: None,
}

sorted_branches = OrderedDict(sorted(branches.items(), key=cmp_to_key(compare_branches)))
sorted_branches = OrderedDict(
sorted(branches.items(), key=cmp_to_key(compare_branches)))
assert list(sorted_branches.keys()) == [(1, 0), (1, 1), (1, None), (2, 0)]
47 changes: 31 additions & 16 deletions bert_e/workflow/gitwaterflow/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@

LOG = logging.getLogger(__name__)


def compare_branches(branch1, branch2):
"""This function will compare branches based on their major and minor version.
"""Compare GitWaterflow branches for sorting.
Important to note that when a branch has a minor version as None, it will be considered
as the latest version.
Important to note that when a branch has a minor version as None,
it will be considered as the latest version.
"""
# need to set the major and minor version
# branch1[0] and branch2[0] is a tuple which can be (major, minor) or (major, minor, micro)

major1, minor1 = branch1[0][:2]
major2, minor2 = branch2[0][:2]
Expand Down Expand Up @@ -187,9 +186,11 @@ def __lt__(self, other):
if self.major != other.major:
return self.major < other.major
if self.minor is None:
return False # development/<major> is greater than development/<major>.<minor>
# development/<major> is greater than development/<major>.<minor>
return False
if other.minor is None:
return True # development/<major>.<minor> is less than development/<major>
# development/<major>.<minor> is less than development/<major>
return True
return self.minor < other.minor

@property
Expand Down Expand Up @@ -317,7 +318,8 @@ def __eq__(self, other):
@total_ordering
class QueueIntegrationBranch(GWFBranch):
# TODO: review if pattern needs to be changed as having a
# pr id may conflict with the major branch pattern and result in a failure to create.
# pr id may conflict with the major branch pattern
# and result in a failure to create.
pattern = r'^q/w/(?P<pr_id>\d+)/' + IntegrationBranch.pattern[3:]

def __eq__(self, other):
Expand Down Expand Up @@ -884,7 +886,8 @@ def add_branch(self, branch, dst_branch=None):
else:
return

# TODO: ensure it's ok to have a -1 minor version included in the cascade
# TODO: ensure it's ok to have a -1 minor version
# included in the cascade
(major, minor) = branch.major, branch.minor
if (major, minor) not in self._cascade.keys():
self._cascade[(major, minor)] = {
Expand All @@ -893,7 +896,9 @@ def add_branch(self, branch, dst_branch=None):
HotfixBranch: None,
}
# Sort the cascade again
self._cascade = OrderedDict(sorted(self._cascade.items(), key=cmp_to_key(compare_branches)))
self._cascade = OrderedDict(
sorted(self._cascade.items(), key=cmp_to_key(compare_branches))
)

cur_branch = self._cascade[(major, minor)][branch.__class__]

Expand Down Expand Up @@ -987,10 +992,14 @@ def validate(self):

previous_dev_branch = dev_branch

# not used right now but might come useful to handle a case with dev/1 and stab/1.0.0
# not used right now but might come useful
# to handle a case with dev/1 and stab/1.0.0
def _find_latest_minor(self, major) -> int | None:
"""For a given major version, find in the cascade the latest minor."""
minors = [minor for (m, minor) in self._cascade.keys() if m == major and minor is not None]
minors = [
minor for (m, minor) in self._cascade.keys()
if m == major and minor is not None
]
if not minors:
return None
return max(minors)
Expand Down Expand Up @@ -1020,10 +1029,16 @@ def _set_target_versions(self, dst_branch):
self.target_versions.append('%d.%d.%d' % (
major, minor, dev_branch.micro + offset))
elif dev_branch and dev_branch.has_minor is False:
# TODO: handle case with stab/x.y.z with no dev/x.y -> no need as stab/x.y.z cannot exist without a dev/x.y
# TODO: handle case where dev/1 and dev/1.0 exists (but no 1.0.0 tag) -> Should return 1.0.0 only
self.target_versions.append(f"{major}.{dev_branch.latest_minor + 1}.{dev_branch.micro + 1}")

# TODO: handle case with stab/x.y.z with no dev/x.y
# -> no need as stab/x.y.z cannot exist without a dev/x.y
# TODO: handle case where dev/1 and dev/1.0 exists
# but no 1.0.0 tag
# -> Should return 1.0.0 only
self.target_versions.append(
f"{major}."
f"{dev_branch.latest_minor + 1}."
f"{dev_branch.micro + 1}"
)

def finalize(self, dst_branch):
"""Finalize cascade considering given destination.
Expand Down

0 comments on commit 1fb9b78

Please sign in to comment.