ruff format: Update more test files

This commit is contained in:
Matthias
2024-05-12 15:59:04 +02:00
parent ca1fe06035
commit d8a8b5c125
8 changed files with 340 additions and 313 deletions

View File

@@ -181,10 +181,10 @@ def test_trade_fromjson():
Trade.commit()
assert trade.id == 25
assert trade.pair == 'ETH/USDT'
assert trade.pair == "ETH/USDT"
assert trade.open_date_utc == datetime(2022, 10, 18, 9, 12, 42, tzinfo=timezone.utc)
assert isinstance(trade.open_date, datetime)
assert trade.exit_reason == 'no longer good'
assert trade.exit_reason == "no longer good"
assert trade.realized_profit == 2.76315361
assert trade.precision_mode == 2
assert trade.amount_precision == 1.0
@@ -199,7 +199,6 @@ def test_trade_fromjson():
@pytest.mark.usefixtures("init_persistence")
def test_trade_serialize_load_back(fee):
create_mock_trades_usdt(fee, None)
t = Trade.get_trades([Trade.id == 1]).first()
@@ -219,12 +218,22 @@ def test_trade_serialize_load_back(fee):
assert len(trade.orders) == len(t.orders)
assert trade.orders[0].funding_fee == t.orders[0].funding_fee
excluded = [
'trade_id', 'quote_currency', 'open_timestamp', 'close_timestamp',
'realized_profit_ratio', 'close_profit_pct',
'trade_duration_s', 'trade_duration',
'profit_ratio', 'profit_pct', 'profit_abs', 'stop_loss_abs',
'initial_stop_loss_abs', 'open_fill_date', 'open_fill_timestamp',
'orders',
"trade_id",
"quote_currency",
"open_timestamp",
"close_timestamp",
"realized_profit_ratio",
"close_profit_pct",
"trade_duration_s",
"trade_duration",
"profit_ratio",
"profit_pct",
"profit_abs",
"stop_loss_abs",
"initial_stop_loss_abs",
"open_fill_date",
"open_fill_timestamp",
"orders",
]
failed = []
# Ensure all attributes written can be read.
@@ -233,29 +242,33 @@ def test_trade_serialize_load_back(fee):
continue
tattr = getattr(trade, obj, None)
if isinstance(tattr, datetime):
tattr = tattr.strftime('%Y-%m-%d %H:%M:%S')
tattr = tattr.strftime("%Y-%m-%d %H:%M:%S")
if tattr != value:
failed.append((obj, tattr, value))
assert tjson.get('trade_id') == trade.id
assert tjson.get('quote_currency') == trade.stake_currency
assert tjson.get('stop_loss_abs') == trade.stop_loss
assert tjson.get('initial_stop_loss_abs') == trade.initial_stop_loss
assert tjson.get("trade_id") == trade.id
assert tjson.get("quote_currency") == trade.stake_currency
assert tjson.get("stop_loss_abs") == trade.stop_loss
assert tjson.get("initial_stop_loss_abs") == trade.initial_stop_loss
excluded_o = [
'order_filled_timestamp', 'ft_is_entry', 'pair', 'is_open', 'order_timestamp',
"order_filled_timestamp",
"ft_is_entry",
"pair",
"is_open",
"order_timestamp",
]
order_obj = trade.orders[0]
for obj, value in tjson['orders'][0].items():
for obj, value in tjson["orders"][0].items():
if obj in excluded_o:
continue
tattr = getattr(order_obj, obj, None)
if isinstance(tattr, datetime):
tattr = tattr.strftime('%Y-%m-%d %H:%M:%S')
tattr = tattr.strftime("%Y-%m-%d %H:%M:%S")
if tattr != value:
failed.append((obj, tattr, value))
assert tjson['orders'][0]['pair'] == order_obj.ft_pair
assert tjson["orders"][0]["pair"] == order_obj.ft_pair
assert not failed
trade2 = LocalTrade.from_json(trade_string)