|
15 | 15 | import pytest |
16 | 16 |
|
17 | 17 | import cirq |
18 | | -from cirq.testing import assert_deprecated |
19 | | - |
20 | | - |
21 | | -def test_single_qubit_gate_validate_args(): |
22 | | - class Dummy(cirq.SingleQubitGate): |
23 | | - def matrix(self): |
24 | | - pass |
25 | | - |
26 | | - with assert_deprecated(deadline="v1.0"): |
27 | | - g = Dummy() |
28 | | - |
29 | | - with assert_deprecated(deadline="isinstance(gate, SingleQubitGate) is deprecated"): |
30 | | - assert isinstance(g, cirq.SingleQubitGate) |
31 | | - q1 = cirq.NamedQubit('q1') |
32 | | - q2 = cirq.NamedQubit('q2') |
33 | | - |
34 | | - assert g.num_qubits() == 1 |
35 | | - g.validate_args([q1]) |
36 | | - g.validate_args([q2]) |
37 | | - with pytest.raises(ValueError): |
38 | | - g.validate_args([]) |
39 | | - with pytest.raises(ValueError): |
40 | | - g.validate_args([q1, q2]) |
41 | | - |
42 | | - |
43 | | -def test_single_qubit_gate_validates_on_each(): |
44 | | - class Dummy(cirq.Gate): |
45 | | - def matrix(self): |
46 | | - pass |
47 | | - |
48 | | - def _num_qubits_(self) -> int: |
49 | | - return 1 |
50 | | - |
51 | | - g = Dummy() |
52 | | - assert g.num_qubits() == 1 |
53 | | - |
54 | | - test_qubits = [cirq.NamedQubit(str(i)) for i in range(3)] |
55 | | - |
56 | | - _ = g.on_each(*test_qubits) |
57 | | - _ = g.on_each(test_qubits) |
58 | | - |
59 | | - test_non_qubits = [str(i) for i in range(3)] |
60 | | - with pytest.raises(ValueError): |
61 | | - _ = g.on_each(*test_non_qubits) |
62 | | - with pytest.raises(ValueError): |
63 | | - _ = g.on_each(*test_non_qubits) |
64 | | - |
65 | | - |
66 | | -def test_single_qubit_validates_on(): |
67 | | - class Dummy(cirq.Gate): |
68 | | - def matrix(self): |
69 | | - pass |
70 | | - |
71 | | - def _num_qubits_(self) -> int: |
72 | | - return 1 |
73 | | - |
74 | | - g = Dummy() |
75 | | - assert g.num_qubits() == 1 |
76 | | - |
77 | | - test_qubits = [cirq.NamedQubit(str(i)) for i in range(3)] |
78 | | - |
79 | | - with pytest.raises(ValueError): |
80 | | - _ = g.on(*test_qubits) |
81 | | - with pytest.raises(ValueError): |
82 | | - _ = g.on(*test_qubits) |
83 | 18 |
|
84 | 19 |
|
85 | 20 | def test_qasm_output_args_validate(): |
|
0 commit comments