From 37500b9fa572534352f5b825acba0b11c46ea4aa Mon Sep 17 00:00:00 2001 From: Matthew Burket Date: Wed, 12 Jun 2024 13:21:34 -0500 Subject: [PATCH] Clean up Code Climate Issues --- tests/validate_automatus_metadata.py | 36 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/validate_automatus_metadata.py b/tests/validate_automatus_metadata.py index c42ca0e7ccaa..47f5a5671e02 100755 --- a/tests/validate_automatus_metadata.py +++ b/tests/validate_automatus_metadata.py @@ -32,27 +32,33 @@ def _test_filename_valid(test_file: str) -> bool: return True +def _has_invalid_param(root: str, test_file: str) -> bool: + full_path = os.path.join(root, test_file) + with open(full_path, "r") as f: + for line in f: + if not line.startswith("#"): + break + line = line.removeprefix('#') + line = line.strip() + parts = line.split('=') + if len(parts) != 2: + continue + param_name = parts[0].strip() + if param_name not in VALID_FIELDS: + print(f"Invalid field '{param_name}' in {test_file}", file=sys.stderr) + return False + return True + + def main() -> int: args = _parse_args() test_files = get_files(args.root) return_value = 0 for test_file in test_files: - if not _test_filename_valid(test_file) != 0: + if not _test_filename_valid(test_file): + return_value = 1 + if not _has_invalid_param(args.root, test_file): return_value = 1 - full_path = os.path.join(args.root, test_file) - with open(full_path, "r") as f: - for line in f: - if not line.startswith("#"): - break - line = line.removeprefix('#') - line = line.strip() - parts = line.split('=') - if len(parts) != 2: - continue - if parts[0].strip() not in VALID_FIELDS: - print(f"Invalid field '{parts[0].strip()}' in {test_file}", file=sys.stderr) - return_value = 1 - return return_value