about summary refs log tree commit diff
path: root/gn2/tests/unit/base/test_species.py
diff options
context:
space:
mode:
authorAlexander_Kabui2024-01-02 13:21:07 +0300
committerAlexander_Kabui2024-01-02 13:21:07 +0300
commit70c4201b332e0e2c0d958428086512f291469b87 (patch)
treeaea4fac8782c110fc233c589c3f0f7bd34bada6c /gn2/tests/unit/base/test_species.py
parent5092eb42f062b1695c4e39619f0bd74a876cfac2 (diff)
parent965ce5114d585624d5edb082c710b83d83a3be40 (diff)
downloadgenenetwork2-70c4201b332e0e2c0d958428086512f291469b87.tar.gz
merge changes
Diffstat (limited to 'gn2/tests/unit/base/test_species.py')
-rw-r--r--gn2/tests/unit/base/test_species.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/gn2/tests/unit/base/test_species.py b/gn2/tests/unit/base/test_species.py
new file mode 100644
index 00000000..d2845b25
--- /dev/null
+++ b/gn2/tests/unit/base/test_species.py
@@ -0,0 +1,80 @@
+"""Tests wqflask/base/species.py"""
+import pytest
+from gn2.base.species import TheSpecies
+from gn2.base.species import IndChromosome
+from gn2.base.species import Chromosomes
+from collections import OrderedDict
+from dataclasses import dataclass
+
+
+@dataclass
+class MockChromosome:
+    OrderId: int
+    Name: str
+    Length: int
+
+
+@dataclass
+class MockGroup:
+    name: str
+
+
+@dataclass
+class MockDataset:
+    group: MockGroup
+
+
+@pytest.mark.parametrize(
+    ("species_name", "dataset", "expected_name", "chromosome_param"),
+    (("BXD", None, "BXD", 1),
+     (None, "Random Dataset", None, 1)))
+def test_species(mocker, species_name, dataset,
+                 expected_name, chromosome_param):
+    _c = mocker.patch("gn2.base.species.Chromosomes",
+                      return_value=chromosome_param)
+    test_species = TheSpecies(dataset=dataset,
+                              species_name=species_name)
+    _c.assert_called_with(species=species_name,
+                          dataset=dataset)
+    assert test_species.name == expected_name
+    assert test_species.chromosomes == chromosome_param
+
+
+@pytest.mark.parametrize(
+    ("name", "length", "mb_length"),
+    (("Test A", 10000000, 10),
+     ("Test B", 100, 0.0001)))
+def test_create_ind_chromosome(name, length, mb_length):
+    _ind = IndChromosome(name=name, length=length)
+    assert _ind.name == name
+    assert _ind.length == length
+    assert _ind.mb_length == mb_length
+
+
+@pytest.mark.parametrize(
+    ("species", "dataset", "expected_call"),
+    (("bxd", MockDataset(MockGroup("Random")),
+      ("SELECT Chr_Length.Name, Chr_Length.OrderId, Length "
+       "FROM Chr_Length, Species WHERE "
+       "Chr_Length.SpeciesId = Species.SpeciesId AND "
+       "Species.Name = %s "
+       "ORDER BY OrderId", ("Bxd",))),
+     (None, MockDataset(MockGroup("Random")),
+      ("SELECT Chr_Length.Name, Chr_Length.OrderId, "
+       "Length FROM Chr_Length, InbredSet WHERE "
+       "Chr_Length.SpeciesId = InbredSet.SpeciesId AND "
+       "InbredSet.Name = "
+       "%s ORDER BY OrderId", ("Random",)))))
+def test_create_chromosomes(mocker, species, dataset, expected_call):
+    mock_conn = mocker.MagicMock()
+    with mock_conn.cursor() as cursor:
+        cursor.fetchall.return_value = (("1", 2, 10,),
+                                        ("2", 3, 11,),
+                                        ("4", 5, 15,),)
+        _c = Chromosomes(dataset=dataset, species=species)
+        assert _c.chromosomes(cursor) == OrderedDict([
+            ("1", IndChromosome("1", 10)),
+            ("2", IndChromosome("2", 11)),
+            ("4", IndChromosome("4", 15)),
+        ])
+        cursor.execute.assert_called_with(*expected_call)