Skip to content

test: add coverage for lab_results dir loading and toxicity flag branches - #80

Merged
cschanhniem merged 2 commits into
mainfrom
feat/test-coverage-lab-results-batch-pack
Jun 28, 2026
Merged

cschanhniem merged 2 commits into
mainfrom
feat/test-coverage-lab-results-batch-pack

Conversation

@cschanhniem

Copy link
Copy Markdown
Collaborator

Summary

Two modules had meaningful coverage gaps that are now closed.

data/lab_results.py: 74% → 100%

load_lab_results_dir() was completely untested (all 12 lines uncovered). This function is the primary entry point for reading wet-lab assay results in the active-learning loop — if it silently drops malformed result files, the active-learning cycle would feed the next generation with a corrupted dataset.

Added TestLoadLabResultsDir with 7 tests:

  • test_empty_directory_returns_empty_list
  • test_loads_all_valid_files
  • test_sorted_by_assay_date
  • test_sorted_by_result_id_within_same_date
  • test_skips_invalid_json_file_with_warning — confirms malformed JSON triggers a Python warning and the valid files still load
  • test_skips_schema_invalid_file_with_warning — confirms schema violations are skipped safely
  • test_non_json_files_ignored

reports/batch_pack.py: 97% → 100%

Five branches uncovered:

  • _toxicity_flags() had 4 branch-true paths untested: high_charge_density, high_cysteine_fraction, long_repeat_run, length_exceeds_35aa
  • write_batch_pack_markdown() had the cluster-truncation footer ("| … | … | (N more clusters)") untested — only triggered with >20 distinct clusters

Added 6 new tests to TestToxicityHemolysisRiskReport and TestWriteBatchPackMarkdown:

  • test_high_charge_density_flagged
  • test_high_cysteine_fraction_flagged
  • test_long_repeat_run_flagged
  • test_length_exceeds_35aa_flagged
  • test_n_with_risk_flags_counts_correctly
  • test_markdown_truncates_clusters_beyond_20

Metrics

Before After
Tests 1245 1258 (+13)
Coverage 87.40% 88.22% (+0.82 pp)
lab_results.py 74% 100%
batch_pack.py 97% 100%

Test plan

  • make coverage → 1258 passed, 88.22%
  • No production code changed — test-only PR

🤖 Generated with Claude Code

…lags

data/lab_results.py: 74% → 100%
- load_lab_results_dir() was completely untested (lines 40-54 uncovered)
- Added TestLoadLabResultsDir with 7 tests:
  empty directory, load all valid files, sort by assay_date,
  sort by result_id within same date, skip invalid JSON with warning,
  skip schema-invalid files with warning, ignore non-.json files
- This function is the entry point for wet-lab result ingestion in the
  active-learning loop — covering it is scientifically important

reports/batch_pack.py: 97% → 100%
- Four _toxicity_flags() branches uncovered (charge_density, cysteine_fraction,
  longest_repeat_run, length_exceeds_35aa)
- Cluster truncation line (>20 clusters → "more clusters" footer) uncovered
- Added 6 new tests in TestToxicityHemolysisRiskReport and
  TestWriteBatchPackMarkdown to cover all remaining branches

Overall coverage: 87.40% → 88.22% (+0.82 pp, 13 fewer uncovered lines)
1258 tests (was 1245)
HIGH:
- test_sorted_by_assay_date: file creation order and date order were
  identical (RES-000→2026-07-01, etc.) so the sort was never exercised.
  Rewrote to use out-of-order dates (0→03, 1→01, 2→02) and assert the
  first result has the earliest date — a genuine regression test now.

- test_skips_schema_invalid_file_with_warning: added identity assertion
  `results[0]["result_id"] == "GOOD-001"` matching the pattern from the
  sibling JSON-parse test; prevents a silent inversion where the wrong
  file is retained.

LOW:
- test_length_exceeds_35aa_flagged: sequence is 36 AA (not 37), corrected
  comment; removed redundant explicit features["length"] override since
  _make_candidate already derives length from len(sequence)
@cschanhniem
cschanhniem merged commit cbf32d1 into main Jun 28, 2026
2 checks passed
@cschanhniem
cschanhniem deleted the feat/test-coverage-lab-results-batch-pack branch June 28, 2026 15:42
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