def test_account_group_str_repr(): prep_test_assets() ac0 = Account.define(name="PiggyBank", asset="EN") ac1 = Account.define(name="Sofa", asset="RON") ag = AccountGroup.define(name="Slush", accounts=[ac0, ac1]) logger.info("Caught a wild {0!s} made when a {0!r} got got".format(ag))
def test_accounting_equation_with_groups(): clear_all_definitions() Asset.define("USD") assets = AccountGroup.define(name="assets") liabilities = AccountGroup.define(name="liabilities") equity = AccountGroup.define(name="equity") shareholder_equity = Account.define(name="shareholder_equity", asset="USD") wells_fargo = Account.define(name="wells_fargo", asset="USD") equipment = Account.define(name="equipment", asset="USD") cash = Account.define(name="cash", asset="USD") assets.add(cash) assets.add(equipment) equity.add(shareholder_equity) liabilities.add(wells_fargo) ipo_amount = AssetAmount(amount=D(100), asset="USD") ipo_entry = DoubleEntry(src=shareholder_equity, dest=equipment, asset_amount=ipo_amount) loan_amount = AssetAmount(amount=D(50), asset="USD") loan_entry = DoubleEntry(src=wells_fargo, dest=cash, asset_amount=loan_amount) with GeneralLedger.transaction_lock: GeneralLedger.realize(ipo_entry) GeneralLedger.realize(loan_entry) assert_true(GeneralLedger.balance()[Asset["USD"]].amount == D(0)) assert_true(assets + liabilities + equity == AssetAmount(asset="USD", amount=D(0)))
def test_account_group_creation(): prep_test_assets() AccountGroup.define(name="EmbezzlingGeneral") ac0 = Account.define(name="PiggyBank", asset="EN") ac1 = Account.define(name="Sofa", asset="RON") ag = AccountGroup.define(name="Slush", accounts=[ac0, ac1]) assert_true(AccountGroup.get("Slush") is ag)
def test_double_entry_creation(): prep_test_assets() ac0 = Account.define(name="PiggyBank", asset="EN") ac1 = Account.define(name="Sofa", asset="EN") DoubleEntry(src=ac0, dest=ac1, amount="100.0") DoubleEntry(src=ac0, dest=ac1, amount=100, asset="EN") DoubleEntry(src=ac0, dest=ac1, amount=D(100), asset=Asset["EN"]) deposit = AccountEntry(account=ac0, amount=D(100.)) withdrawal = AccountEntry(account=ac1, amount=D(100.)) DoubleEntry(deposit=deposit, withdrawal=withdrawal)
def test_exchange_entry_str_and_repr(): prep_test_assets_and_pairs() Account.define(name="PiggyBank", asset="EN") Account.define(name="Sofa", asset="RON") rate = ExchangeRate(rate=D(2), base="EN", quote="RON") tde = ExchangeEntry(asset_amount=Asset["EN"].make_amount(1), rate=rate, src="PiggyBank", dest="Sofa") logger.info("Found a {0!s} created like so: {0!r}".format(tde))
def test_account_balance_math(): prep_test_assets() ac1 = Account.define(asset="EN", amount=D(12)) ac2 = Account.define(asset="RON", amount=D(10)) ab1 = AssetBalance() nosetools.eq_(ab1 + ac1, ac1) nosetools.eq_(ab1 + ac2, ac2) ab2 = AssetBalance() ab2 = ab2 + ac1 ab2 = ab2 + ac2 nosetools.eq_(ab2["EN"], ac1) nosetools.eq_(ab2["RON"], ac2)
def prep_test_ledger(): clear_all_definitions() Asset.define("USD") assets = AccountGroup.define(name="assets") liabilities = AccountGroup.define(name="liabilities") equity = AccountGroup.define(name="equity") shareholder_equity = Account.define(name="shareholder_equity", asset="USD") wells_fargo = Account.define(name="wells_fargo", asset="USD") equipment = Account.define(name="equipment", asset="USD") cash = Account.define(name="cash", asset="USD") assets.add(cash) assets.add(equipment) equity.add(shareholder_equity) liabilities.add(wells_fargo)
def test_exchange_entry_creation_and_realization(): prep_test_assets_and_pairs() foo = Asset["EN"] bar = Asset["RON"] pb = Account.define(name="PiggyBank", asset="EN") sofa = Account.define(name="Sofa", asset="RON") rate = ExchangeRate(rate=D(2.0), base="EN", quote="RON") tde = ExchangeEntry(asset_amount=Asset["EN"].make_amount(1), rate=rate, src="PiggyBank", dest="Sofa") nosetools.eq_(tde.withdrawal.amount, D(1)) nosetools.eq_(tde.deposit.amount, D(2)) with GeneralLedger.transaction_lock: GeneralLedger.realize(tde) nosetools.eq_(pb, foo.make_amount(-1)) nosetools.eq_(sofa, bar.make_amount(2))
def test_entries_balance_to_zero(): clear_all_definitions() Asset.define("USD") assets = Account.define(name="Assets", asset="USD") liabilities = Account.define(name="Liabilities", asset="USD") equity = Account.define(name="Equity", asset="USD") ipo_amount = AssetAmount(amount=D(100), asset="USD") ipo_entry = DoubleEntry(src=equity, dest=assets, asset_amount=ipo_amount) loan_amount = AssetAmount(amount=D(50), asset="USD") loan_entry = DoubleEntry(src=liabilities, dest=assets, asset_amount=loan_amount) with GeneralLedger.transaction_lock: GeneralLedger.realize(ipo_entry) GeneralLedger.realize(loan_entry) assert_true(GeneralLedger.balance()[Asset["USD"]].amount == D(0))
def test_account_creation(): prep_test_assets() Account.define(name="Piggybank", asset="EN", amount=0)
def get_test_account(): prep_test_assets() return Account.define(name="Piggybank", asset="EN", amount=0)
def test_wrong_name(): prep_test_assets() Account.define(name="Piggybank", asset="EN", amount=0) Account.get("PiggyBank_whoops")
def test_get_by_name(): prep_test_assets() ac0 = Account.define(name="PiggyBank", asset="EN", amount=0) ac1 = Account.get("PiggyBank") assert_true(ac0 is ac1)
def test_cannot_reuse_account_name(): prep_test_assets() Account.define(name="Piggybank", asset="EN", amount=0) Account.define(name="Piggybank", asset="EN", amount=0)
def test_double_entry_str_repr__(): prep_test_assets() ac0 = Account.define(name="PiggyBank", asset="EN") ac1 = Account.define(name="Sofa", asset="EN") de = DoubleEntry(src=ac0, dest=ac1, amount="100.0") logger.info("Found a {0!s} created like so: {0!r}".format(de))
def test_anon_account_def(): prep_test_assets() a = Account.define(asset="EN") assert (type(a.name) is str)
def test_cannot_instantiate_from_float_mindlessly(): prep_test_assets() my_fun_val = math.e a = Asset.get("EN") Account.define(name="Donut", asset=a, amount=my_fun_val)