Skip to content

Commit 6e38a27

Browse files
authored
Fix coverage exclusion syntax (#6241)
* switch to standard opt-out comments for code exclusion from coverage * fix placement of `# pragma: no cover` markup comments, so they are either on the affected line or at the preceding block * remove no-cover comments for code that is covered * remove redundant no-cover comments
1 parent 6b44704 commit 6e38a27

File tree

111 files changed

+260
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+260
-379
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# How to Contribute
22

33
We'd love to accept your patches and contributions to this project.
4-
We do have some guidelines to follow, covered in this document, but don't
4+
We do have some guidelines to follow, covered in this document, but don't
55
worry about (or expect to) get everything right the first time!
6-
Create a pull request and we'll nudge you in the right direction. Please also
6+
Create a pull request and we'll nudge you in the right direction. Please also
77
note that we have a [code of conduct](CODE_OF_CONDUCT.md) to make Cirq an
88
open and welcoming environment.
99

@@ -83,7 +83,7 @@ on setting up your local development environment.
8383

8484
## Code Testing Standards
8585

86-
When a pull request is created or updated, various automatic checks will
86+
When a pull request is created or updated, various automatic checks will
8787
run to ensure that the change won't break Cirq and meets our coding standards.
8888
8989
Cirq contains a continuous integration tool to verify testing. See our
@@ -94,36 +94,36 @@ Please be aware of the following code standards that will be applied to any
9494
new changes.
9595
9696
- **Tests**.
97-
Existing tests must continue to pass (or be updated) when new changes are
98-
introduced. We use [pytest](https://docs.pytest.org/en/latest/) to run our
97+
Existing tests must continue to pass (or be updated) when new changes are
98+
introduced. We use [pytest](https://docs.pytest.org/en/latest/) to run our
9999
tests.
100100
- **Coverage**.
101101
Code should be covered by tests.
102-
We use [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/) to compute
102+
We use [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/) to compute
103103
coverage, and custom tooling to filter down the output to only include new or
104-
changed code. We don't require 100% coverage, but any uncovered code must
105-
be annotated with `# coverage: ignore`. To ignore coverage of a single line,
106-
place `# coverage: ignore` at the end of the line. To ignore coverage for
107-
an entire block, start the block with a `# coverage: ignore` comment on its
104+
changed code. We don't require 100% coverage, but any uncovered code must
105+
be annotated with `# pragma: no cover`. To ignore coverage of a single line,
106+
place `# pragma: no cover` at the end of the line. To ignore coverage for
107+
an entire block, start the block with a `# pragma: no cover` comment on its
108108
own line.
109109
- **Lint**.
110-
Code should meet common style standards for python and be free of error-prone
110+
Code should meet common style standards for python and be free of error-prone
111111
constructs. We use [pylint](https://www.pylint.org/) to check for lint.
112-
To see which lint checks we enforce, see the
112+
To see which lint checks we enforce, see the
113113
[dev_tools/conf/.pylintrc](dev_tools/conf/.pylintrc) file. When pylint produces
114-
a false positive, it can be squashed with annotations like
114+
a false positive, it can be squashed with annotations like
115115
`# pylint: disable=unused-import`.
116116
- **Types**.
117117
Code should have [type annotations](https://www.python.org/dev/peps/pep-0484/).
118118
We use [mypy](http://mypy-lang.org/) to check that type annotations are correct.
119-
When type checking produces a false positive, it can be ignored with
119+
When type checking produces a false positive, it can be ignored with
120120
annotations like `# type: ignore`.
121121

122122
## Request For Comment Process for New Major Features
123123

124-
For larger contributions that will benefit from design reviews, please use the
124+
For larger contributions that will benefit from design reviews, please use the
125125
[Request for Comment](docs/dev/rfc_process.md) process.
126126

127-
## Developing notebooks
127+
## Developing notebooks
128128

129-
Please refer to our [notebooks guide](docs/dev/notebooks.md) on how to develop iPython notebooks for documentation.
129+
Please refer to our [notebooks guide](docs/dev/notebooks.md) on how to develop iPython notebooks for documentation.

cirq-core/cirq/_version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
import sys
1919

20-
if sys.version_info < (3, 9, 0):
21-
# coverage: ignore
20+
if sys.version_info < (3, 9, 0): # pragma: no cover
2221
raise SystemError(
2322
"You installed the latest version of cirq but aren't on python 3.9+.\n"
2423
'To fix this error, you need to either:\n'

cirq-core/cirq/circuits/circuit_operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def _full_join_string_lists(
6161
list1: Optional[Sequence[str]], list2: Optional[Sequence[str]]
6262
) -> Optional[Sequence[str]]:
6363
if list1 is None and list2 is None:
64-
return None # coverage: ignore
64+
return None # pragma: no cover
6565
if list1 is None:
66-
return list2 # coverage: ignore
66+
return list2 # pragma: no cover
6767
if list2 is None:
6868
return list1
6969
return [f'{first}{REPETITION_ID_SEPARATOR}{second}' for first in list1 for second in list2]

cirq-core/cirq/circuits/qasm_output_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _qasm_(self, args: cirq.QasmArgs) -> str:
257257

258258
def _decompose_(self):
259259
# Only used by test_output_unitary_same_as_qiskit
260-
return () # coverage: ignore
260+
return () # pragma: no cover
261261

262262
class DummyCompositeOperation(cirq.Operation):
263263
qubits = (q0,)

cirq-core/cirq/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def pytest_configure(config):
2727

2828
def pytest_pyfunc_call(pyfuncitem):
2929
if inspect.iscoroutinefunction(pyfuncitem._obj):
30-
# coverage: ignore
31-
raise ValueError(
30+
raise ValueError( # pragma: no cover
3231
f'{pyfuncitem._obj.__name__} is a bare async function. '
3332
f'It should be decorated with "@duet.sync".'
3433
)

cirq-core/cirq/contrib/acquaintance/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class _UnconstrainedAcquaintanceDevice(AcquaintanceDevice):
6868
"""An acquaintance device with no constraints other than of the gate types."""
6969

7070
def __repr__(self) -> str:
71-
return 'UnconstrainedAcquaintanceDevice' # coverage: ignore
71+
return 'UnconstrainedAcquaintanceDevice' # pragma: no cover
7272

7373

7474
UnconstrainedAcquaintanceDevice = _UnconstrainedAcquaintanceDevice()

cirq-core/cirq/contrib/hacks/disable_validation_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_disable_op_validation():
2929
with pytest.raises(ValueError, match='mysterious and terrible'):
3030
with disable_op_validation():
3131
# This does not run - the with condition errors out first.
32-
_ = cirq.H(q0, q1) # coverage: ignore
32+
_ = cirq.H(q0, q1) # pragma: no cover
3333

3434
# Passes, skipping validation.
3535
with disable_op_validation(accept_debug_responsibility=True):

cirq-core/cirq/contrib/noise_models/noise_models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def __init__(self, depol_prob: float, prepend: bool = False):
4141
self._prepend = prepend
4242

4343
def noisy_moment(self, moment: 'cirq.Moment', system_qubits: Sequence['cirq.Qid']):
44-
if validate_all_measurements(moment) or self.is_virtual_moment(moment):
45-
# coverage: ignore
44+
if validate_all_measurements(moment) or self.is_virtual_moment(moment): # pragma: no cover
4645
return moment
4746

4847
output = [

cirq-core/cirq/contrib/paulistring/clifford_optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def try_merge_cz(cz_op: ops.GateOperation, start_i: int) -> int:
161161
else:
162162
# Two CZ gates that share one qubit
163163
# Pass through and keep looking
164-
continue # coverage: ignore
164+
continue # pragma: no cover
165165
# The above line is covered by test_remove_staggered_czs but the
166166
# coverage checker disagrees.
167167
return 0

cirq-core/cirq/contrib/qcircuit/qcircuit_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# coverage: ignore
15+
# pragma: no cover
1616

1717
import errno
1818
import os

0 commit comments

Comments
 (0)