File size: 1,177 Bytes
9f8cf99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Contract tests for qhybrid JSON schema version handling."""

import json

import pytest

from qhybrid_kernels import execute_quantum_circuit
from qhybrid_kernels.circuit import QHYBRID_PAYLOAD_VERSION


def test_execute_quantum_circuit_rejects_missing_schema_version():
    payload = {
        "n_qubits": 1,
        "gates": [],
        "name": "legacy_payload",
    }

    with pytest.raises(ValueError, match="Missing circuit schema_version"):
        execute_quantum_circuit(json.dumps(payload))


def test_execute_quantum_circuit_rejects_unsupported_schema_version():
    payload = {
        "schema_version": QHYBRID_PAYLOAD_VERSION + 1,
        "n_qubits": 1,
        "gates": [],
        "name": "future_payload",
    }

    with pytest.raises(ValueError, match="Unsupported circuit schema_version"):
        execute_quantum_circuit(json.dumps(payload))


def test_execute_quantum_circuit_accepts_current_schema_version():
    payload = {
        "schema_version": QHYBRID_PAYLOAD_VERSION,
        "n_qubits": 1,
        "gates": [],
        "name": "valid_payload",
    }

    result = execute_quantum_circuit(json.dumps(payload))
    assert result.shape == (2, 2)