mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
refactor: tests - update timezone.utc to UTC
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
from zipfile import ZipFile
|
||||
@@ -182,19 +182,19 @@ def test_extract_trades_of_period(testdatadir):
|
||||
"profit_abs": [0.0, 1, -2, -5],
|
||||
"open_date": to_datetime(
|
||||
[
|
||||
datetime(2017, 11, 13, 15, 40, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 14, 9, 41, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 14, 14, 20, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 15, 3, 40, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 13, 15, 40, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 14, 9, 41, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 14, 14, 20, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 15, 3, 40, 0, tzinfo=UTC),
|
||||
],
|
||||
utc=True,
|
||||
),
|
||||
"close_date": to_datetime(
|
||||
[
|
||||
datetime(2017, 11, 13, 16, 40, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 14, 10, 41, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 14, 15, 25, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 15, 3, 55, 0, tzinfo=timezone.utc),
|
||||
datetime(2017, 11, 13, 16, 40, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 14, 10, 41, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 14, 15, 25, 0, tzinfo=UTC),
|
||||
datetime(2017, 11, 15, 3, 55, 0, tzinfo=UTC),
|
||||
],
|
||||
utc=True,
|
||||
),
|
||||
@@ -203,10 +203,10 @@ def test_extract_trades_of_period(testdatadir):
|
||||
trades1 = extract_trades_of_period(data, trades)
|
||||
# First and last trade are dropped as they are out of range
|
||||
assert len(trades1) == 2
|
||||
assert trades1.iloc[0].open_date == datetime(2017, 11, 14, 9, 41, 0, tzinfo=timezone.utc)
|
||||
assert trades1.iloc[0].close_date == datetime(2017, 11, 14, 10, 41, 0, tzinfo=timezone.utc)
|
||||
assert trades1.iloc[-1].open_date == datetime(2017, 11, 14, 14, 20, 0, tzinfo=timezone.utc)
|
||||
assert trades1.iloc[-1].close_date == datetime(2017, 11, 14, 15, 25, 0, tzinfo=timezone.utc)
|
||||
assert trades1.iloc[0].open_date == datetime(2017, 11, 14, 9, 41, 0, tzinfo=UTC)
|
||||
assert trades1.iloc[0].close_date == datetime(2017, 11, 14, 10, 41, 0, tzinfo=UTC)
|
||||
assert trades1.iloc[-1].open_date == datetime(2017, 11, 14, 14, 20, 0, tzinfo=UTC)
|
||||
assert trades1.iloc[-1].close_date == datetime(2017, 11, 14, 15, 25, 0, tzinfo=UTC)
|
||||
|
||||
|
||||
def test_analyze_trade_parallelism(testdatadir):
|
||||
@@ -293,7 +293,7 @@ def test_combined_dataframes_with_rel_mean(testdatadir):
|
||||
pairs = ["ETH/BTC", "ADA/BTC"]
|
||||
data = load_data(datadir=testdatadir, pairs=pairs, timeframe="5m")
|
||||
df = combined_dataframes_with_rel_mean(
|
||||
data, datetime(2018, 1, 12, tzinfo=timezone.utc), datetime(2018, 1, 28, tzinfo=timezone.utc)
|
||||
data, datetime(2018, 1, 12, tzinfo=UTC), datetime(2018, 1, 28, tzinfo=UTC)
|
||||
)
|
||||
assert isinstance(df, DataFrame)
|
||||
assert "ETH/BTC" not in df.columns
|
||||
@@ -596,7 +596,7 @@ def test_calculate_max_drawdown_abs(profits, relative, highd, lowdays, result, r
|
||||
[1000, 500, 1000, 11000, 10000] # absolute results
|
||||
[1000, 50%, 0%, 0%, ~9%] # Relative drawdowns
|
||||
"""
|
||||
init_date = datetime(2020, 1, 1, tzinfo=timezone.utc)
|
||||
init_date = datetime(2020, 1, 1, tzinfo=UTC)
|
||||
dates = [init_date + timedelta(days=i) for i in range(len(profits))]
|
||||
df = DataFrame(zip(profits, dates, strict=False), columns=["profit_abs", "open_date"])
|
||||
# sort by profit and reset index
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
||||
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
@@ -165,19 +165,19 @@ def test_datahandler_ohlcv_data_min_max(testdatadir):
|
||||
# Empty pair
|
||||
min_max = dh.ohlcv_data_min_max("UNITTEST/BTC", "8m", "spot")
|
||||
assert len(min_max) == 3
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=timezone.utc)
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=UTC)
|
||||
assert min_max[0] == min_max[1]
|
||||
# Empty pair2
|
||||
min_max = dh.ohlcv_data_min_max("NOPAIR/XXX", "41m", "spot")
|
||||
assert len(min_max) == 3
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=timezone.utc)
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=UTC)
|
||||
assert min_max[0] == min_max[1]
|
||||
|
||||
# Existing pair ...
|
||||
min_max = dh.ohlcv_data_min_max("UNITTEST/BTC", "1m", "spot")
|
||||
assert len(min_max) == 3
|
||||
assert min_max[0] == datetime(2017, 11, 4, 23, 2, tzinfo=timezone.utc)
|
||||
assert min_max[1] == datetime(2017, 11, 14, 22, 59, tzinfo=timezone.utc)
|
||||
assert min_max[0] == datetime(2017, 11, 4, 23, 2, tzinfo=UTC)
|
||||
assert min_max[1] == datetime(2017, 11, 14, 22, 59, tzinfo=UTC)
|
||||
|
||||
|
||||
def test_datahandler__check_empty_df(testdatadir, caplog):
|
||||
@@ -467,14 +467,14 @@ def test_datahandler_trades_data_min_max(testdatadir):
|
||||
# Empty pair
|
||||
min_max = dh.trades_data_min_max("NADA/ETH", TradingMode.SPOT)
|
||||
assert len(min_max) == 3
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=timezone.utc)
|
||||
assert min_max[0] == datetime.fromtimestamp(0, tz=UTC)
|
||||
assert min_max[0] == min_max[1]
|
||||
|
||||
# Existing pair ...
|
||||
min_max = dh.trades_data_min_max("XRP/ETH", TradingMode.SPOT)
|
||||
assert len(min_max) == 3
|
||||
assert min_max[0] == datetime(2019, 10, 11, 0, 0, 11, 620000, tzinfo=timezone.utc)
|
||||
assert min_max[1] == datetime(2019, 10, 13, 11, 19, 28, 844000, tzinfo=timezone.utc)
|
||||
assert min_max[0] == datetime(2019, 10, 11, 0, 0, 11, 620000, tzinfo=UTC)
|
||||
assert min_max[1] == datetime(2019, 10, 13, 11, 19, 28, 844000, tzinfo=UTC)
|
||||
|
||||
|
||||
def test_gethandlerclass():
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@@ -222,8 +222,8 @@ def test_get_producer_df(default_conf):
|
||||
timeframe = default_conf["timeframe"]
|
||||
candle_type = CandleType.SPOT
|
||||
|
||||
empty_la = datetime.fromtimestamp(0, tz=timezone.utc)
|
||||
now = datetime.now(timezone.utc)
|
||||
empty_la = datetime.fromtimestamp(0, tz=UTC)
|
||||
now = datetime.now(UTC)
|
||||
|
||||
# no data has been added, any request should return an empty dataframe
|
||||
dataframe, la = dataprovider.get_producer_df(pair, timeframe, candle_type)
|
||||
@@ -404,7 +404,7 @@ def test_get_analyzed_dataframe(mocker, default_conf, ohlcv_history):
|
||||
dataframe, time = dp.get_analyzed_dataframe("NOTHING/BTC", timeframe)
|
||||
assert dataframe.empty
|
||||
assert isinstance(time, datetime)
|
||||
assert time == datetime(1970, 1, 1, tzinfo=timezone.utc)
|
||||
assert time == datetime(1970, 1, 1, tzinfo=UTC)
|
||||
|
||||
# Test backtest mode
|
||||
default_conf["runmode"] = RunMode.BACKTEST
|
||||
@@ -478,7 +478,7 @@ def test_dp__add_external_df(default_conf_usdt):
|
||||
default_conf_usdt["timeframe"] = timeframe
|
||||
dp = DataProvider(default_conf_usdt, None)
|
||||
df = generate_test_data(timeframe, 24, "2022-01-01 00:00:00+00:00")
|
||||
last_analyzed = datetime.now(timezone.utc)
|
||||
last_analyzed = datetime.now(UTC)
|
||||
|
||||
res = dp._add_external_df("ETH/USDT", df, last_analyzed, timeframe, CandleType.SPOT)
|
||||
assert res[0] is False
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pragma pylint: disable=missing-docstring, C0103
|
||||
|
||||
from datetime import timezone
|
||||
from datetime import UTC
|
||||
|
||||
import pandas as pd
|
||||
from numpy import nan
|
||||
@@ -16,15 +16,15 @@ def test_get_tick_size_over_time():
|
||||
# Create test dataframe with different levels of precision
|
||||
data = {
|
||||
"date": [
|
||||
Timestamp("2020-01-01 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-02 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-03 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-15 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-16 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-31 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-02-01 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-02-15 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-03-15 00:00:00", tz=timezone.utc),
|
||||
Timestamp("2020-01-01 00:00:00", tz=UTC),
|
||||
Timestamp("2020-01-02 00:00:00", tz=UTC),
|
||||
Timestamp("2020-01-03 00:00:00", tz=UTC),
|
||||
Timestamp("2020-01-15 00:00:00", tz=UTC),
|
||||
Timestamp("2020-01-16 00:00:00", tz=UTC),
|
||||
Timestamp("2020-01-31 00:00:00", tz=UTC),
|
||||
Timestamp("2020-02-01 00:00:00", tz=UTC),
|
||||
Timestamp("2020-02-15 00:00:00", tz=UTC),
|
||||
Timestamp("2020-03-15 00:00:00", tz=UTC),
|
||||
],
|
||||
"open": [1.23456, 1.234, 1.23, 1.2, 1.23456, 1.234, 2.3456, 2.34, 2.34],
|
||||
"high": [1.23457, 1.235, 1.24, 1.3, 1.23456, 1.235, 2.3457, 2.34, 2.34],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from shutil import copytree
|
||||
from unittest.mock import PropertyMock
|
||||
|
||||
@@ -50,10 +50,10 @@ def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_co
|
||||
assert len(trades) == 340
|
||||
|
||||
assert trades["date"].min().to_pydatetime() == datetime(
|
||||
2023, 1, 1, 0, 3, 56, tzinfo=timezone.utc
|
||||
2023, 1, 1, 0, 3, 56, tzinfo=UTC
|
||||
)
|
||||
assert trades["date"].max().to_pydatetime() == datetime(
|
||||
2023, 1, 2, 23, 17, 3, tzinfo=timezone.utc
|
||||
2023, 1, 2, 23, 17, 3, tzinfo=UTC
|
||||
)
|
||||
# ID is not filled
|
||||
assert len(trades.loc[trades["id"] != ""]) == 0
|
||||
|
||||
Reference in New Issue
Block a user