forked from JanetMatsen/bacteriopop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
89 lines (73 loc) · 3.06 KB
/
tests.py
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
85
86
87
88
89
import unittest
import bacteriopop_utils
import load_data
import numpy as np
import pandas as pd
import pandas as pd
import requests
print "hello!"
class TestUrlsExist(unittest.TestCase):
def test_raw_data_link(self):
"""
Test for existence of raw_data.csv link in load_data module.
"""
request = requests.get("https://raw.githubusercontent.com/"
"JanetMatsen/bacteriopop/master/raw_data/"
"raw_data.csv")
self.assertEqual(request.status_code, 200)
def test_sample_meta_info_link(self):
"""
Test for existence of sample_meta_info.tsv link in load_data module.
"""
request = requests.get("https://raw.githubusercontent.com/"
"JanetMatsen/bacteriopop/master/raw_data/"
"sample_meta_info.tsv")
self.assertEqual(request.status_code, 200)
class TestDataframe(unittest.TestCase):
def test_df_columns(self):
"""
Test for output dataframe column count in load_data module.
"""
df = load_data.load_data()
cols = df.columns.tolist()
num = len(cols)
num_assert = len(['kingdom', 'phylum', 'class', 'order',
'family', 'genus', 'length', 'oxygen',
'replicate', 'week', 'abundance'])
self.assertEqual(num, num_assert)
def test_df_type(self):
"""
Test for type of the output dataframe in load_data module.
"""
df = load_data.load_data()
self.assertEqual(type(df), pd.DataFrame)
class TestExtractFeatures(unittest.TestCase):
def test_on_animal_df(self):
"""
Simple example with expected numpy vector to compare to.
Use fillna mode.
"""
animal_df = pd.DataFrame({'animal': ['dog', 'cat', 'rat'],
'color': ['white', 'brown', 'brown'],
'gender': ['F', 'F', np.NaN],
'weight': [25, 5, 1],
'garbage': [0, 1, np.NaN],
'abundance': [0.5, 0.4, 0.1]})
extracted = bacteriopop_utils.extract_features(
dataframe=animal_df,
column_list=['animal', 'color', 'weight', 'abundance'],
fillna=True
)
# check that the column names match what is expected
self.assertEqual(extracted.columns.tolist(),
['abundance', 'animal=cat', 'animal=dog',
'animal=rat', 'color=brown', 'color=white',
'weight'])
# check that the values are what was expected.
expected_result = np.array([[0.5, 0., 1., 0., 0., 1., 25.],
[0.4, 1., 0., 0., 1., 0., 5.],
[0.1, 0., 0., 1., 1., 0., 1.]])
self.assertEqual(expected_result.tolist(),
extracted.as_matrix().tolist())
if __name__ == '__main__':
unittest.main()