Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Idan Yael committed Apr 28, 2022
1 parent 03f07e2 commit b7263f6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
26 changes: 24 additions & 2 deletions src/correlation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@
[
"AAPL",
"MSFT",
"FB",
"GOOG"
"TSM",
"NVDA",
"ASML",
"ASMLF",
"AVGO",
"ADBE",
"CSCO",
"ACN",
"ORCL",
"CRM",
"QCOM",
"INTC",
"INTU",
"TXN",
"AMD",
"SAP",
"SAPGF",
"SONY",
"SNEJF",
"AMAT",
"KYCCF",
"IBM",
"NOW",
"SHOP"
]
]
}
4 changes: 2 additions & 2 deletions src/storage/mongodb_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_symbol_candles(self, symbol: str, time_span: TimeSpan,
}

return [self._deserialize_candle(candle) for candle in
self.candles_collection.find(query, allow_disk_use=True).sort("timestamp")]
self.candles_collection.find(query).sort("timestamp")]

def get_candles(self, time_span: TimeSpan,
from_timestamp: datetime, to_timestamp: datetime) -> List[Candle]:
Expand All @@ -116,7 +116,7 @@ def get_candles(self, time_span: TimeSpan,
}

return [self._deserialize_candle(candle) for candle in
self.candles_collection.find(query, allow_disk_use=True).sort("timestamp")]
self.candles_collection.find(query).sort("timestamp")]

def __drop_collections__(self):
self.db.drop_collection(CANDLES_COLLECTION)
6 changes: 4 additions & 2 deletions tests/unit/strategies/test_history_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def _check(signals: List[StrategySignal]):
@mongomock.patch(servers=(('localhost', 27017),))
def test_no_signals(self):
def _check(signals: List[StrategySignal]):
self.fail()
if signals:
self.fail()

candle = self._get_candle()

Expand All @@ -81,7 +82,8 @@ def _check(signals: List[StrategySignal]):
@mongomock.patch(servers=(('localhost', 27017),))
def test_no_signal_because_timeframe(self):
def _check(signals: List[StrategySignal]):
self.fail()
if signals:
self.fail()

candle = self._get_candle()

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_asset_correlation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import random
from datetime import datetime, timedelta
from typing import List
Expand Down Expand Up @@ -54,12 +55,14 @@ def _check(context: SharedContext, candle: Candle):
if candle.symbol == 'X':
self.assertFalse(asset_correlation.has('X'))
self.assertTrue(asset_correlation.get('Y') > 0)
self.assertTrue(asset_correlation.get('Z') > 0)
else:
self.assertTrue(asset_correlation.get('X') > 0)

validator = ValidationProcessor(_check)
cache_processor = CandleCache(validator)
asset_correlation = AssetCorrelationProcessor('../configs/correlations.json', cache_processor)
correlations_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../configs/correlations.json')
asset_correlation = AssetCorrelationProcessor(correlations_file_path, cache_processor)
timespan_change_processor = TimeSpanChangeProcessor(TimeSpan.Day, asset_correlation)
technicals = TechnicalsProcessor(timespan_change_processor)
PipelineRunner(self.source, technicals).run()
4 changes: 2 additions & 2 deletions tests/unit/test_technicals_binner_terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test(self):
technicals = TechnicalsProcessor(technicals_normalizer)

with patch("builtins.open", mock_open()) as mock_file:
binner_terminator = TechnicalsBinner([TEST_SYMBOL], "/not/a/real/path.dat")
binner_terminator = TechnicalsBinner([TEST_SYMBOL], 7, "/not/a/real/path.dat")
PipelineRunner(self.source, technicals, binner_terminator).run()

mock_file.assert_called_with("/not/a/real/path.dat", 'w+')
Expand Down Expand Up @@ -64,7 +64,7 @@ def _check(context: SharedContext, candle: Candle):
cache_processor = CandleCache()
technicals_normalizer = TechnicalsNormalizerProcessor(next_processor=cache_processor)
technicals = TechnicalsProcessor(technicals_normalizer)
binner_terminator = TechnicalsBinner([TEST_SYMBOL], tmpfilepath)
binner_terminator = TechnicalsBinner([TEST_SYMBOL], 7, tmpfilepath)

PipelineRunner(self.source, technicals, binner_terminator).run()

Expand Down

0 comments on commit b7263f6

Please sign in to comment.