def round_trip_rapidyaml(self, prefix, in_message):
        strings, value = to_rapidyaml(in_message)
        yaml_string = ryml.emit(value)

        if OUTPUT_FILES:
            with open(prefix + '_test_rapidyaml.yaml', 'w') as f:
                f.write(yaml_string)

        value_out = ryml.parse(yaml_string)
        message = get_module_from_id(in_message.schema.node.id).new_message()
        from_rapidyaml(message, value_out)
        compare_capnp(self, in_message, message)

        strings, value2 = to_rapidyaml(message)
        yaml_string2 = ryml.emit(value2)

        if OUTPUT_FILES:
            with open(prefix + '_test_rapidyaml2.yaml', 'w') as f:
                f.write(yaml_string2)

        self.assertTrue(yaml_string == yaml_string2)
    def round_trip_json(self, prefix, in_message):
        value = to_json(in_message)
        json_string = json.dumps(value, indent=2)

        if OUTPUT_FILES:
            with open(prefix + '_test_json.json', 'w') as f:
                f.write(json_string)

        value_out = json.loads(json_string)
        message = get_module_from_id(in_message.schema.node.id).new_message()
        from_json(message, value_out)
        compare_capnp(self, in_message, message)

        value2 = to_json(message)
        json_string2 = json.dumps(value2, indent=2)

        if OUTPUT_FILES:
            with open(prefix + '_test_json2.json', 'w') as f:
                f.write(json_string2)

        self.assertTrue(json_string == json_string2)
    def round_trip_yaml(self, prefix, in_message):
        value = to_yaml(in_message)
        yaml_string = yaml.dump(value, sort_keys=False, Dumper=Dumper)

        if OUTPUT_FILES:
            with open(prefix + '_test_yaml.yaml', 'w') as f:
                f.write(yaml_string)

        value_out = yaml.load(yaml_string, Loader=SafeLoader)
        message = get_module_from_id(in_message.schema.node.id).new_message()
        from_yaml(message, value_out)
        compare_capnp(self, in_message, message)

        value2 = to_yaml(message)
        yaml_string2 = yaml.dump(value2, sort_keys=False, Dumper=Dumper)

        if OUTPUT_FILES:
            with open(prefix + '_test_yaml2.yaml', 'w') as f:
                f.write(yaml_string2)

        self.assertTrue(yaml_string == yaml_string2)
示例#4
0
    def test_patch_series7_constraints(self):
        phys_netlist = example_physical_netlist()

        interchange = Interchange(
            schema_directory=os.environ['INTERCHANGE_SCHEMA_PATH'])

        with open(
                os.path.join(os.environ['DEVICE_RESOURCE_PATH'],
                             phys_netlist.part + '.device'), 'rb') as f:
            dev_message = interchange.read_device_resources_raw(f)

        dev_message = dev_message.as_builder()

        path = os.path.join(__dir__, 'data', 'series7_constraints.yaml')
        with open(path, 'rb') as f:
            patch_capnp(dev_message, ['constraints'], 'yaml', f)

        schema = get_schema(os.environ['INTERCHANGE_SCHEMA_PATH'], 'device',
                            'Device.Constraints')
        with open(path, 'rb') as f:
            series7 = read_format(schema, 'yaml', f)

        compare_capnp(self, series7, dev_message.constraints)
    def round_read_write_message(self, schema, message):
        schema_dir = os.environ['INTERCHANGE_SCHEMA_PATH']

        schema = get_schema(schema_dir, schema)

        for format1 in FORMATS:
            f = io.BytesIO()
            write_format(message, format1, f)
            f.seek(0)
            message_out = read_format(schema, format1, f)
            compare_capnp(self, message, message_out)

            for format2 in FORMATS:
                f2 = io.BytesIO()
                write_format(message_out, format2, f2)
                f2.seek(0)
                message_out2 = read_format(schema, format2, f2)
                compare_capnp(self, message, message_out2)
                compare_capnp(self, message_out, message_out2)