From 1fb9b78b6984c278357ab12890cf49c806fd01b1 Mon Sep 17 00:00:00 2001 From: Thomas Carmet <8408330+tcarmet@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:53:26 +0000 Subject: [PATCH] linting --- bert_e/tests/test_bert_e.py | 26 ++++++------- bert_e/tests/unit/test_sorted.py | 10 ++++- bert_e/workflow/gitwaterflow/branches.py | 47 ++++++++++++++++-------- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/bert_e/tests/test_bert_e.py b/bert_e/tests/test_bert_e.py index 007d9ab9..73f08418 100644 --- a/bert_e/tests/test_bert_e.py +++ b/bert_e/tests/test_bert_e.py @@ -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) @@ -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 @@ -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)) @@ -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) @@ -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. @@ -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) @@ -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') @@ -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( @@ -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( diff --git a/bert_e/tests/unit/test_sorted.py b/bert_e/tests/unit/test_sorted.py index 6b424681..0c2dca46 100644 --- a/bert_e/tests/unit/test_sorted.py +++ b/bert_e/tests/unit/test_sorted.py @@ -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(): @@ -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)] diff --git a/bert_e/workflow/gitwaterflow/branches.py b/bert_e/workflow/gitwaterflow/branches.py index 183d7465..ea3333dd 100644 --- a/bert_e/workflow/gitwaterflow/branches.py +++ b/bert_e/workflow/gitwaterflow/branches.py @@ -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] @@ -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/ is greater than development/. + # development/ is greater than development/. + return False if other.minor is None: - return True # development/. is less than development/ + # development/. is less than development/ + return True return self.minor < other.minor @property @@ -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\d+)/' + IntegrationBranch.pattern[3:] def __eq__(self, other): @@ -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)] = { @@ -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__] @@ -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) @@ -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.