Skip to content

Commit 63f5aae

Browse files
Victory OmoleCirqBot
Victory Omole
authored andcommittedApr 30, 2019
Remove @cirq.testing.only_test_in_python3 (quantumlib#1579)
Part of: quantumlib#1372
1 parent 0827da8 commit 63f5aae

20 files changed

+28
-68
lines changed
 

‎CONTRIBUTING.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,5 @@ When pylint produces a false positive, it can be squashed with annotations like
9999
Code should have [type annotations](https://www.python.org/dev/peps/pep-0484/).
100100
We use [mypy](http://mypy-lang.org/) to check that type annotations are correct.
101101
When type checking produces a false positive, it can be ignored with annotations like `# type: ignore`.
102-
- **Python 2 Convertibility**.
103-
Code must avoid constructs which fail to translate to python 2.
104-
Cirq is written in python 3, but we use [3to2](https://pypi.org/project/3to2/) (and some custom tooling) to automatically translate the code into runnable python 2 code.
105-
This translation step is not perfect.
106-
For example, `max([], default=2)` fails to translate.
107-
We check that the translation worked by testing the translated code against the translated tests.
108-
Cirq has several utilities to help the translation process along, such as the `@cirq.testing.only_test_in_python3` decorator for tests that check functionality specific to python 3.
102+
109103

‎cirq/circuits/circuit_dag_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_wrapper_cmp():
4343
assert u1 >= u0
4444

4545

46-
@cirq.testing.only_test_in_python3
46+
4747
def test_wrapper_cmp_failure():
4848
with pytest.raises(TypeError):
4949
_ = object() < cirq.Unique(1)

‎cirq/circuits/circuit_test.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_bool():
221221
assert Circuit.from_ops(cirq.X(cirq.NamedQubit('a')))
222222

223223

224-
@cirq.testing.only_test_in_python3
224+
225225
def test_repr():
226226
assert repr(cirq.Circuit()) == 'cirq.Circuit()'
227227

@@ -325,7 +325,7 @@ def test_empty_moments():
325325
use_unicode_characters=True,
326326
transpose=True)
327327

328-
# 2-qubit ascii-only test
328+
# 2-qubit ascii-only test
329329
cirq.testing.assert_has_diagram(circuit, """
330330
a: ---@---@-------@---
331331
| | |
@@ -360,7 +360,7 @@ def test_symbol_addition_in_gate_exponent():
360360

361361

362362
cirq.testing.assert_has_diagram(circuit,
363-
"""
363+
"""
364364
a
365365
366366
X^0.5
@@ -369,22 +369,22 @@ def test_symbol_addition_in_gate_exponent():
369369
370370
""",
371371
use_unicode_characters=True,
372-
transpose=True)
372+
transpose=True)
373373

374374
cirq.testing.assert_has_diagram(circuit,
375375
'a: ---X^0.5---Y^(a + b)---',
376376
use_unicode_characters=False)
377377

378378
cirq.testing.assert_has_diagram(circuit,
379-
"""
379+
"""
380380
a
381381
|
382382
X^0.5
383383
|
384384
Y^(a + b)
385385
|
386386
387-
""",
387+
""",
388388
use_unicode_characters=False,
389389
transpose=True)
390390

@@ -2649,8 +2649,7 @@ def test_to_qasm():
26492649
cirq.X(q0),
26502650
)
26512651
assert circuit.to_qasm() == cirq.qasm(circuit)
2652-
assert (circuit.to_qasm() ==
2653-
"""// Generated from Cirq v{}
2652+
assert (circuit.to_qasm() == """// Generated from Cirq v{}
26542653
26552654
OPENQASM 2.0;
26562655
include "qelib1.inc";
@@ -2673,8 +2672,7 @@ def test_save_qasm():
26732672
circuit.save_qasm(file_path)
26742673
with open(file_path, 'r') as f:
26752674
file_content = f.read()
2676-
assert (file_content ==
2677-
"""// Generated from Cirq v{}
2675+
assert (file_content == """// Generated from Cirq v{}
26782676
26792677
OPENQASM 2.0;
26802678
include "qelib1.inc";

‎cirq/google/engine/engine_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272

7373

74-
@cirq.testing.only_test_in_python3
74+
7575
def test_repr():
7676
v = cirq.google.JobConfig(project_id='my-project-id',
7777
program_id='my-program-id',
@@ -476,7 +476,7 @@ def test_implied_job_config_gcs_prefix(build):
476476
assert eng_with.implied_job_config(config).gcs_prefix == 'gs://better/'
477477

478478

479-
@cirq.testing.only_test_in_python3 # uses re.fullmatch
479+
# uses re.fullmatch
480480
@mock.patch.object(discovery, 'build')
481481
def test_implied_job_config(build):
482482
eng = cg.Engine(api_key="key")

‎cirq/google/xmon_device_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_init_timedelta():
7979
assert d.duration_of(cirq.CZ(q00, q01)) == 3 * microsecond
8080

8181

82-
@cirq.testing.only_test_in_python3
82+
8383
def test_repr():
8484
d = square_device(2, 2, holes=[])
8585

‎cirq/ion/ion_device_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_decomposition():
8989
""", use_unicode_characters=True)
9090

9191

92-
@cirq.testing.only_test_in_python3
92+
9393
def test_repr():
9494
d = ion_device(3)
9595

‎cirq/line/line_qubit_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import pytest
1616

17-
from cirq.testing import EqualsTester, only_test_in_python3
17+
from cirq.testing import EqualsTester
1818
from cirq import LineQubit
1919

2020

@@ -49,7 +49,6 @@ def test_cmp():
4949
assert LineQubit(1) >= LineQubit(0)
5050

5151

52-
@only_test_in_python3
5352
def test_cmp_failure():
5453
with pytest.raises(TypeError):
5554
_ = 0 < LineQubit(1)

‎cirq/ops/named_qubit_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_named_qubit_str():
2323

2424

2525
# Python 2 gives a different repr due to unicode strings being prefixed with u.
26-
@cirq.testing.only_test_in_python3
26+
2727
def test_named_qubit_repr():
2828
q = cirq.NamedQubit('a')
2929
assert repr(q) == "cirq.NamedQubit('a')"

‎cirq/ops/pauli_gates_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_gt():
122122
assert not cirq.Z > cirq.Z
123123

124124

125-
@cirq.testing.only_test_in_python3
125+
126126
def test_gt_other_type():
127127
with pytest.raises(TypeError):
128128
_ = cirq.X > object()
@@ -140,7 +140,7 @@ def test_lt():
140140
assert not cirq.Z < cirq.Z
141141

142142

143-
@cirq.testing.only_test_in_python3
143+
144144
def test_lt_other_type():
145145
with pytest.raises(TypeError):
146146
_ = cirq.X < object()

‎cirq/ops/pauli_string_phasor_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def test_text_diagram():
431431
""")
432432

433433

434-
@cirq.testing.only_test_in_python3
434+
435435
def test_repr():
436436
q0, q1, q2 = _make_qubits(3)
437437
cirq.testing.assert_equivalent_repr(

‎cirq/schedules/schedule_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_query_overlapping_operations_exclusive():
179179

180180

181181
# In python 2, timedelta doesn't support multiplication with floats
182-
@cirq.testing.only_test_in_python3
182+
183183
def test_query_timedelta():
184184
q = cirq.NamedQubit('q')
185185
zero = cirq.Timestamp(picos=0)

‎cirq/sim/density_matrix_simulator_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def test_density_matrix_simulator_state_eq():
465465

466466

467467
# Python 2 gives a different repr due to unicode strings being prefixed with u.
468-
@cirq.testing.only_test_in_python3
468+
469469
def test_density_matrix_simulator_state_repr():
470470
q0 = cirq.LineQubit(0)
471471
assert (repr(cirq.DensityMatrixSimulatorState(
@@ -503,7 +503,7 @@ def test_density_matrix_trial_result_eq():
503503

504504

505505
# Python 2 gives a different repr due to unicode strings being prefixed with u.
506-
@cirq.testing.only_test_in_python3
506+
507507
def test_density_matrix_trial_result_repr():
508508
q0 = cirq.LineQubit(0)
509509
final_simulator_state = cirq.DensityMatrixSimulatorState(

‎cirq/sim/simulator_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_simulation_trial_result_equality():
217217

218218

219219
# Python 2 gives a different repr due to unicode strings being prefixed with u.
220-
@cirq.testing.only_test_in_python3
220+
221221
def test_simulation_trial_result_repr():
222222
assert repr(cirq.SimulationTrialResult(params=cirq.ParamResolver({'s': 1}),
223223
measurements={'m': np.array([[1]])},

‎cirq/sim/wave_function_simulator_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
# Python 2 gives a different repr due to unicode strings being prefixed with u.
21-
@cirq.testing.only_test_in_python3
21+
2222
def test_wave_function_trial_result_repr():
2323
final_simulator_state = cirq.WaveFunctionSimulatorState(
2424
qubit_map={cirq.NamedQubit('a'): 0}, state_vector=np.array([0, 1]))

‎cirq/study/trial_result_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
# Python 2 gives a different repr due to unicode strings being prefixed with u.
23-
@cirq.testing.only_test_in_python3
23+
2424
def test_repr():
2525
v = cirq.TrialResult(
2626
params=cirq.ParamResolver({'a': 2}),

‎cirq/testing/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,5 @@
6767
from cirq.testing.random_circuit import (
6868
random_circuit,)
6969

70-
from cirq.testing.only_test_in_python3 import (
71-
only_test_in_python3,)
72-
7370
from cirq.testing.sample_circuits import (
7471
nonoptimal_toffoli_circuit,)

‎cirq/testing/only_test_in_python3.py

-28
This file was deleted.

‎cirq/value/duration_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_cmp():
8787
# In python 2, comparisons fallback to __cmp__ and don't fail.
8888
# But a custom __cmp__ that does fail would result in == failing.
8989
# So we throw up our hands and let it be.
90-
@cirq.testing.only_test_in_python3
90+
9191
def test_cmp_vs_other_type():
9292
with pytest.raises(TypeError):
9393
_ = Duration() < 0

‎cirq/value/timestamp_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_cmp():
7070
# In python 2, comparisons fallback to __cmp__ and don't fail.
7171
# But a custom __cmp__ that does fail would result in == failing.
7272
# So we throw up our hands and let it be.
73-
@cirq.testing.only_test_in_python3
73+
7474
def test_cmp_vs_other_type():
7575
with pytest.raises(TypeError):
7676
_ = Timestamp() < Duration()

‎cirq/value/value_equality_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class _:
252252
assert True # HACK: sacrificial line for indentation bug in 3to2.
253253

254254

255-
@cirq.testing.only_test_in_python3
255+
256256
def test_bad_manual_cls_forgot_method():
257257
with pytest.raises(TypeError, match='_value_equality_values_cls_'):
258258

0 commit comments

Comments
 (0)
Please sign in to comment.