about summary refs log tree commit diff
diff options
context:
space:
mode:
authorpi coding agent <pi@localhost>2026-11-04 17:09:44 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-11-04 11:14:35 -0600
commit6112e00f3b7de903426d38ea2af36ac5270ba67f (patch)
tree1c7b09068ca6f0de97e1f82797867697f0f4757e
parent863946f5ee15ccf0a8587dac757cb2dbcbe3dc5c (diff)
downloadgn-uploader-6112e00f3b7de903426d38ea2af36ac5270ba67f.tar.gz
Test: cover building the genotype collector config from the form
Add tests for mapping the upload form's metadata fields to the statistics
collector's config keys, including collector defaults, the transposed checkbox
and normalisation of the missing-value strings.
-rw-r--r--tests/uploader/test_genotype_collector_config.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/uploader/test_genotype_collector_config.py b/tests/uploader/test_genotype_collector_config.py
new file mode 100644
index 0000000..d0ab99e
--- /dev/null
+++ b/tests/uploader/test_genotype_collector_config.py
@@ -0,0 +1,79 @@
+"""Tests for building the genotype collector config from the upload form."""
+import pytest
+
+from uploader.genotypes.collector_config import from_form
+
+
+@pytest.mark.unit_test
+def test_from_form_maps_every_upload_field():
+    """
+    GIVEN: a fully specified upload form
+    WHEN: the collector config is built
+    THEN: each form field is mapped to the collector's config key
+    """
+    form = {
+        "markers_field": "Marker",
+        "chromosomes_field": "Chrom",
+        "centimorgans_field": "Centimorgan",
+        "megabases_field": "Megabase",
+        "file-separator": "\t",
+        "file-comment-char": ";",
+        "file-na": "- NA",
+        "transposed": "on",
+    }
+    assert from_form(form) == {
+        "markers": "Marker",
+        "chromosome": "Chrom",
+        "cm": "Centimorgan",
+        "mb": "Megabase",
+        "separator": "\t",
+        "comment.char": ";",
+        "na_strings": ["-", "NA"],
+        "transposed": True,
+    }
+
+
+@pytest.mark.unit_test
+def test_from_form_uses_collector_defaults_for_missing_fields():
+    """
+    GIVEN: an upload form without the metadata fields
+    WHEN: the collector config is built
+    THEN: the collector's own defaults are used
+    """
+    assert from_form({}) == {
+        "markers": "Locus",
+        "chromosome": "Chr",
+        "cm": "cM",
+        "mb": "Mb",
+        "separator": ",",
+        "comment.char": "#",
+        "na_strings": ["-", "NA", "N/A"],
+        "transposed": False,
+    }
+
+
+@pytest.mark.unit_test
+@pytest.mark.parametrize(
+    "form,expected",
+    (({"transposed": "on"}, True),
+     ({"transposed": ""}, False),
+     ({"transposed": "off"}, False),
+     ({}, False)))
+def test_from_form_parses_the_transposed_checkbox(form, expected):
+    """
+    GIVEN: an upload form with various transposed checkbox values
+    WHEN: the collector config is built
+    THEN: the transposed flag is True only when the checkbox is checked
+    """
+    assert from_form(form)["transposed"] is expected
+
+
+@pytest.mark.unit_test
+def test_from_form_normalises_na_string_whitespace():
+    """
+    GIVEN: a space- and tab-separated list of missing-value strings
+    WHEN: the collector config is built
+    THEN: the list is split into non-empty strings
+    """
+    assert from_form({"file-na": "  -   NA\tN/A  "})["na_strings"] == [
+        "-", "NA", "N/A"]