def check_one_to_one_relationship(self, left_data: List, right_data: List, left_key: str, right_key: str) -> OneCheckReport: """Check that relationships are one-to-one, not one-to-many""" left_keys = [item[left_key] for item in left_data] right_keys = [item[right_key] for item in right_data] # Check if any left key maps to multiple right items from collections import Counter right_counts = Counter(right_keys) violations = [] for key in set(left_keys): if right_counts.get(key, 0) > 1: violations.append({ 'key': key, 'count': right_counts[key] }) if violations: return OneCheckReport( check_name="One-to-one relationship check", result=CheckerResult.FAIL, message=f"Found {len(violations)} keys with multiple relationships", details={'violations': violations} ) else: return OneCheckReport( check_name="One-to-one relationship check", result=CheckerResult.PASS, message="All relationships are one-to-one" )
# Example 2: Check active configuration configs = { 'dev': {'active': False, 'env': 'development'}, 'prod': {'active': True, 'env': 'production'}, 'staging': {'active': False, 'env': 'staging'} } one checker
checker.register_check("Single source of truth", check_sot) right_key: str) ->
def check_sot(): return checker.check_single_source_of_truth(sources) OneCheckReport: """Check that relationships are one-to-one