adding test cases

This commit is contained in:
Florian Förster 2025-02-19 12:47:07 +01:00
parent 8fa429d477
commit 0c76dc0325
4 changed files with 125485 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

View File

@ -0,0 +1,17 @@
from delta_barth.analysis import forecast as fc
def test_sales_per_customer_success(sales_data):
customer_id = 1133
err, res = fc.sales_per_customer(sales_data, customer_id)
assert err == 0
assert res is not None
def test_sales_per_customer_too_few_data_points(sales_data):
customer_id = 1000
err, res = fc.sales_per_customer(sales_data, customer_id)
assert err == 1
assert res is None

38
tests/conftest.py Normal file
View File

@ -0,0 +1,38 @@
from pathlib import Path
from typing import Any
import pandas as pd
import pytest
# TODO: maybe include in main package depending if needed in future
def _cvt_str_float(value: str) -> float:
import locale
locale.setlocale(locale.LC_NUMERIC, "de_DE.UTF-8")
return locale.atof(value)
def _cvt_str_ts(value: str) -> Any:
date = value.split("_")[0]
return pd.to_datetime(date, format="%Y%m%d", errors="coerce")
@pytest.fixture(scope="session")
def sales_data() -> pd.DataFrame:
pwd = Path.cwd()
assert "barth" in pwd.parent.name.lower(), "not in project root directory"
data_pth = pwd / "./tests/_test_data/swm_f_umsatz_fakt.csv"
assert data_pth.exists(), "file to sales data not found"
data = pd.read_csv(data_pth, sep="\t")
data["betrag"] = data["betrag"].apply(_cvt_str_float)
data["buchungs_datum"] = data["buchungs_datum"].apply(_cvt_str_ts)
data = data.dropna(
how="any",
subset=["firma_refid", "beleg_typ", "buchungs_datum", "betrag"],
ignore_index=True,
)
data["buchungs_datum"] = pd.to_datetime(data["buchungs_datum"])
return data