def idiom_mappings(converted_json, stored_json, ignored_properties): for good, to_check in zip(iterpath(stored_json), iterpath(converted_json)): good_path, good_value = good check_path, check_value = to_check # last_good_field = good_path[-1] if isinstance(good_value, (dict, list)): # Rule #1: No need to verify iterable types. Since we will deal # with individual values in the future. continue if (any(s in (u"object_marking_refs", u"granular_markings") for s in good_path)): # Exception to Rule #1: object_marking_refs and granular_markings # are not verifiable because they contain identifiers per rule #2. continue # make sure that the property names match if any(x in ignored_properties for x in good_path) and good_path[-1] == check_path[-1]: # Rule #2: Since fresh conversion may create dynamic values. # Some fields are omitted for verification. Currently # fields with: identifier and timestamp values. continue yield good, to_check
def idiom_mappings(xml_file_path, stored_json): """Test fresh conversion from XML to JSON matches stored JSON samples.""" print("Checking - " + xml_file_path) initialize_options() converted_json = elevate_file(xml_file_path) io = StringIO(converted_json) converted_json = json.load(io) for good, to_check in zip(iterpath(stored_json), iterpath(converted_json)): good_path, good_value = good last_good_field = good_path[-1] if isinstance(good_value, (dict, list)): # No need to verify iterable types. Since we will deal # with individual values in the future. continue if last_good_field in IGNORE: # Since fresh conversion may create dynamic values. # Some fields are omitted for verification. Currently # fields with: identifier and timestamp values. continue yield good, to_check
def idiom_mappings(xml_file_path, stored_json): """Test fresh conversion from XML to JSON matches stored JSON samples.""" print("Checking - " + xml_file_path) print("With Master - " + stored_json["id"]) initialize_options() set_option_value("log_level", "CRITICAL") set_option_value("validator_args", "--no-cache") if not get_option_value("policy") == "no_policy": print("'no_policy' is not allowed for testing") set_option_value("policy", "no_policy") sys.setrecursionlimit(3000) converted_json = elevate_file(xml_file_path) converted_json = json.loads(converted_json) for good, to_check in zip(iterpath(stored_json), iterpath(converted_json)): good_path, good_value = good last_good_field = good_path[-1] if isinstance(good_value, (dict, list)): # Rule #1: No need to verify iterable types. Since we will deal # with individual values in the future. continue if (any(s in (u"object_marking_refs", u"granular_markings") for s in good_path)): # Exception to Rule #1: object_marking_refs and granular_markings # are not verifiable because they contain identifiers per rule #2. continue if last_good_field in IGNORE: # Rule #2: Since fresh conversion may create dynamic values. # Some fields are omitted for verification. Currently # fields with: identifier and timestamp values. continue yield good, to_check