convert asserts to pytest style

This commit is contained in:
Janne Sinivirta 2017-09-30 20:38:19 +03:00
parent 3f6f502e66
commit 53b4c3722e
4 changed files with 53 additions and 53 deletions

View File

@ -24,28 +24,28 @@ class TestAnalyze(unittest.TestCase):
self.result = parse_ticker_dataframe(RESULT_BITTREX['result'], arrow.get('2017-08-30T10:00:00'))
def test_1_dataframe_has_correct_columns(self):
self.assertEqual(self.result.columns.tolist(),
['close', 'high', 'low', 'open', 'date', 'volume'])
assert self.result.columns.tolist() == \
['close', 'high', 'low', 'open', 'date', 'volume']
def test_2_orders_by_date(self):
self.assertEqual(self.result['date'].tolist(),
assert self.result['date'].tolist() == \
['2017-08-30T10:34:00',
'2017-08-30T10:37:00',
'2017-08-30T10:40:00',
'2017-08-30T10:42:00'])
'2017-08-30T10:42:00']
def test_3_populates_buy_trend(self):
dataframe = populate_buy_trend(populate_indicators(self.result))
self.assertTrue('buy' in dataframe.columns)
self.assertTrue('buy_price' in dataframe.columns)
assert 'buy' in dataframe.columns
assert 'buy_price' in dataframe.columns
def test_4_returns_latest_buy_signal(self):
buydf = DataFrame([{'buy': 1, 'date': arrow.utcnow()}])
with patch('freqtrade.analyze.analyze_ticker', return_value=buydf):
self.assertEqual(get_buy_signal('BTC-ETH'), True)
assert get_buy_signal('BTC-ETH') == True
buydf = DataFrame([{'buy': 0, 'date': arrow.utcnow()}])
with patch('freqtrade.analyze.analyze_ticker', return_value=buydf):
self.assertEqual(get_buy_signal('BTC-ETH'), False)
assert get_buy_signal('BTC-ETH') == False
if __name__ == '__main__':

View File

@ -62,15 +62,15 @@ class TestMain(unittest.TestCase):
trade = create_trade(15.0, exchange.Exchange.BITTREX)
Trade.session.add(trade)
Trade.session.flush()
self.assertIsNotNone(trade)
self.assertEqual(trade.open_rate, 0.072661)
self.assertEqual(trade.pair, pair)
self.assertEqual(trade.exchange, exchange.Exchange.BITTREX)
self.assertEqual(trade.amount, 206.43811673387373)
self.assertEqual(trade.stake_amount, 15.0)
self.assertEqual(trade.is_open, True)
self.assertIsNotNone(trade.open_date)
self.assertEqual(whitelist, self.conf['bittrex']['pair_whitelist'])
assert trade is not None
assert trade.open_rate == 0.072661
assert trade.pair == pair
assert trade.exchange == exchange.Exchange.BITTREX
assert trade.amount == 206.43811673387373
assert trade.stake_amount == 15.0
assert trade.is_open == True
assert trade.open_date is not None
assert whitelist == self.conf['bittrex']['pair_whitelist']
buy_signal.assert_has_calls(
[call('BTC_ETH'), call('BTC_TKN'), call('BTC_TRST'), call('BTC_SWT')]
@ -87,36 +87,36 @@ class TestMain(unittest.TestCase):
}),
buy=MagicMock(return_value='mocked_order_id')):
trade = Trade.query.filter(Trade.is_open.is_(True)).first()
self.assertTrue(trade)
assert trade
handle_trade(trade)
self.assertEqual(trade.close_rate, 0.17256061)
self.assertEqual(trade.close_profit, 137.4872490056564)
self.assertIsNotNone(trade.close_date)
self.assertEqual(trade.open_order_id, 'dry_run')
assert trade.close_rate == 0.17256061
assert trade.close_profit == 137.4872490056564
assert trade.close_date is not None
assert trade.open_order_id == 'dry_run'
def test_3_close_trade(self):
with patch.dict('freqtrade.main._CONF', self.conf):
trade = Trade.query.filter(Trade.is_open.is_(True)).first()
self.assertTrue(trade)
assert trade
# Simulate that there is no open order
trade.open_order_id = None
closed = close_trade_if_fulfilled(trade)
self.assertTrue(closed)
self.assertEqual(trade.is_open, False)
assert closed
assert trade.is_open == False
def test_balance_fully_ask_side(self):
with patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 0.0}}):
self.assertEqual(get_target_bid({'ask': 20, 'last': 10}), 20)
assert get_target_bid({'ask': 20, 'last': 10}) == 20
def test_balance_fully_last_side(self):
with patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 1.0}}):
self.assertEqual(get_target_bid({'ask': 20, 'last': 10}), 10)
assert get_target_bid({'ask': 20, 'last': 10}) == 10
def test_balance_when_last_bigger_than_ask(self):
with patch.dict('freqtrade.main._CONF', {'bid_strategy': {'ask_last_balance': 1.0}}):
self.assertEqual(get_target_bid({'ask': 5, 'last': 10}), 5)
assert get_target_bid({'ask': 5, 'last': 10}) == 5
@classmethod
def setUpClass(cls):

View File

@ -18,10 +18,10 @@ class TestTrade(unittest.TestCase):
)
profit = trade.exec_sell_order(1.00, 10.00)
api_mock.assert_called_once_with('BTC_ETH', 1.0, 10.0)
self.assertEqual(profit, 100.0)
self.assertEqual(trade.close_rate, 1.0)
self.assertEqual(trade.close_profit, profit)
self.assertIsNotNone(trade.close_date)
assert profit == 100.0
assert trade.close_rate == 1.0
assert trade.close_profit == profit
assert trade.close_date is not None
if __name__ == '__main__':

View File

@ -63,13 +63,13 @@ class TestTelegram(unittest.TestCase):
# Create some test data
trade = create_trade(15.0, exchange.Exchange.BITTREX)
self.assertTrue(trade)
assert trade
Trade.session.add(trade)
Trade.session.flush()
_status(bot=MagicBot(), update=self.update)
self.assertEqual(msg_mock.call_count, 2)
self.assertIn('[BTC_ETH]', msg_mock.call_args_list[-1][0][0])
assert msg_mock.call_count == 2
assert '[BTC_ETH]' in msg_mock.call_args_list[-1][0][0]
def test_2_profit_handle(self):
with patch.dict('freqtrade.main._CONF', self.conf):
@ -87,7 +87,7 @@ class TestTelegram(unittest.TestCase):
# Create some test data
trade = create_trade(15.0, exchange.Exchange.BITTREX)
self.assertTrue(trade)
assert trade
trade.close_rate = 0.07256061
trade.close_profit = 100.00
trade.close_date = datetime.utcnow()
@ -97,8 +97,8 @@ class TestTelegram(unittest.TestCase):
Trade.session.flush()
_profit(bot=MagicBot(), update=self.update)
self.assertEqual(msg_mock.call_count, 2)
self.assertIn('(100.00%)', msg_mock.call_args_list[-1][0][0])
assert msg_mock.call_count == 2
assert '(100.00%)' in msg_mock.call_args_list[-1][0][0]
def test_3_forcesell_handle(self):
with patch.dict('freqtrade.main._CONF', self.conf):
@ -116,16 +116,16 @@ class TestTelegram(unittest.TestCase):
# Create some test data
trade = create_trade(15.0, exchange.Exchange.BITTREX)
self.assertTrue(trade)
assert trade
Trade.session.add(trade)
Trade.session.flush()
self.update.message.text = '/forcesell 1'
_forcesell(bot=MagicBot(), update=self.update)
self.assertEqual(msg_mock.call_count, 2)
self.assertIn('Selling [BTC/ETH]', msg_mock.call_args_list[-1][0][0])
self.assertIn('0.072561', msg_mock.call_args_list[-1][0][0])
assert msg_mock.call_count == 2
assert 'Selling [BTC/ETH]' in msg_mock.call_args_list[-1][0][0]
assert '0.072561' in msg_mock.call_args_list[-1][0][0]
def test_4_performance_handle(self):
with patch.dict('freqtrade.main._CONF', self.conf):
@ -143,7 +143,7 @@ class TestTelegram(unittest.TestCase):
# Create some test data
trade = create_trade(15.0, exchange.Exchange.BITTREX)
self.assertTrue(trade)
assert trade
trade.close_rate = 0.07256061
trade.close_profit = 100.00
trade.close_date = datetime.utcnow()
@ -153,9 +153,9 @@ class TestTelegram(unittest.TestCase):
Trade.session.flush()
_performance(bot=MagicBot(), update=self.update)
self.assertEqual(msg_mock.call_count, 2)
self.assertIn('Performance', msg_mock.call_args_list[-1][0][0])
self.assertIn('BTC_ETH 100.00%', msg_mock.call_args_list[-1][0][0])
assert msg_mock.call_count == 2
assert 'Performance' in msg_mock.call_args_list[-1][0][0]
assert 'BTC_ETH 100.00%' in msg_mock.call_args_list[-1][0][0]
def test_5_start_handle(self):
with patch.dict('freqtrade.main._CONF', self.conf):
@ -164,10 +164,10 @@ class TestTelegram(unittest.TestCase):
init(self.conf, 'sqlite://')
update_state(State.STOPPED)
self.assertEqual(get_state(), State.STOPPED)
assert get_state() == State.STOPPED
_start(bot=MagicBot(), update=self.update)
self.assertEqual(get_state(), State.RUNNING)
self.assertEqual(msg_mock.call_count, 0)
assert get_state() == State.RUNNING
assert msg_mock.call_count == 0
def test_6_stop_handle(self):
with patch.dict('freqtrade.main._CONF', self.conf):
@ -176,11 +176,11 @@ class TestTelegram(unittest.TestCase):
init(self.conf, 'sqlite://')
update_state(State.RUNNING)
self.assertEqual(get_state(), State.RUNNING)
assert get_state() == State.RUNNING
_stop(bot=MagicBot(), update=self.update)
self.assertEqual(get_state(), State.STOPPED)
self.assertEqual(msg_mock.call_count, 1)
self.assertIn('Stopping trader', msg_mock.call_args_list[0][0][0])
assert get_state() == State.STOPPED
assert msg_mock.call_count == 1
assert 'Stopping trader' in msg_mock.call_args_list[0][0][0]
def setUp(self):
self.update = Update(0)