88import numpy as np
99
1010from common .hamiltonian import build_hamiltonian
11+ import qpe .__main__ as qpe_main
1112from qpe import run_qpe
1213from qpe .visualize import plot_qpe_distribution
1314
@@ -189,12 +190,23 @@ def test_qpe_distribution_displays_right_to_left_kets(monkeypatch) -> None:
189190 assert labels == ["|00⟩" , "|01⟩" , "|10⟩" , "|11⟩" ]
190191
191192
192- def test_qpe_cli_supports_explicit_geometry () -> None :
193- p = subprocess .run (
193+ def test_qpe_cli_supports_explicit_geometry (monkeypatch , capsys ) -> None :
194+ captured : dict [str , object ] = {}
195+
196+ def fake_run_qpe (** kwargs ):
197+ captured .update (kwargs )
198+ return {
199+ "best_bitstring" : "0" ,
200+ "energy" : - 1.0 ,
201+ "hf_energy" : - 0.9 ,
202+ "num_qubits" : 4 ,
203+ }
204+
205+ monkeypatch .setattr (qpe_main , "ensure_dirs" , lambda : None )
206+ monkeypatch .setattr (qpe_main , "run_qpe" , fake_run_qpe )
207+
208+ qpe_main .main (
194209 [
195- sys .executable ,
196- "-m" ,
197- "qpe" ,
198210 "--symbols" ,
199211 "H,H" ,
200212 "--coordinates" ,
@@ -208,18 +220,27 @@ def test_qpe_cli_supports_explicit_geometry() -> None:
208220 "--shots" ,
209221 "50" ,
210222 "--force" ,
211- ],
212- check = False ,
213- capture_output = True ,
214- text = True ,
215- timeout = 20 ,
223+ ]
216224 )
225+ out = capsys .readouterr ().out
217226
218- assert p .returncode == 0
219- assert "QPE completed" in p .stdout
220- assert "system=4, ancillas=1" in p .stdout
227+ assert captured ["molecule" ] == "H2"
228+ assert captured ["symbols" ] == ["H" , "H" ]
229+ assert np .array_equal (
230+ captured ["coordinates" ],
231+ np .array ([[0.0 , 0.0 , 0.0 ], [0.0 , 0.0 , 0.7 ]], dtype = float ),
232+ )
233+ assert captured ["charge" ] == 0
234+ assert captured ["basis" ] == "sto-3g"
235+ assert captured ["n_ancilla" ] == 1
236+ assert captured ["shots" ] == 50
237+ assert captured ["force" ] is True
238+ assert "QPE completed" in out
239+ assert "system=4, ancillas=1" in out
221240
222241
242+ @pytest .mark .slow
243+ @pytest .mark .cli_subprocess
223244def test_qpe_cli_returns_nonzero_on_failure () -> None :
224245 p = subprocess .run (
225246 [sys .executable , "-m" , "qpe" , "--molecule" , "DOES_NOT_EXIST" ],
0 commit comments