From 5e6399411ab8b7d051f1d951ab62f02a4158a5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Bal=C3=A1=C5=BEik?= Date: Wed, 28 Jan 2026 15:21:58 +0100 Subject: [PATCH] Fix 'Too many return statements' pylint error Refactor `Key.match_properties` into multiple functions. (cherry picked from commit 19076c0d4d39410c7060094faebccc0803312606) --- bin/tests/system/isctest/kasp.py | 87 +++++++++++++++++++++----------- pyproject.toml | 1 - 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/bin/tests/system/isctest/kasp.py b/bin/tests/system/isctest/kasp.py index 18682f3bd8..8098afecb6 100644 --- a/bin/tests/system/isctest/kasp.py +++ b/bin/tests/system/isctest/kasp.py @@ -575,14 +575,10 @@ class Key: isctest.log.debug(f"{self.name} {key} TIMING UNEXPECTED: {value}") return value == "undefined" - def match_properties(self, zone, properties): + def _check_public_key_file(self, zone, properties): """ - Check the key with given properties. + Check the public key file. """ - # Check file existence. - # Noop. If file is missing then the get_metadata calls will fail. - - # Check the public key file. role = properties.role_full() comment = f"This is a {role} key, keyid {self.tag}, for {zone}." if not isctest.util.file_contents_contain(self.keyfile, comment): @@ -597,31 +593,45 @@ class Key: isctest.log.debug(f"{self.name} DNSKEY MISMATCH: expected '{dnskey}'") return False - # Now check the private key file. - if properties.private: - # Retrieve creation date. - created = self.get_metadata("Generated") + return True - pval = self.get_metadata("Created", file=self.privatefile) - if pval != created: - isctest.log.debug( - f"{self.name} Created METADATA MISMATCH: {pval} - {created}" - ) - return False - pval = self.get_metadata("Private-key-format", file=self.privatefile) - if pval != "v1.3": - isctest.log.debug( - f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3" - ) - return False - pval = self.get_metadata("Algorithm", file=self.privatefile) - if pval != f"{alg}": - isctest.log.debug( - f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}" - ) - return False + def _check_private_key_file(self, properties): + """ + Check the private key file. + """ + if not properties.private: + return True - # Now check the key state file. + alg = properties.metadata["Algorithm"] + + # Retrieve creation date. + created = self.get_metadata("Generated") + + pval = self.get_metadata("Created", file=self.privatefile) + if pval != created: + isctest.log.debug( + f"{self.name} Created METADATA MISMATCH: {pval} - {created}" + ) + return False + pval = self.get_metadata("Private-key-format", file=self.privatefile) + if pval != "v1.3": + isctest.log.debug( + f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3" + ) + return False + pval = self.get_metadata("Algorithm", file=self.privatefile) + if pval != f"{alg}": + isctest.log.debug( + f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}" + ) + return False + + return True + + def _check_key_state_file(self, zone, properties): + """ + Check the key state file. + """ if properties.legacy: return True @@ -652,7 +662,24 @@ class Key: if self.tag > properties.keytag_max: return False - # A match is found. + return True + + def match_properties(self, zone, properties): + """ + Check the key with given properties. + """ + # Check file existence. + # Noop. If file is missing then the get_metadata calls will fail. + + if not self._check_public_key_file(zone, properties): + return False + + if not self._check_private_key_file(properties): + return False + + if not self._check_key_state_file(zone, properties): + return False + return True def match_timingmetadata(self, timings, file=None, comment=False): diff --git a/pyproject.toml b/pyproject.toml index 9b6d430ec9..4aed089859 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ disable = [ "R0801", # duplicate-code "R0902", # too-many-instance-attributes "R0903", # too-few-public-methods - "R0911", # too-many-return-statements "R0912", # too-many-branches "R0913", # too-many-arguments "R0914", # too-many-locals