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
|
"""module contains tests for creating traits"""
from unittest import TestCase
from unittest import mock
from gn3.computations.traits import compute_sum
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"""
def test_sum(self):
"""initial faling tests"""
results = compute_sum(2, 5)
self.assertEqual(results, 7)
@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
}
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")
self.assertEqual(results, expected_trait)
get_sample_data.assert_called_once_with(None, "AXFDSF_AT")
@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"
results = get_trait_sample_data(
trait_dataset, trait_name)
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)
|