Skip to content

Commit d69b05f

Browse files
committed
test(py): check roundtrip through CLI
1 parent cafc964 commit d69b05f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

hugr-py/tests/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,30 @@ def validate(
169169
dot.pipe("svg")
170170
else:
171171
# Package
172+
# first python roundtrip
172173
encoded = h.to_str(EnvelopeConfig.TEXT)
173174
loaded = Package.from_str(encoded)
174175
roundtrip_encoded = loaded.to_str(EnvelopeConfig.TEXT)
175176
assert encoded == roundtrip_encoded
176177

178+
# then roundtrip through the CLI
177179

178-
def _run_hugr_cmd(serial: bytes, cmd: list[str]):
180+
# TODO once model loading is supported in Python
181+
# try every combo of input and output formats
182+
cmd = [*_base_command(), "convert", "-", "--text"]
183+
184+
serial = h.to_bytes(EnvelopeConfig.BINARY)
185+
out = _run_hugr_cmd(serial, cmd)
186+
loaded = Package.from_bytes(out.stdout)
187+
188+
189+
def _run_hugr_cmd(serial: bytes, cmd: list[str]) -> subprocess.CompletedProcess[bytes]:
179190
"""Run a HUGR command.
180191
181192
The `serial` argument is the serialized HUGR to pass to the command via stdin.
182193
"""
183194
try:
184-
subprocess.run(cmd, check=True, input=serial, capture_output=True) # noqa: S603
195+
return subprocess.run(cmd, check=True, input=serial, capture_output=True) # noqa: S603
185196
except subprocess.CalledProcessError as e:
186197
error = e.stderr.decode()
187198
raise RuntimeError(error) from e

0 commit comments

Comments
 (0)