|
1 | 1 | import pytest |
2 | 2 | from requests.exceptions import HTTPError |
3 | 3 |
|
| 4 | +from compose_runner import run as run_module |
4 | 5 | from compose_runner.run import Runner |
5 | 6 |
|
6 | | - |
7 | 7 | @pytest.mark.vcr(record_mode="once") |
8 | 8 | def test_incorrect_id(): |
9 | 9 | runner = Runner( |
@@ -62,6 +62,120 @@ def test_run_string_group_comparison_workflow(): |
62 | 62 | ) |
63 | 63 | runner.run_workflow() |
64 | 64 |
|
| 65 | + |
| 66 | +def test_process_bundle_keeps_studysets(monkeypatch): |
| 67 | + first_studyset = object() |
| 68 | + second_studyset = object() |
| 69 | + estimator = object() |
| 70 | + corrector = object() |
| 71 | + |
| 72 | + class FakeStudyset: |
| 73 | + def __init__(self, source): |
| 74 | + self.source = source |
| 75 | + |
| 76 | + class FakeAnnotation: |
| 77 | + def __init__(self, source, studyset): |
| 78 | + self.source = source |
| 79 | + self.studyset = studyset |
| 80 | + |
| 81 | + def fake_apply_filter(self, studyset, annotation): |
| 82 | + assert isinstance(studyset, FakeStudyset) |
| 83 | + assert isinstance(annotation, FakeAnnotation) |
| 84 | + return first_studyset, second_studyset |
| 85 | + |
| 86 | + def fake_load_specification(self, n_cores=None): |
| 87 | + assert n_cores == 3 |
| 88 | + return estimator, corrector |
| 89 | + |
| 90 | + monkeypatch.setattr(run_module, "Studyset", FakeStudyset) |
| 91 | + monkeypatch.setattr(run_module, "Annotation", FakeAnnotation) |
| 92 | + monkeypatch.setattr(Runner, "apply_filter", fake_apply_filter) |
| 93 | + monkeypatch.setattr(Runner, "load_specification", fake_load_specification) |
| 94 | + |
| 95 | + runner = Runner(meta_analysis_id="made_up_id", environment="staging") |
| 96 | + runner.cached_studyset = {"id": "studyset", "studies": []} |
| 97 | + runner.cached_annotation = {"note_keys": {}} |
| 98 | + |
| 99 | + runner.process_bundle(n_cores=3) |
| 100 | + |
| 101 | + assert runner.first_studyset is first_studyset |
| 102 | + assert runner.second_studyset is second_studyset |
| 103 | + assert runner.estimator is estimator |
| 104 | + assert runner.corrector is corrector |
| 105 | + |
| 106 | + |
| 107 | +def test_run_meta_analysis_single_studyset_uses_cbma_workflow(monkeypatch, tmp_path): |
| 108 | + calls = {} |
| 109 | + |
| 110 | + class FakeCBMAEstimator: |
| 111 | + pass |
| 112 | + |
| 113 | + class FakeWorkflow: |
| 114 | + def __init__(self, estimator, corrector, diagnostics, output_dir): |
| 115 | + calls["init"] = { |
| 116 | + "estimator": estimator, |
| 117 | + "corrector": corrector, |
| 118 | + "diagnostics": diagnostics, |
| 119 | + "output_dir": output_dir, |
| 120 | + } |
| 121 | + |
| 122 | + def fit(self, dataset): |
| 123 | + calls["fit"] = {"dataset": dataset} |
| 124 | + return "meta-results" |
| 125 | + |
| 126 | + monkeypatch.setattr(run_module, "CBMAEstimator", FakeCBMAEstimator) |
| 127 | + monkeypatch.setattr(run_module, "CBMAWorkflow", FakeWorkflow) |
| 128 | + |
| 129 | + runner = Runner(meta_analysis_id="made_up_id", environment="staging", result_dir=tmp_path) |
| 130 | + runner.first_studyset = object() |
| 131 | + runner.second_studyset = None |
| 132 | + runner.estimator = FakeCBMAEstimator() |
| 133 | + runner.corrector = object() |
| 134 | + runner._persist_meta_results = lambda: None |
| 135 | + |
| 136 | + runner.run_meta_analysis() |
| 137 | + |
| 138 | + assert calls["fit"] == {"dataset": runner.first_studyset} |
| 139 | + assert runner.meta_results == "meta-results" |
| 140 | + |
| 141 | + |
| 142 | +def test_run_meta_analysis_pairwise_uses_pairwise_workflow(monkeypatch, tmp_path): |
| 143 | + calls = {} |
| 144 | + |
| 145 | + class FakePairwiseEstimator: |
| 146 | + pass |
| 147 | + |
| 148 | + class FakeWorkflow: |
| 149 | + def __init__(self, estimator, corrector, diagnostics, output_dir): |
| 150 | + calls["init"] = { |
| 151 | + "estimator": estimator, |
| 152 | + "corrector": corrector, |
| 153 | + "diagnostics": diagnostics, |
| 154 | + "output_dir": output_dir, |
| 155 | + } |
| 156 | + |
| 157 | + def fit(self, dataset1, dataset2): |
| 158 | + calls["fit"] = {"dataset1": dataset1, "dataset2": dataset2} |
| 159 | + return "pairwise-results" |
| 160 | + |
| 161 | + monkeypatch.setattr(run_module, "PairwiseCBMAEstimator", FakePairwiseEstimator) |
| 162 | + monkeypatch.setattr(run_module, "PairwiseCBMAWorkflow", FakeWorkflow) |
| 163 | + |
| 164 | + runner = Runner(meta_analysis_id="made_up_id", environment="staging", result_dir=tmp_path) |
| 165 | + runner.first_studyset = object() |
| 166 | + runner.second_studyset = object() |
| 167 | + runner.estimator = FakePairwiseEstimator() |
| 168 | + runner.corrector = object() |
| 169 | + runner._persist_meta_results = lambda: None |
| 170 | + |
| 171 | + runner.run_meta_analysis() |
| 172 | + |
| 173 | + assert calls["fit"] == { |
| 174 | + "dataset1": runner.first_studyset, |
| 175 | + "dataset2": runner.second_studyset, |
| 176 | + } |
| 177 | + assert runner.meta_results == "pairwise-results" |
| 178 | + |
65 | 179 | # def test_yifan_workflow(): |
66 | 180 | # runner = Runner( |
67 | 181 | # meta_analysis_id="4WELjap2yCJm", |
|
0 commit comments