aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/computations/test_trait.py
blob: feb97c6fff98e282f6aacbeeed76fda791fdad05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Module contains tests for creating traits"""
from unittest import TestCase
from unittest import mock

from gn3.computations.traits import fetch_trait
from gn3.computations.traits import get_trait_sample_data
from gn3.computations.traits import get_trait_info_data


class TestTrait(TestCase):
    """Class contains tests for creating traits"""

    @mock.patch("gn3.computations.traits.get_trait_sample_data")
    def test_fetch_trait(self, get_sample_data):
        """Test for creating/fetching trait"""

        expected_sample_data = {
            "A/Y": 12.3,
            "WQC": 11.1
        }

        database = mock.Mock()

        get_sample_data.return_value = expected_sample_data

        expected_trait = {
            "trait_name": "AXFDSF_AT",
            "dataset": None,
            "trait_data": expected_sample_data
        }
        results = fetch_trait(dataset=None,
                              trait_name="AXFDSF_AT",
                              database=database)

        self.assertEqual(results, expected_trait)
        self.assertEqual(get_sample_data.call_count, 1)

    @mock.patch("gn3.computations.traits.retrieve_trait_sample_data")
    def test_get_trait_sample_data(self, mock_retrieve_sample_data):
        """Test for getting sample data from  either\
        the trait's dataset or form redis
        """

        trait_dataset = mock.Mock()
        dataset_trait_sample_data = [
            ('129S1/SvImJ', 7.433, None, None, '129S1/SvImJ'),
            ('A/J', 7.596, None, None, 'A/J'),
            ('AKR/J', 7.774, None, None, 'AKR/J'),
            ('B6D2F1', 7.707, None, None, 'B6D2F1')]
        mock_retrieve_sample_data.return_value = dataset_trait_sample_data

        trait_name = "1426679_at"

        database = mock.Mock()

        results = get_trait_sample_data(
            trait_dataset, trait_name, database)

        expected_results = {
            "129S1/SvImJ": 7.433,
            "A/J": 7.596,
            "AKR/J": 7.774,
            "B6D2F1": 7.707
        }

        self.assertEqual(results, expected_results)

    def test_get_trait_info_data(self):
        """Test for getting info data related\
        to trait
        """

        results = get_trait_info_data(
            trait_name="AXSF_AT", trait_dataset=mock.Mock(), database_instance=None)
        expected_trait_info = {
            "description": "",
            "trait_display_name": "",
            "abbreviation": "",
            "chr": "",
            "mb": "",
            "locus": ""
        }

        self.assertEqual(results, expected_trait_info)