コード例 #1
0
    def test_examples_are_valid(self):
        """Validate example json files against respective schemas"""
        schemas = TestSchemaExamples._json_examples_per_schema
        for schema_name, examples in schemas.items():
            with self.subTest(schema_test=schema_name):
                for example_schema in examples:
                    with self.subTest(example=example_schema):
                        with open(
                                os.path.join(self.examples_base_path,
                                             example_schema),
                                'r') as example_file:
                            example = json.load(example_file)
                            msg = 'JSON failed validation of {}.'\
                                  'Set Qiskit log level to DEBUG'\
                                  'for further information.'\
                                  ''.format(schema_name)

                            validate_json_against_schema(
                                example, schema_name, msg)

                        # Check for validating examples using the qiskit models.
                        obj_map = {
                            'result': Result,
                            'backend_configuration': BackendConfiguration,
                            'backend_properties': BackendProperties,
                            'backend_status': BackendStatus,
                            'job_status': JobStatus,
                            'default_pulse_configuration': PulseDefaults
                        }
                        cls = obj_map.get(schema_name, None)
                        if cls and 'openpulse' not in example_schema:
                            _ = cls.from_dict(example)
コード例 #2
0
    def test_examples_are_valid(self):
        """Validate example json files against respective schemas"""
        schemas = TestSchemaExamples._json_examples_per_schema
        for test_name, examples in schemas.items():
            if isinstance(examples, tuple):
                schema_name = examples[0]
                examples = examples[1]
            else:
                schema_name = test_name

            with self.subTest(schema_test=test_name):
                for example_schema in examples:
                    with self.subTest(example=example_schema):
                        with open(
                                os.path.join(self.examples_base_path,
                                             example_schema)) as example_file:
                            example = json.load(example_file)
                            msg = ("JSON failed validation of {}."
                                   "Set Qiskit log level to DEBUG"
                                   "for further information."
                                   "".format(test_name))

                            validate_json_against_schema(
                                example, schema_name, msg)

                        # Check for validating examples using the qiskit models.
                        obj_map = {
                            "result": Result,
                            "qasm_backend_configuration":
                            QasmBackendConfiguration,
                            "pulse_backend_configuration":
                            PulseBackendConfiguration,
                            "backend_properties": BackendProperties,
                            "backend_status": BackendStatus,
                            "job_status": JobStatus,
                            "default_pulse_configuration": PulseDefaults,
                        }
                        cls = obj_map.get(schema_name, None)
                        if cls and "openpulse" not in example_schema:
                            _ = cls.from_dict(example)