-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathtest_load_indicator_from_file.py
145 lines (135 loc) · 4.8 KB
/
test_load_indicator_from_file.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Test file for classes and functions:
- analysis_engine.indicators.load_indicator_from_module
- analysis_engine.indicators.indicator_processor
"""
import mock
import analysis_engine.mocks.mock_talib as mock_talib
import analysis_engine.consts as ae_consts
import analysis_engine.indicators.load_indicator_from_module as load_ind
import analysis_engine.mocks.base_test as base_test
class TestLoadIndicatorFromFile(base_test.BaseTestCase):
"""TestLoadIndicatorFromFile"""
ticker = None
last_close_str = None
def setUp(
self):
"""setUp"""
self.ticker = 'SPY'
self.example_module_path = (
'analysis_engine/mocks/example_indicator_williamsr.py')
self.test_data = {
"name": "test_5_days_ahead",
"algo_module_path": None,
"algo_version": 1,
"trade_horizon_units": "day",
"trade_horizon": 5,
"buy_rules": {
"confidence": 75,
"min_indicators": 1
},
"sell_rules": {
"confidence": 75,
"min_indicators": 1
},
"indicators": [
{
"name": "willr",
"module_path": self.example_module_path,
"category": "technical",
"type": "momentum",
"dataset_df": "daily",
'high': 0,
'low': 0,
'open': 0,
'willr_value': 0,
"num_points": 19,
"buy_above": 80,
"sell_below": 10
},
{
"name": "willr",
"module_path": self.example_module_path,
"category": "technical",
"type": "momentum",
"dataset_df": "daily",
'high': 0,
'low': 0,
'open': 0,
'willr_value': 0,
"num_points": 15,
"buy_above": 60,
"sell_below": 20
},
{
"name": "baseindicator",
"category": "fundamental",
"type": "balance_sheet",
"dataset_df": "daily"
}
],
"slack": {
"webhook": None
}
}
# end of setUp
@mock.patch(
('analysis_engine.ae_talib.WILLR'),
new=mock_talib.MockWILLRBuy)
def test_load_indicator_from_example_indicator_file(self):
"""test_load_indicator_from_example_indicator_file"""
log_label = 'my_ind_1'
ind_1 = load_ind.load_indicator_from_module(
module_name='ExampleIndicatorWilliamsR',
log_label=log_label,
path_to_module=self.example_module_path,
ind_dict=self.test_data['indicators'][0])
self.assertTrue(
ind_1 is not None)
self.assertEqual(
ind_1.get_name(),
log_label)
# end of test_load_indicator_from_example_indicator_file
@mock.patch(
('analysis_engine.ae_talib.WILLR'),
new=mock_talib.MockWILLRBuy)
def test_load_multiple_indicator_from_same_example_indicator_file(self):
"""test_load_multiple_indicator_from_same_example_indicator_file"""
log_label_1 = 'my_ind_1'
log_label_2 = 'my_ind_2'
log_label_3 = 'base_ind_1'
ind_1 = load_ind.load_indicator_from_module(
module_name='ExampleIndicatorWilliamsR',
log_label=log_label_1,
path_to_module=self.example_module_path,
ind_dict=self.test_data['indicators'][0])
self.assertTrue(
ind_1 is not None)
self.assertEqual(
ind_1.get_name(),
log_label_1)
ind_2 = load_ind.load_indicator_from_module(
module_name='ExampleIndicatorWilliamsR',
log_label=log_label_2,
path_to_module=self.example_module_path,
ind_dict=self.test_data['indicators'][1])
self.assertTrue(
ind_2 is not None)
self.assertEqual(
ind_2.get_name(),
log_label_2)
self.assertEqual(
ind_1.get_path_to_module(),
ind_2.get_path_to_module())
ind_3 = load_ind.load_indicator_from_module(
module_name='BaseIndicator',
log_label=log_label_3,
ind_dict=self.test_data['indicators'][2])
self.assertEqual(
ind_3.get_path_to_module(),
ae_consts.INDICATOR_BASE_MODULE_PATH)
self.assertEqual(
ind_3.get_name(),
log_label_3)
# end of test_load_indicator_from_example_indicator_file
# end of TestLoadIndicatorFromFile