def schema_to_str(args): schema_str = None if get('version', args): schema_str = schema.from_version(get('version', args)) elif get('schema_file', args): schema_str = schema.load_schema_file(get('schema_file', args)) if not schema_str: print('you need to supply a schema version or file with -v or -s') die() return schema_str
def unpack(x): d = { 'version': get('--version', x) or get('-v', x), 'schema_file': get('--schema-file', x) or get('-s', x), 'glob': get('--files', x) or get('-f', x), } return d
def conforms(source, target): """ Return whether the `target` object conforms to `source` where `source` is a dictionary that contains key-value pairs which are compared against the same key- values in `target`. If a key- value in `source` is a callable, then that callable is used as a predicate against the corresponding key-value in `target`. Examples: >>> conforms({'b': 2}, {'a': 1, 'b': 2}) True >>> conforms({'b': 3}, {'a': 1, 'b': 2}) False >>> conforms({'b': 2, 'a': lambda a: a > 0}, {'a': 1, 'b': 2}) True >>> conforms({'b': 2, 'a': lambda a: a > 0}, {'a': -1, 'b': 2}) False Args: source (Mapping): Object of path values to match. target (Mapping): Object to compare. Returns: bool: Whether `target` is a match or not. """ result = True for key, value in source.items(): target_value = fnc.get(key, target, default=Sentinel) if target_value is Sentinel: target_result = False elif callable(value): target_result = value(target_value) else: target_result = target_value == value if not target_result: result = False break return result
def test_get__should_not_populate_defaultdict(): data = defaultdict(list) fnc.get("a", data) assert data == {}
schema_str = schema.from_version(get('version', args)) elif get('schema_file', args): schema_str = schema.load_schema_file(get('schema_file', args)) if not schema_str: print('you need to supply a schema version or file with -v or -s') die() return schema_str args = args_to_dict(arguments) print('using args', args) schema_str = schema_to_str(args) gl = get('glob', args) or './examples/' + get('version', args) print('glooob patternnn', gl) # read a directory for xml files recursively else just use given one gg = list( filter(lambda x: x.endswith('.xml'), glob(f'{gl}/**', recursive=True) + [gl])) print(f'running supplied schema on the following files') print(gg) print('---------------------------------------------------------') print('validating xml files!!!!') print('---------------------------------------------------------') for f in gg: xml = schema.load_schema_file(f) result = validate_one(schema_str, xml) print(f)