Skip to content

No automated tests for the Python layer (bin/python/) #5

Description

@corgab

Problem

The PHP side is well covered (Pest, ~90% line coverage), but the Python scripts in bin/python/ have no automated tests and no test harness. This is now a concrete gap because circuit.py contains non-trivial pure logic:

  • _validate_gates() — qubit-index range validation, measure targets handling, the isinstance(index, bool) guard, and the _QUBIT_INDEX_KEYS allowlist that must stay in sync with _build_circuit().

These are exactly the kind of guards that get silently broken by a future refactor with nothing to catch the regression. Today they are only verified by ad-hoc manual invocation.

Proposal

  • Add a minimal pytest harness under bin/python/ (e.g. tests/ + requirements-dev.txt with pytest).
  • _validate_gates() and _build_circuit's gate-dispatch are importable without the Braket SDK (braket is imported lazily inside the functions), so the validation logic can be unit-tested with no AWS/Braket dependency.
  • Cover: valid circuits pass; out-of-range / negative / non-int indices raise ValueError; scalar measure.targets; measure-all (null); unknown gate type.
  • Wire pytest into the CI workflow (.github/workflows/tests.yml) as a separate step.

Acceptance

  • pytest runs in CI and covers _validate_gates (and ideally _build_circuit with a mocked/stubbed Braket Circuit).
  • The bool-is-int guard and the _QUBIT_INDEX_KEYS/_build_circuit coupling have explicit regression tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions