Skip to content

test(py): add coverage for PyO3 bindings + gallery round-trip#43

Merged
lostmygithubaccount merged 1 commit into
mainfrom
agent3/py-tests
Apr 13, 2026
Merged

test(py): add coverage for PyO3 bindings + gallery round-trip#43
lostmygithubaccount merged 1 commit into
mainfrom
agent3/py-tests

Conversation

@lostmygithubaccount
Copy link
Copy Markdown
Member

Summary

Grows the Python test suite from 5 tests to 27. Covers the full dkdc_draw.core surface (new/save/load/export SVG/export PNG) plus error paths, and exercises every element type via the committed examples/gallery/*.draw.json fixtures.

Files

  • `tests/test_core.py` (12 tests): unit tests per-function for the PyO3 surface + top-level re-export smoke test + error paths (nonexistent path, invalid JSON on save/svg/png).
  • `tests/test_gallery_roundtrip.py` (15 tests, 3 × 5 parameterized): for each gallery drawing (flowchart, sticky, wireframe, sketch, patterns): save-reload fixed point, SVG well-formed, PNG magic bytes + nontrivial size.
  • Deletes `tests/test_draw.py`: 4 of its 5 tests were narrower duplicates of the new test_core.py versions; its `HAS_NATIVE` ImportError guard was cargo-cult (the project ships via maturin and every test needs the native module). The unique smoke test (`test_import` / attr-hasattr loop) is preserved as `test_top_level_reexports_wrapper_api`.

How to run

```bash
bin/test-py # or
uv run pytest # or
bin/test # runs bin/test-rs + bin/test-py
```

Scope notes

Not added to `bin/check-py`. The existing convention is that `check-py` skips maturin+ty in CI (because `draw-app` needs GTK); adding pytest would need maturin too, so it'd be skipped in CI for the same reason. Keeping pytest on the `bin/test-py` path preserves the existing split: `check` = lint/type, `test` = execute.

`run_cli` is not covered — it's argv-driven and structural correctness is already covered by the Rust tests.

Test plan

  • `bin/test` green (31 rust + 27 python = 58 tests, all pass)
  • `bin/check` green

🤖 Generated with Claude Code

Grows the Python test suite from 5 tests (test_draw.py) to 27 across
two files:

  tests/test_core.py
    - top-level re-export smoke test (dkdc_draw → dkdc_draw.core)
    - new_document structure
    - save/load round-trip (empty + with element)
    - SVG well-formedness
    - PNG magic bytes, default scale, custom scale
    - error paths: nonexistent load, invalid JSON on save/svg/png

  tests/test_gallery_roundtrip.py
    - Uses the 5 committed examples/gallery/*.draw.json fixtures
      (flowchart, sticky, wireframe, sketch, patterns) to exercise
      every element type and fill pattern against the Python layer.
    - Per-slug: save-reload fixed point + SVG well-formed + PNG valid.

Deletes tests/test_draw.py — the 4 non-smoke tests were narrower
duplicates of the new test_core.py versions, and the `HAS_NATIVE`
ImportError guard was cargo-cult (the project ships via maturin and
every test needs the native module).

Run with `bin/test-py` or `uv run pytest`. Runs as part of `bin/test`.
Not added to `bin/check-py` to preserve the existing CI-skip pattern
(maturin+ty already local-only; tests follow suit).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lostmygithubaccount lostmygithubaccount merged commit 1e948b9 into main Apr 13, 2026
1 check passed
@lostmygithubaccount lostmygithubaccount deleted the agent3/py-tests branch April 13, 2026 05:24
lostmygithubaccount added a commit that referenced this pull request Apr 13, 2026
Bumps all Rust crates and the Python package from 0.2.1 to 0.3.0. This
minor bump reflects one breaking change in the dkdc-draw-core public API
surface (pub -> pub(crate) demotions in #42), accumulated with the
non-breaking work from this cycle:

  - #35: arrow snap-to-shape connection points
  - #36: CONTRIBUTING.md + README badges
  - #37: integration tests for draw-core public API
  - #38: Rust + Python hello-world examples
  - #39: CHANGELOG.md scaffolding
  - #40: surgical clippy opt-ins workspace-wide
  - #41: sample gallery (5 drawings × json/svg/png)
  - #42: pub -> pub(crate) demotions (BREAKING)
  - #43: Python test coverage 5 -> 27

See CHANGELOG.md for the 0.3.0 section and migration notes for the
demoted symbols.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lostmygithubaccount lostmygithubaccount mentioned this pull request Apr 13, 2026
4 tasks
lostmygithubaccount added a commit that referenced this pull request Apr 13, 2026
Bumps all Rust crates and the Python package from 0.2.1 to 0.3.0. This
minor bump reflects one breaking change in the dkdc-draw-core public API
surface (pub -> pub(crate) demotions in #42), accumulated with the
non-breaking work from this cycle:

  - #35: arrow snap-to-shape connection points
  - #36: CONTRIBUTING.md + README badges
  - #37: integration tests for draw-core public API
  - #38: Rust + Python hello-world examples
  - #39: CHANGELOG.md scaffolding
  - #40: surgical clippy opt-ins workspace-wide
  - #41: sample gallery (5 drawings × json/svg/png)
  - #42: pub -> pub(crate) demotions (BREAKING)
  - #43: Python test coverage 5 -> 27

See CHANGELOG.md for the 0.3.0 section and migration notes for the
demoted symbols.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant