mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 17:00:41 +00:00
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import matplotlib
|
|
|
|
matplotlib.use("Agg")
|
|
|
|
import os
|
|
import sys
|
|
import pandas as pd
|
|
|
|
sys.path.append(os.path.abspath("."))
|
|
|
|
from scripts.lagged_oil_unrate_chart_styled import plot_lagged
|
|
from scripts.custom_chart import plot_series, main as custom_main
|
|
|
|
|
|
def test_plot_lagged_returns_figure():
|
|
dates = pd.date_range("2000-01-01", periods=5, freq="M")
|
|
unrate = pd.DataFrame({"value": [5, 6, 7, 5, 4]}, index=dates)
|
|
oil = pd.DataFrame({"value": [20, 25, 30, 35, 40]}, index=dates)
|
|
|
|
fig = plot_lagged(unrate, oil, 1, dates[0], dates[-1], 0)
|
|
|
|
assert len(fig.axes) == 2
|
|
assert any(ax.get_lines() for ax in fig.axes)
|
|
|
|
|
|
def test_plot_series_and_main():
|
|
dates = pd.date_range("2020-01-01", periods=3, freq="D")
|
|
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=dates)
|
|
fig = plot_series(df)
|
|
assert len(fig.axes) == 1
|
|
assert any(fig.axes[0].get_lines())
|
|
|
|
fig2 = custom_main(
|
|
[
|
|
"--series",
|
|
"UNRATE",
|
|
"DCOILWTICO",
|
|
"--start",
|
|
"2020-01-01",
|
|
"--end",
|
|
"2020-03-01",
|
|
"--db",
|
|
"data/fred.db",
|
|
]
|
|
)
|
|
assert len(fig2.axes) == 1
|
|
assert any(fig2.axes[0].get_lines())
|