mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 08:50:39 +00:00
Add argparse options to refresh_data
This commit is contained in:
1 parent
025821ed18
commit
4b3eeb21cc
3 files changed
+76
-14
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import sys
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
|
||||
sys.path.append(os.path.abspath("."))
|
||||
|
||||
import scripts.refresh_data as refresh_data
|
||||
|
||||
|
||||
def test_refresh_data_writes_series(tmp_path, monkeypatch):
|
||||
calls = []
|
||||
|
||||
def fake_reader(name, src, start, end):
|
||||
calls.append(name)
|
||||
dates = pd.date_range(start, periods=1)
|
||||
return pd.DataFrame({name: [1]}, index=dates)
|
||||
|
||||
monkeypatch.setattr(refresh_data, "DataReader", fake_reader)
|
||||
monkeypatch.setattr(refresh_data, "DATA_PATH", tmp_path)
|
||||
db_file = tmp_path / "fred.db"
|
||||
monkeypatch.setattr(refresh_data, "DB_FILE", db_file)
|
||||
|
||||
refresh_data.main(
|
||||
[
|
||||
"--series",
|
||||
"A",
|
||||
"B",
|
||||
"--start",
|
||||
"2000-01-01",
|
||||
"--end",
|
||||
"2000-01-02",
|
||||
]
|
||||
)
|
||||
|
||||
assert set(calls) == {"A", "B"}
|
||||
with sqlite3.connect(db_file) as conn:
|
||||
tables = {
|
||||
row[0]
|
||||
for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
||||
}
|
||||
assert {"A", "B"} <= tables
|
||||
Reference in new issue
Block a user