62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
"""Tests for state (L_cb, open economy) and new IPSAS helpers."""
|
|
|
|
import pytest
|
|
from fqbm.state import FQBMState, open_economy_view
|
|
from fqbm.ipsas.presentation import (
|
|
statement_of_changes_in_net_assets_structure,
|
|
cash_flow_from_state_changes,
|
|
fx_translate,
|
|
)
|
|
|
|
|
|
def test_state_has_L_cb():
|
|
state = FQBMState(B=100, L_cb=20, R=80, C=30, E_cb=10)
|
|
assert state.L_cb == 20
|
|
assert len(state.to_vector()) == 12
|
|
assert state.to_vector()[-1] == 20
|
|
|
|
|
|
def test_from_vector_backward_compat():
|
|
# 11 elements still supported
|
|
state = FQBMState.from_vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
|
|
assert state.L_cb == 0
|
|
state12 = FQBMState.from_vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
|
|
assert state12.L_cb == 12
|
|
|
|
|
|
def test_open_economy_view():
|
|
v = open_economy_view(100, 50, 80, 40, 30)
|
|
assert v["total_assets"] == 150
|
|
assert v["total_liab_equity"] == 150
|
|
assert v["identity_holds"] is True
|
|
v2 = open_economy_view(100, 50, 90, 40, 30)
|
|
assert v2["identity_holds"] is False
|
|
|
|
|
|
def test_statement_of_changes_in_net_assets_structure():
|
|
df = statement_of_changes_in_net_assets_structure()
|
|
assert "Opening balance" in df.columns
|
|
assert "Closing balance" in df.columns
|
|
assert df.attrs.get("ipsas_1_changes") is True
|
|
|
|
|
|
def test_cash_flow_from_state_changes():
|
|
prev = FQBMState(R=100, C=20, B=50, Loans=200, Deposits=180)
|
|
curr = FQBMState(R=110, C=22, B=55, Loans=210, Deposits=195)
|
|
df = cash_flow_from_state_changes(prev, curr)
|
|
assert "Category" in df.columns
|
|
assert "Amount" in df.columns
|
|
assert df.attrs.get("ipsas_2_from_state") is True
|
|
# Net change should be consistent
|
|
row = df[df["Line item"].str.contains("Net increase", na=False)]
|
|
assert len(row) == 1
|
|
|
|
|
|
def test_fx_translate():
|
|
r = fx_translate(100.0, 1.0, 1.1)
|
|
assert r["local_prev"] == pytest.approx(100)
|
|
assert r["local_curr"] == pytest.approx(110)
|
|
assert r["fx_gain_loss"] == pytest.approx(10)
|
|
r2 = fx_translate(100.0, 1.2, 1.0)
|
|
assert r2["fx_gain_loss"] == pytest.approx(-20)
|