Skip to content

Commit 73ac751

Browse files
committed
added fixes to test
1 parent b8a454c commit 73ac751

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
def generate_market_data(trend_type, length=300, start_price=100, volatility=0.02):
99
"""
1010
Genera dati OHLCV coerenti matematicamente.
11-
High/Low sono derivati dal Close + Volatilità.
11+
Date: Termina OGGI e va indietro di 'length' giorni.
1212
"""
13-
dates = pd.date_range(start="2024-01-01", periods=length)
13+
# MODIFICA: Generazione date dinamica (fino a oggi)
14+
end_date = pd.Timestamp.now().normalize() # normalize mette l'ora a 00:00:00
15+
dates = pd.date_range(end=end_date, periods=length)
1416

1517
# Base trend
1618
x = np.linspace(0, 10, length)

tests/test_core/test_db_integration.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,35 @@ def test_db_ohlc_lifecycle(test_db):
77
Scrive OHLC, legge OHLC e verifica.
88
Usa il DB reale (che viene pulito dalla fixture).
99
"""
10-
# 1. Prepare Data
11-
# Tuple: (ticker, date, open, high, low, close, volume)
10+
# Calcoliamo date dinamiche
11+
today = date.today()
12+
yesterday = today - timedelta(days=1)
13+
two_days_ago = today - timedelta(days=2)
14+
15+
# 1. Prepare Data (Usiamo le date calcolate)
1216
raw_data = [
13-
("TEST_A", date(2024, 1, 1), 100, 110, 90, 105, 1000),
14-
("TEST_A", date(2024, 1, 2), 105, 115, 95, 110, 2000),
15-
("TEST_B", date(2024, 1, 1), 50, 55, 45, 52, 500)
17+
("TEST_A", two_days_ago, 100, 110, 90, 105, 1000),
18+
("TEST_A", yesterday, 105, 115, 95, 110, 2000),
19+
("TEST_B", two_days_ago, 50, 55, 45, 52, 500)
1620
]
1721

1822
# 2. Insert (Upsert)
1923
test_db.upsert_ohlc(raw_data)
2024

2125
fetched = test_db.get_ohlc(["TEST_A"], "2024-01-01", "2024-01-05")
2226

23-
# 3. Retrieve
24-
# Chiediamo solo TEST_A
25-
fetched = test_db.get_ohlc(["TEST_A"], "2024-01-01", "2024-01-05")
27+
## 3. Retrieve (Range specifico)
28+
# Convertiamo le date in stringa ISO per sicurezza nella query
29+
fetched = test_db.get_ohlc(["TEST_A"], two_days_ago.isoformat(), today.isoformat())
2630

2731
assert len(fetched) == 2
2832
assert fetched[0]['ticker'] == "TEST_A"
29-
assert float(fetched[0]['close']) == 105.0 # Postgres torna Decimal, convertiamo o confrontiamo bene
33+
assert float(fetched[0]['close']) == 105.0
3034

31-
# Chiediamo tutti gli storici
35+
# 4. Retrieve ALL (Il punto che falliva)
36+
# Ora funzionerà perché i dati sono di "ieri", quindi sicuramente negli ultimi 365 giorni
3237
all_data_map = test_db.get_ohlc_all_tickers(days=365)
3338

34-
print(f"DEBUG FETCHED: {all_data_map}")
35-
3639
assert "TEST_A" in all_data_map
3740
assert "TEST_B" in all_data_map
3841
assert len(all_data_map["TEST_A"]) == 2

tests/test_core/test_yfinance.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def test_fetch_ohlc_success(mock_download):
1414
data = {
1515
'Open': [100.0], 'High': [105.0], 'Low': [95.0], 'Close': [102.0], 'Volume': [1000]
1616
}
17-
mock_df = pd.DataFrame(data, index=pd.to_datetime(["2024-01-01"]))
18-
mock_df.index.name = "Date"
19-
# Aggiungiamo Ticker come colonna o indice a seconda di come yfinance si comporta quel giorno
20-
# Nel codice YFinanceManager gestiamo entrambi, qui simuliamo il reset_index
21-
mock_df['Ticker'] = "AAPL"
17+
today = pd.Timestamp.now().normalize()
18+
19+
mock_df = pd.DataFrame(data, index=[today])
20+
mock_df.index.name = "Date" # Ricorda il fix di prima!
21+
mock_df['Ticker'] = "AAPL"
2222

2323
mock_download.return_value = mock_df
2424

0 commit comments

Comments
 (0)