Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing tests for Python 3.11 #6181

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cirq-core/cirq/circuits/frozen_circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ def test_immutable():
q = cirq.LineQubit(0)
c = cirq.FrozenCircuit(cirq.X(q), cirq.H(q))

with pytest.raises(AttributeError, match="can't set attribute"):
# Match one of two strings. The second one is message returned since python 3.11.
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'moments' of 'FrozenCircuit' object has no setter)",
):
c.moments = (cirq.Moment(cirq.H(q)), cirq.Moment(cirq.X(q)))
26 changes: 21 additions & 5 deletions cirq-core/cirq/devices/grid_qubit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,39 @@ def test_to_json():


def test_immutable():
with pytest.raises(AttributeError, match="can't set attribute"):
# Match one of two strings. The second one is message returned since python 3.11.
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'col' of 'GridQubit' object has no setter)",
):
q = cirq.GridQubit(1, 2)
q.col = 3

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'row' of 'GridQubit' object has no setter)",
):
q = cirq.GridQubit(1, 2)
q.row = 3

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'col' of 'GridQid' object has no setter)",
):
q = cirq.GridQid(1, 2, dimension=3)
q.col = 3

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'row' of 'GridQid' object has no setter)",
):
q = cirq.GridQid(1, 2, dimension=3)
q.row = 3

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'dimension' of 'GridQid' object has no setter)",
):
q = cirq.GridQid(1, 2, dimension=3)
q.dimension = 3

Expand Down
11 changes: 9 additions & 2 deletions cirq-core/cirq/devices/line_qubit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ def _qid_shape_(self):


def test_immutable():
with pytest.raises(AttributeError, match="can't set attribute"):
# Match one of two strings. The second one is message returned since python 3.11.
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'x' of 'LineQubit' object has no setter)",
):
q = cirq.LineQubit(5)
q.x = 6

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'x' of 'LineQid' object has no setter)",
):
q = cirq.LineQid(5, dimension=4)
q.x = 6

Expand Down
11 changes: 9 additions & 2 deletions cirq-core/cirq/ops/gate_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ def test_immutable():
a, b = cirq.LineQubit.range(2)
op = cirq.X(a)

with pytest.raises(AttributeError, match="can't set attribute"):
# Match one of two strings. The second one is message returned since python 3.11.
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'gate' of 'SingleQubitPauliStringGateOperation' object has no setter)",
):
op.gate = cirq.Y

with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'qubits' of 'SingleQubitPauliStringGateOperation' object has no setter)",
):
op.qubits = [b]


Expand Down
16 changes: 13 additions & 3 deletions cirq-core/cirq/ops/gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,21 @@ def test_invalid_gate_family():

def test_gate_family_immutable():
g = cirq.GateFamily(CustomX)
with pytest.raises(AttributeError, match="can't set attribute"):
# Match one of two strings. The second one is message returned since python 3.11.
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'gate' of 'GateFamily' object has no setter)",
):
g.gate = CustomXPowGate
with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'name' of 'GateFamily' object has no setter)",
):
g.name = 'new name'
with pytest.raises(AttributeError, match="can't set attribute"):
with pytest.raises(
AttributeError,
match="(can't set attribute)|(property 'description' of 'GateFamily' object has no setter)",
):
g.description = 'new description'


Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/value/classical_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MeasurementType(enum.IntEnum):
CHANNEL = 2

def __repr__(self):
return f'cirq.{str(self)}'
return f'cirq.MeasurementType.{self.name}'


class ClassicalDataStoreReader(abc.ABC):
Expand Down