Beispiel #1
0
    def _read_json_and_protos(
            self,
            json_path: str,
            proto_path: str,
            proto_cls: Type[message.Message],
            *,
            json_delimiter: Optional[str] = None,
            proto_delimiter: Optional[str] = None) -> _JsonFormatTestdata:
        """Convenience method for returning collections of testdata."""
        json_strs = testdata_utils.read_data(json_path,
                                             delimiter=json_delimiter)

        # We filter out 'null' values here, as the proto-parsing has no delimiter/
        # methodology for loading a 'null' .prototxt representation. This value is
        # simply absent in the corresponding .prototxt file.
        nonnull_json_strs = [
            json_str for json_str in json_strs if json_str != 'null'
        ]
        protos = testdata_utils.read_protos(proto_path,
                                            proto_cls,
                                            delimiter=proto_delimiter)
        if len(nonnull_json_strs) != len(protos):
            raise ValueError(
                f'Cannot compare {len(nonnull_json_strs)} .json representations '
                f'against {len(protos)} .prototxt representations.')
        return _JsonFormatTestdata(nonnull_json_strs, protos)
    def _invalid_test(self, name: str, message_cls: Type[message.Message]):
        msg = testdata_utils.read_protos(
            os.path.join(_VALIDATION_DIR, name + '.prototxt'), message_cls)[0]

        with self.assertRaises(fhir_errors.InvalidFhirError) as fe:
            resource_validation.validate_resource(msg)

        self.assertIsInstance(fe.exception, fhir_errors.InvalidFhirError)
Beispiel #3
0
 def _coding_from_file(
         self, name: str,
         coding_cls: Type[message.Message]) -> message.Message:
     """Reads data from the CODES_DIR/name into an instance of coding_cls."""
     return testdata_utils.read_protos(os.path.join(_CODES_DIR, name),
                                       coding_cls)[0]
 def _valid_test(self, name: str,
                 message_cls: Type[message.Message]) -> None:
     msg = testdata_utils.read_protos(
         os.path.join(_VALIDATION_DIR, name + '.prototxt'), message_cls)[0]
     resource_validation.validate_resource(msg)