Skip to content

[medgan-pr-prep] T8: Integration tests (8 MECE in-memory + 4 MIMIC-III skip-gracefully) #44

@jalengg

Description

@jalengg

Goal

Create tests/integration/test_medgan_end_to_end.py covering all 8 integration seams, following the same bootstrap pattern used for CorGAN.

Bootstrap pattern

Same as CorGAN: stub pyhealth.datasets and pyhealth.models via sys.modules, load model via importlib.util.spec_from_file_location. This avoids litdata/pyarrow/dask import failures in CI.

Small test config

_SMALL_MODEL_KWARGS = {
    "latent_dim": 4,
    "hidden_dim": 4,
    "autoencoder_hidden_dim": 4,
    "discriminator_hidden_dim": 8,
    "ae_epochs": 1,
    "gan_epochs": 1,
    "batch_size": 4,
    "save_dir": None,
}

Sample data: flat list ["A", "B", "C"] (5–8 codes per patient, ≥4 patients).

Category A tests (8, always run)

Test Seam
TestMedGANIsBaseModelInstance Inheritance contract
TestMedGANFeatureKeys model.feature_keys == ["visits"]
TestMedGANInputDim model.input_dim == processor.size()
TestMedGANForwardRaisesNotImplementedError forward() contract
TestMedGANTrainModelRuns Training loop (compute)
TestMedGANSynthesizeCount synthesize_dataset(5) returns 5 dicts
TestMedGANSynthesizeOutputStructure Output is flat list of str (not nested)
TestMedGANSaveLoadRoundtrip Checkpoint I/O

Category B tests (4, skip when MIMIC-III absent)

_MIMIC3_PATH = os.environ.get(
    "PYHEALTH_MIMIC3_PATH",
    "/srv/local/data/physionet.org/files/mimiciii/1.4",
)
Test What it verifies
TestMedGANMIMIC3TaskFunction MedGANGenerationMIMIC3 produces valid samples
TestMedGANMIMIC3FullPipeline Dataset → task → model → train (1 epoch)
TestMedGANMIMIC3Synthesize100 synthesize_dataset(100) succeeds
TestMedGANMIMIC3SynthesizeCodeQuality All generated codes exist in training vocab

Resource cleanup

Every test using tempfile.mkdtemp() must have tearDown: shutil.rmtree(self.tmpdir, ignore_errors=True).

Acceptance criteria

  • All 8 Category A tests pass on a machine without MIMIC-III
  • Category B tests are skipped gracefully (not errored) when MIMIC-III is absent
  • No hardcoded absolute paths in bootstrap
  • tests/integration/__init__.py exists (already created for CorGAN)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions