diff options
| author | pi coding agent <pi@localhost> | 2026-11-04 17:52:06 +0000 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-11-04 12:14:24 -0600 |
| commit | cd504858c3e142c2cbe00c041efce6b6bf8485bf (patch) | |
| tree | b7a32beba5eba6d3a536cd9c43d00b1a9a8db60d | |
| parent | 9cdd3edc1fe41e32bbdf687d761d31a703757d2d (diff) | |
| download | gn-uploader-cd504858c3e142c2cbe00c041efce6b6bf8485bf.tar.gz | |
Test: cover building the collector job command
Add tests for translating the collector config into the collector CLI's arguments (log level, file metadata, separator/comment/NA strings and the transposed flag), with the file path as the final argument.
| -rw-r--r-- | tests/uploader/test_genotype_collector_config.py | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/uploader/test_genotype_collector_config.py b/tests/uploader/test_genotype_collector_config.py index d0ab99e..1ebdcb6 100644 --- a/tests/uploader/test_genotype_collector_config.py +++ b/tests/uploader/test_genotype_collector_config.py @@ -1,7 +1,9 @@ """Tests for building the genotype collector config from the upload form.""" +import sys + import pytest -from uploader.genotypes.collector_config import from_form +from uploader.genotypes.collector_config import command, from_form @pytest.mark.unit_test @@ -77,3 +79,71 @@ def test_from_form_normalises_na_string_whitespace(): """ assert from_form({"file-na": " - NA\tN/A "})["na_strings"] == [ "-", "NA", "N/A"] + + +def _config(**overrides): + """Build a collector config for the command tests.""" + return { + "markers": "Marker", + "chromosome": "Chrom", + "cm": "Centimorgan", + "mb": "Megabase", + "separator": "\t", + "comment.char": ";", + "na_strings": ["-", "NA", "N/A"], + "transposed": False, + **overrides, + } + + +@pytest.mark.unit_test +def test_command_builds_the_collector_cli(tmp_path): + """ + GIVEN: a file path and a collector config + WHEN: the collector command is built + THEN: the config is translated into the collector CLI's flags and the file + path is the final argument + """ + filepath = tmp_path / "genotypes.csv" + cmd = command(filepath, _config()) + + assert cmd[:3] == [ + sys.executable, "-m", + "uploader.scripts.genotypes.preprocess_csv_collect_info"] + + def value_of(flag): + return cmd[cmd.index(flag) + 1] + + assert value_of("--log-level") == "info" + assert value_of("--separator") == "\t" + assert value_of("--comment_char") == ";" + assert value_of("--markers_field") == "Marker" + assert value_of("--chr_field") == "Chrom" + assert value_of("--cm_field") == "Centimorgan" + assert value_of("--mb_field") == "Megabase" + assert cmd[-1] == str(filepath) + + +@pytest.mark.unit_test +@pytest.mark.parametrize("transposed", (True, False)) +def test_command_includes_transposed_flag_only_when_transposed( + tmp_path, transposed): + """ + GIVEN: a collector config with the transposed flag on or off + WHEN: the collector command is built + THEN: the ``--is-transposed`` flag is present only when transposed + """ + cmd = command(tmp_path / "genotypes.csv", _config(transposed=transposed)) + assert ("--is-transposed" in cmd) is transposed + + +@pytest.mark.unit_test +def test_command_passes_na_strings_as_repeated_options(tmp_path): + """ + GIVEN: a collector config with several missing-value strings + WHEN: the collector command is built + THEN: each string is passed with its own ``--na_strings`` option + """ + cmd = command(tmp_path / "genotypes.csv", _config()) + indices = [idx for idx, part in enumerate(cmd) if part == "--na_strings"] + assert [cmd[idx + 1] for idx in indices] == ["-", "NA", "N/A"] |
