Created
December 19, 2024 20:25
-
-
Save a-chumagin/879b1655ef2b45e35f9ef57f27f105d6 to your computer and use it in GitHub Desktop.
Validations for Soda CL checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from soda.scan import Scan | |
import os | |
import yaml | |
import argparse | |
def parse_arguments(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--path', help='Specify the tests to run') | |
return parser.parse_args() | |
def validate_yaml(file_path): | |
try: | |
with open(file_path, 'r') as file: | |
yaml.safe_load(file) | |
print(f"{file_path} is a valid YAML file.") | |
except yaml.YAMLError as exc: | |
print(f"Error in {file_path}: {exc}") | |
def validate_checks(path): | |
if os.path.isfile(path): | |
files = [path] | |
elif os.path.isdir(path): | |
files = [os.path.join(root, filename) | |
for root, _, filenames in os.walk(path) | |
for filename in filenames if filename.endswith('.yml')] | |
else: | |
raise ValueError("Provided path is neither a file nor a directory") | |
valid_count = 0 | |
invalid_count = 0 | |
valid_count, invalid_count = 0, 0 | |
for file in files: | |
print(f"Validating {file}") | |
validate_yaml(file) | |
with open(file, 'r') as f: | |
yaml_str = str(f.read()) | |
scan = Scan() | |
scan._parse_sodacl_yaml_str(yaml_str, file) | |
if not scan.has_error_logs(): | |
result = "Valid" | |
valid_count += 1 | |
else: | |
result = "Invalid" | |
invalid_count += 1 | |
print(f"{file}: is {result} SODA check") | |
print(f"Total valid files: {valid_count}") | |
print(f"Total invalid files: {invalid_count}") | |
# Parse command-line arguments | |
test_path = parse_arguments().path | |
validate_checks(test_path) | |
validate_checks(test_path) | |
# pip istall soda-core | |
# pip install pyyaml | |
# python scripts/validate_checks.py --path=checks/prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment