|
| 1 | +import pytest |
| 2 | + |
| 3 | +from waters2mzml.cli import convert |
| 4 | + |
| 5 | + |
| 6 | +def test_docker_without_image_errors(tmp_path): |
| 7 | + raw = tmp_path / "raw" |
| 8 | + raw.mkdir() |
| 9 | + out = tmp_path / "mzml" |
| 10 | + out.mkdir() |
| 11 | + |
| 12 | + with pytest.raises(Exception) as exc: |
| 13 | + convert( |
| 14 | + input=raw, |
| 15 | + output=out, |
| 16 | + centroid=False, |
| 17 | + base_dir=tmp_path, |
| 18 | + parallel=1, |
| 19 | + docker=True, |
| 20 | + docker_image=None, |
| 21 | + retries=0, |
| 22 | + log_level="INFO", |
| 23 | + ) |
| 24 | + |
| 25 | + assert "docker-image" in str(exc.value).lower() |
| 26 | + |
| 27 | + |
| 28 | +def test_docker_with_image_passes_validation(tmp_path, monkeypatch): |
| 29 | + called = {} |
| 30 | + |
| 31 | + def fake_pipeline(**kwargs): |
| 32 | + called.update(kwargs) |
| 33 | + |
| 34 | + monkeypatch.setattr("waters2mzml.cli.run_pipeline", fake_pipeline) |
| 35 | + |
| 36 | + raw = tmp_path / "raw" |
| 37 | + raw.mkdir() |
| 38 | + (raw / "sample.raw").mkdir() |
| 39 | + |
| 40 | + out = tmp_path / "mzml" |
| 41 | + out.mkdir() |
| 42 | + |
| 43 | + convert( |
| 44 | + input=raw, |
| 45 | + output=out, |
| 46 | + centroid=False, |
| 47 | + base_dir=tmp_path, |
| 48 | + parallel=1, |
| 49 | + docker=True, |
| 50 | + docker_image="my/image", |
| 51 | + retries=0, |
| 52 | + log_level="INFO", |
| 53 | + ) |
| 54 | + |
| 55 | + assert called["use_docker"] is True |
| 56 | + assert called["docker_image"] == "my/image" |
| 57 | + |
| 58 | + |
| 59 | +def test_parallel_pipeline_receives_docker_image(tmp_path, monkeypatch): |
| 60 | + called = {} |
| 61 | + |
| 62 | + def fake_parallel(**kwargs): |
| 63 | + called.update(kwargs) |
| 64 | + |
| 65 | + monkeypatch.setattr("waters2mzml.cli.run_pipeline_parallel", fake_parallel) |
| 66 | + |
| 67 | + raw = tmp_path / "raw" |
| 68 | + raw.mkdir() |
| 69 | + (raw / "sample.raw").mkdir() |
| 70 | + |
| 71 | + out = tmp_path / "mzml" |
| 72 | + out.mkdir() |
| 73 | + |
| 74 | + convert( |
| 75 | + input=raw, |
| 76 | + output=out, |
| 77 | + centroid=False, |
| 78 | + base_dir=tmp_path, |
| 79 | + parallel=4, |
| 80 | + docker=True, |
| 81 | + docker_image="pwiz/msconvert", |
| 82 | + retries=0, |
| 83 | + log_level="INFO", |
| 84 | + ) |
| 85 | + |
| 86 | + assert called["use_docker"] is True |
| 87 | + assert called["docker_image"] == "pwiz/msconvert" |
| 88 | + assert called["jobs"] == 4 |
| 89 | + |
| 90 | + |
| 91 | +def test_native_mode_does_not_require_image(tmp_path, monkeypatch): |
| 92 | + called = {} |
| 93 | + |
| 94 | + def fake_pipeline(**kwargs): |
| 95 | + called.update(kwargs) |
| 96 | + |
| 97 | + monkeypatch.setattr("waters2mzml.cli.run_pipeline", fake_pipeline) |
| 98 | + |
| 99 | + raw = tmp_path / "raw" |
| 100 | + raw.mkdir() |
| 101 | + (raw / "sample.raw").mkdir() |
| 102 | + |
| 103 | + out = tmp_path / "mzml" |
| 104 | + out.mkdir() |
| 105 | + |
| 106 | + convert( |
| 107 | + input=raw, |
| 108 | + output=out, |
| 109 | + centroid=False, |
| 110 | + base_dir=tmp_path, |
| 111 | + parallel=1, |
| 112 | + docker=False, |
| 113 | + docker_image=None, |
| 114 | + retries=0, |
| 115 | + log_level="INFO", |
| 116 | + ) |
| 117 | + |
| 118 | + assert called["use_docker"] is False |
| 119 | + assert called["docker_image"] is None |
| 120 | + |
| 121 | + |
| 122 | +def test_invalid_paths_fail_cleanly(tmp_path, caplog): |
| 123 | + out = tmp_path / "mzml" |
| 124 | + out.mkdir() |
| 125 | + |
| 126 | + convert( |
| 127 | + input=tmp_path / "does_not_exist", |
| 128 | + output=out, |
| 129 | + centroid=False, |
| 130 | + base_dir=tmp_path, |
| 131 | + parallel=1, |
| 132 | + docker=False, |
| 133 | + docker_image=None, |
| 134 | + retries=0, |
| 135 | + log_level="INFO", |
| 136 | + ) |
| 137 | + |
| 138 | + # The pipeline should NOT raise — it should log a message |
| 139 | + assert "no .raw folders found" in caplog.text.lower() |
0 commit comments