Skip to content

Commit

Permalink
codecov - fix syntax for excluding code lines from coverage (#6240)
Browse files Browse the repository at this point in the history
The `coverage` tool understands `# pragma: no cover` markup comments to exclude
code lines from coverage analysis.    The previous syntax `# coverage: ignore`
had no effect and resulted in spurious coverage changes for a different code
paths taken.

Removing the codecov.yml file, because coverage precision had no effect on
codecov complaints about decreased coverage.
  • Loading branch information
pavoljuhas authored Aug 15, 2023
1 parent c193c48 commit 2fcdeb8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cirq-core/cirq/circuits/circuit_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_repeat_zero_times(add_measurements, use_repetition_ids, initial_reps):


def test_no_repetition_ids():
def default_repetition_ids(self):
def default_repetition_ids(self): # pragma: no cover
assert False, "Should not call default_repetition_ids"

with mock.patch.object(circuit_operation, 'default_repetition_ids', new=default_repetition_ids):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ def two_qubit_gate_product_tabulation(
# If all KAK vectors in the mesh have been tabulated, return.
missing_vec_inds = np.logical_not(tabulated_kak_inds).nonzero()[0]

if not np.any(missing_vec_inds):
# coverage: ignore
if not np.any(missing_vec_inds): # pragma: no cover
return TwoQubitGateTabulation(
base_gate, np.array(kak_vecs), sq_cycles, max_infidelity, summary, ()
)
Expand Down
2 changes: 0 additions & 2 deletions codecov.yml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/bernstein_vazirani.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def make_oracle(input_qubits, output_qubit, secret_factor_bits, secret_bias_bit)
yield cirq.X(output_qubit)

for qubit, bit in zip(input_qubits, secret_factor_bits):
if bit:
if bit: # pragma: no cover
yield cirq.CNOT(qubit, output_qubit)


Expand Down
5 changes: 2 additions & 3 deletions examples/deutsch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ def main():
def make_oracle(q0, q1, secret_function):
"""Gates implementing the secret function f(x)."""

# coverage: ignore
if secret_function[0]:
if secret_function[0]: # pragma: no cover
yield [CNOT(q0, q1), X(q1)]

if secret_function[1]:
if secret_function[1]: # pragma: no cover
yield CNOT(q0, q1)


Expand Down
15 changes: 7 additions & 8 deletions examples/shor.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ def quantum_order_finder(x: int, n: int) -> Optional[int]:
eigenphase = read_eigenphase(result)
f = fractions.Fraction.from_float(eigenphase).limit_denominator(n)
if f.numerator == 0:
return None # coverage: ignore
return None # pragma: no cover
r = f.denominator
if x**r % n != 1:
return None # coverage: ignore
return None # pragma: no cover
return r


Expand Down Expand Up @@ -311,18 +311,18 @@ def find_factor(
x = random.randint(2, n - 1)
c = math.gcd(x, n)
if 1 < c < n:
return c # coverage: ignore
return c # pragma: no cover
r = order_finder(x, n)
if r is None:
continue # coverage: ignore
continue # pragma: no cover
if r % 2 != 0:
continue # coverage: ignore
continue # pragma: no cover
y = x ** (r // 2) % n
assert 1 < y < n
c = math.gcd(y - 1, n)
if 1 < c < n:
return c
return None # coverage: ignore
return None # pragma: no cover


def main(n: int, order_finder: Callable[[int, int], Optional[int]] = naive_order_finder):
Expand All @@ -340,8 +340,7 @@ def main(n: int, order_finder: Callable[[int, int], Optional[int]] = naive_order
assert n % d == 0


if __name__ == '__main__':
# coverage: ignore
if __name__ == '__main__': # pragma: no cover
ORDER_FINDERS = {'naive': naive_order_finder, 'quantum': quantum_order_finder}
args = parser.parse_args()
main(n=args.n, order_finder=ORDER_FINDERS[args.order_finder])

0 comments on commit 2fcdeb8

Please sign in to comment.