def test_equality(): clear_all_definitions() Asset.define("EN") a1 = Asset.get("EN") a2 = Asset.get("EN") assert_true(a1 == a2) assert_true(a1 is a2)
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 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_asset_balance_comparisons(): clear_all_definitions() k = Asset.define("KET") b0 = AssetBalance() b1 = AssetBalance() b0[k] = AssetAmount(asset=k, amount=D("123")) b1[k] = AssetAmount(asset=k, amount=D("123")) assert_true(AssetAmount(asset=k, amount=D("123")) == b1) assert_true(b0 == AssetAmount(asset=k, amount=D("123"))) assert_true(b0 == b1)
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 cannot_create_asset_from_asset(): prep_test_assets() a = Asset.get("EN") Asset.define(a)
def cannot_doubly_define(): clear_all_definitions() Asset.define("EN") Asset.define("EN")
def test_asset_definition(): clear_all_definitions() Asset.define("EN") Asset.get("EN") Asset["EN"]
def prep_test_assets(): clear_all_definitions() Asset.define("EN") Asset.define("RON")
def test_asset_str_and_repr(): clear_all_definitions() a = Asset.define("EN") logger.info("Found a {0!s} made by {0!r}".format(a))
def test_make_amount(): clear_all_definitions() a = Asset.define("EN") a.make_amount(D(1)) a.make_amount(10) a.make_amount()
def cannot_compare_to_strings(): prep_test_assets() a = Asset.define("EN") if a != "RON": logger.info("I think it's safe to skip this account")