Skip to content

[DRAFT] test: cover behavior gaps surfaced by external review#14

Draft
speckhard wants to merge 2 commits intoLeMaterial:mainfrom
speckhard:test/coverage-gaps
Draft

[DRAFT] test: cover behavior gaps surfaced by external review#14
speckhard wants to merge 2 commits intoLeMaterial:mainfrom
speckhard:test/coverage-gaps

Conversation

@speckhard
Copy link
Copy Markdown

@speckhard speckhard commented Apr 29, 2026

Summary

Pure test additions — no production code changes. Each test pins or exercises a documented public-API contract that previously had no coverage. Surfaced by external code review.

What's tested

test_database.py (+3 tests, +1 parametrize value)

  • test_database_open_mmap_populateDatabase.open(path, mmap=True, populate=True). Smoke test only on macOS (memmap2 PopulateRead advise is best-effort there); pre-faulting performance is a benchmark concern, not a unit-test one. Documented in the test docstring.
  • test_database_negative_indexing_raises_overflow_error — pins the actual current exception (OverflowError from PyO3's usize extraction) and its message. If wraparound semantics are ever added, this test will fail loudly.
  • test_database_empty_molecule_roundtripn_atoms == 0 round-trip through the SOA encoder and parser. The 0-atom path has no upstream guard; this test exercises it end-to-end.
  • lz4 added to four mmap-parametrized tests (test_database_single_item_reads_are_view_compatible, ..._custom_array_properties_roundtrip_all_numeric_tags, ..._single_item_mutation_is_copy_on_write, ..._single_item_pickle_materializes_owned_roundtrip). The basic lz4+mmap=True path was already covered by test_database_roundtrip[lz4], but the deeper mutation/pickle/view round-trips ran only ["none", "zstd"].

test_atom_molecule.py (+3)

  • test_from_arrays_rejects_wrong_dtype_positions and ..._atomic_numbers — wrong numpy dtypes (float64 positions, int64 atomic numbers) must error cleanly across the PyO3 boundary, not silently truncate or panic.
  • test_set_property_python_bool_pins_current_behavior — locks in that mol.set_property(key, True) stores Int(1) because Python bool is an int subclass and PyO3 extracts i64 before f64. If anyone wants real bool storage, this test will fail loudly so the design choice is explicit.

test_from_ase.py (+1)

  • test_from_ase_expands_voigt6_stress_to_3x3 — covers ase_bridge._voigt6_to_mat3x3. ASE's get_stress(voigt=True) returns a (6,) Voigt-form vector and the bridge must expand it to a (3,3) symmetric tensor. The test asserts both the exact element mapping and matrix symmetry.

Test plan

  • Full suite green; new tests counted:
$ uv run --extra dev --locked --with "maturin>=1.4,<2.0" maturin develop --release
🛠 Installed atompack-db-0.2.1

$ uv run --extra dev --locked pytest tests/ -q
154 passed, 1 skipped in 6.95s   # with ASE installed

(test_from_ase.py is gated by pytest.importorskip("ase") like the rest of the file; the Voigt test runs only when ASE is available. Without ASE, the suite still passes — the test_from_ase module is module-level skipped.)

  • Each new test runs and passes individually (verified with -v).

What this is not

No production code changes, no API changes, no fixture changes. Risk surface is zero — this PR can only fail by running tests against unmerged behavior changes. All assertions are against current main semantics.

Pure test additions; no production code changes. Each test pins or
exercises a documented public-API contract that previously had no
coverage.

test_database.py:
- test_database_open_mmap_populate covers Database.open(populate=True),
  the documented Linux page-prefault path which had no smoke test.
- test_database_negative_indexing_raises_index_error pins that
  Database[-1] is not currently supported (raises IndexError /
  OverflowError / ValueError) — locks in the contract until someone
  intentionally adds wraparound.
- test_database_empty_molecule_roundtrip exercises n_atoms == 0 through
  the SOA encoder + parser (the empty-positions slice edge case).

test_atom_molecule.py:
- test_from_arrays_rejects_wrong_dtype_positions and the analogous
  atomic_numbers test confirm that wrong dtypes raise cleanly across the
  PyO3 boundary instead of silently truncating or panicking.
- test_set_property_python_bool_pins_current_behavior locks in that
  Python bool is stored as Int(1/0) because bool is a subclass of int
  and PyO3 extracts i64 before f64. If anyone wants real bool storage,
  this test will fail loudly.

test_from_ase.py:
- test_from_ase_expands_voigt6_stress_to_3x3 covers the bridge's
  _voigt6_to_mat3x3 path; ASE's get_stress(voigt=True) returns (6,) and
  the bridge must expand it before storing as a 3x3 tensor.
- test_database_negative_indexing_raises_overflow_error pins the actual
  current exception (OverflowError from PyO3 usize extraction) and the
  message; previously the test caught a permissive (IndexError,
  OverflowError, ValueError) tuple that would have masked any future
  silent change.
- test_database_open_mmap_populate now documents that the assertion is
  smoke-only on macOS (memmap2 PopulateRead advise is best-effort there);
  pre-faulting performance is a benchmark concern, not a unit-test one.
- Add "lz4" to the four mmap-parametrized tests in test_database.py
  (single_item_reads_are_view_compatible, custom_array_properties_...,
  single_item_mutation_is_copy_on_write, single_item_pickle_...). The
  basic lz4+mmap=True path was covered by test_database_roundtrip[lz4]
  but the deeper mutation/pickle/view round-trips were not.
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