From 519b6e199580105a0c2a9401a4f22fcf7783d573 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Wed, 15 Nov 2023 16:54:59 +0000 Subject: [PATCH] Remove `print` calls from test suite This removes some debugging `print` statements from the test suite, to avoid noise in the test-runner output. In some cases, the `print` was only part of an assertion that the conversion to string fails, and these were converted to explicit calls to `str`. This isn't strictly necessary, it's just trying to get the test suite out of the habit of using `print`. --- .../circuit/library/test_functional_pauli_rotations.py | 6 +++--- test/python/circuit/library/test_integer_comparator.py | 4 ++-- test/python/circuit/library/test_nlocal.py | 2 +- test/python/circuit/library/test_permutation.py | 1 - test/python/circuit/library/test_piecewise_chebyshev.py | 2 +- test/python/circuit/library/test_weighted_adder.py | 4 ++-- test/python/circuit/test_piecewise_polynomial.py | 2 +- test/python/primitives/test_backend_sampler.py | 1 - test/python/primitives/test_sampler.py | 2 -- .../quantum_info/operators/symplectic/test_clifford.py | 3 ++- 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test/python/circuit/library/test_functional_pauli_rotations.py b/test/python/circuit/library/test_functional_pauli_rotations.py index 38f6568f117a..294a2b3282f0 100644 --- a/test/python/circuit/library/test_functional_pauli_rotations.py +++ b/test/python/circuit/library/test_functional_pauli_rotations.py @@ -84,7 +84,7 @@ def test_polynomial_rotations_mutability(self): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): # no state qubits set - print(polynomial_rotations.draw()) + _ = str(polynomial_rotations.draw()) with self.subTest(msg="default setup, just setting number of state qubits"): polynomial_rotations.num_state_qubits = 2 @@ -121,7 +121,7 @@ def test_linear_rotations_mutability(self): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): # no state qubits set - print(linear_rotation.draw()) + _ = str(linear_rotation.draw()) with self.subTest(msg="default setup, just setting number of state qubits"): linear_rotation.num_state_qubits = 2 @@ -171,7 +171,7 @@ def test_piecewise_linear_rotations_mutability(self): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): # no state qubits set - print(pw_linear_rotations.draw()) + _ = str(pw_linear_rotations.draw()) with self.subTest(msg="default setup, just setting number of state qubits"): pw_linear_rotations.num_state_qubits = 2 diff --git a/test/python/circuit/library/test_integer_comparator.py b/test/python/circuit/library/test_integer_comparator.py index 2c6459cf38e3..55bd2b9071af 100644 --- a/test/python/circuit/library/test_integer_comparator.py +++ b/test/python/circuit/library/test_integer_comparator.py @@ -71,13 +71,13 @@ def test_mutability(self): with self.subTest(msg="missing num state qubits and value"): with self.assertRaises(AttributeError): - print(comp.draw()) + _ = str(comp.draw()) comp.num_state_qubits = 2 with self.subTest(msg="missing value"): with self.assertRaises(AttributeError): - print(comp.draw()) + _ = str(comp.draw()) comp.value = 0 comp.geq = True diff --git a/test/python/circuit/library/test_nlocal.py b/test/python/circuit/library/test_nlocal.py index f20377368ed4..62e7912606b8 100644 --- a/test/python/circuit/library/test_nlocal.py +++ b/test/python/circuit/library/test_nlocal.py @@ -378,7 +378,7 @@ def test_pairwise_entanglement_raises(self): # pairwise entanglement is only defined if the entangling gate has 2 qubits with self.assertRaises(ValueError): - print(nlocal.draw()) + _ = str(nlocal.draw()) def test_entanglement_by_list(self): """Test setting the entanglement by list. diff --git a/test/python/circuit/library/test_permutation.py b/test/python/circuit/library/test_permutation.py index bf4da582b6ad..25bfa0bfae49 100644 --- a/test/python/circuit/library/test_permutation.py +++ b/test/python/circuit/library/test_permutation.py @@ -170,7 +170,6 @@ def test_qpy(self): circuit.cx(0, 1) circuit.append(PermutationGate([1, 2, 0]), [2, 4, 5]) circuit.h(4) - print(circuit) qpy_file = io.BytesIO() dump(circuit, qpy_file) diff --git a/test/python/circuit/library/test_piecewise_chebyshev.py b/test/python/circuit/library/test_piecewise_chebyshev.py index 4b8cb6054e1d..c721fe47ee67 100644 --- a/test/python/circuit/library/test_piecewise_chebyshev.py +++ b/test/python/circuit/library/test_piecewise_chebyshev.py @@ -103,7 +103,7 @@ def f_x_1(x): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): # no state qubits set - print(pw_approximation.draw()) + _ = str(pw_approximation.draw()) with self.subTest(msg="default setup, just setting number of state qubits"): pw_approximation.num_state_qubits = 2 diff --git a/test/python/circuit/library/test_weighted_adder.py b/test/python/circuit/library/test_weighted_adder.py index 7bfe614e0bd6..db33156aa0a2 100644 --- a/test/python/circuit/library/test_weighted_adder.py +++ b/test/python/circuit/library/test_weighted_adder.py @@ -67,7 +67,7 @@ def test_mutability(self): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): - print(adder.draw()) + _ = str(adder.draw()) with self.subTest(msg="default weights"): adder.num_state_qubits = 3 @@ -81,7 +81,7 @@ def test_mutability(self): with self.subTest(msg="mismatching number of state qubits and weights"): with self.assertRaises(ValueError): adder.weights = [0, 1, 2, 3] - print(adder.draw()) + _ = str(adder.draw()) with self.subTest(msg="change all attributes"): adder.num_state_qubits = 4 diff --git a/test/python/circuit/test_piecewise_polynomial.py b/test/python/circuit/test_piecewise_polynomial.py index 9bc34179ba63..e84cc35de87b 100644 --- a/test/python/circuit/test_piecewise_polynomial.py +++ b/test/python/circuit/test_piecewise_polynomial.py @@ -101,7 +101,7 @@ def pw_poly(x): with self.subTest(msg="missing number of state qubits"): with self.assertRaises(AttributeError): # no state qubits set - print(pw_polynomial_rotations.draw()) + _ = str(pw_polynomial_rotations.draw()) with self.subTest(msg="default setup, just setting number of state qubits"): pw_polynomial_rotations.num_state_qubits = 2 diff --git a/test/python/primitives/test_backend_sampler.py b/test/python/primitives/test_backend_sampler.py index 86dc709f8983..971104af9870 100644 --- a/test/python/primitives/test_backend_sampler.py +++ b/test/python/primitives/test_backend_sampler.py @@ -117,7 +117,6 @@ def test_sample_run_multiple_circuits(self, backend): bell = self._circuit[1] sampler = BackendSampler(backend=backend) result = sampler.run([bell, bell, bell]).result() - # print([q.binary_probabilities() for q in result.quasi_dists]) self._compare_probs(result.quasi_dists[0], self._target[1]) self._compare_probs(result.quasi_dists[1], self._target[1]) self._compare_probs(result.quasi_dists[2], self._target[1]) diff --git a/test/python/primitives/test_sampler.py b/test/python/primitives/test_sampler.py index 2dc2aac11098..fac9a250a9e9 100644 --- a/test/python/primitives/test_sampler.py +++ b/test/python/primitives/test_sampler.py @@ -93,7 +93,6 @@ def test_sampler_run(self): self.assertIsInstance(job, JobV1) result = job.result() self.assertIsInstance(result, SamplerResult) - # print([q.binary_probabilities() for q in result.quasi_dists]) self._compare_probs(result.quasi_dists, self._target[1]) def test_sample_run_multiple_circuits(self): @@ -103,7 +102,6 @@ def test_sample_run_multiple_circuits(self): bell = self._circuit[1] sampler = Sampler() result = sampler.run([bell, bell, bell]).result() - # print([q.binary_probabilities() for q in result.quasi_dists]) self._compare_probs(result.quasi_dists[0], self._target[1]) self._compare_probs(result.quasi_dists[1], self._target[1]) self._compare_probs(result.quasi_dists[2], self._target[1]) diff --git a/test/python/quantum_info/operators/symplectic/test_clifford.py b/test/python/quantum_info/operators/symplectic/test_clifford.py index 76cd9463f00e..615f09e6ad21 100644 --- a/test/python/quantum_info/operators/symplectic/test_clifford.py +++ b/test/python/quantum_info/operators/symplectic/test_clifford.py @@ -1044,7 +1044,8 @@ def test_visualize_does_not_throw_error(self): # An error may be thrown if visualization code calls op.condition instead # of getattr(op, "condition", None) clifford = random_clifford(3, seed=0) - print(clifford) + _ = str(clifford) + _ = repr(clifford) @combine(num_qubits=[1, 2, 3, 4]) def test_from_matrix_round_trip(self, num_qubits):