def test_instantiation(clp_params_df): """ Test (in)correct Debt instantiation """ good_btax_params = clp_params_df bad_btax_params = list() good_asset_forecast = np.ones(16) bad_asset_forecast = np.ones(13) good_data = Data() bad_data = list() good_response = np.zeros(16) bad_response = np.zeros(13) with pytest.raises(ValueError): Debt(bad_btax_params, good_asset_forecast) with pytest.raises(ValueError): Debt(good_btax_params, bad_asset_forecast) Debt(good_btax_params, good_asset_forecast, data=good_data) Debt(good_btax_params, good_asset_forecast, data=bad_data) with pytest.raises(ValueError): Debt(good_btax_params, good_asset_forecast, corp=list()) Debt(good_btax_params, good_asset_forecast, corp=False) with pytest.raises(ValueError): Debt(good_btax_params, good_asset_forecast, eta=-0.2) Debt(good_btax_params, good_asset_forecast, response=good_response) with pytest.raises(ValueError): Debt(good_btax_params, good_asset_forecast, response=bad_response)
def test_debt_interest_path(reform_number, corporate, reforms, actual_vs_expect): """ Test corp/non-corp interest path results under different reforms. """ asset = Asset(reforms[reform_number], corp=corporate) asset.calc_all() debt = Debt(reforms[reform_number], asset.get_forecast()) debt.calc_all() decimals = 2 interest_path = debt.interest_path.round(decimals) fname = 'debt_ref{}_{}_expect.csv'.format(reform_number, 'corp' if corporate else 'nonc') actual_vs_expect(interest_path, fname, precision=decimals)
def test_instantiation_and_update_methods(default_btax_params): """ Test (in)correct CorpTaxReturn instantiation and update_* methods """ good_btax_params = default_btax_params bad_btax_params = list() good_earnings = np.ones(14) bad1_earnings = np.ones(13) bad2_earnings = dict() good_data = Data() good_assets = Asset(default_btax_params) good_assets.calc_all() bad_assets = dict() good_debts = Debt(default_btax_params, np.ones(14)) good_debts.calc_all() bad_debts = dict() # test (in)correct instantiation with pytest.raises(ValueError): CorpTaxReturn(bad_btax_params, good_earnings) with pytest.raises(AssertionError): CorpTaxReturn(good_btax_params, bad1_earnings) with pytest.raises(AssertionError): CorpTaxReturn(good_btax_params, bad2_earnings) CorpTaxReturn(good_btax_params, good_earnings, data=Data()) CorpTaxReturn(good_btax_params, good_earnings, assets=good_assets) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, good_earnings, assets=bad_assets) CorpTaxReturn(good_btax_params, good_earnings, debts=good_debts) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, good_earnings, debts=bad_debts) # test update_* methods ctr = CorpTaxReturn(good_btax_params, good_earnings) assert isinstance(ctr, CorpTaxReturn) ctr.update_assets(good_assets) with pytest.raises(ValueError): ctr.update_assets(bad_assets) ctr.update_debts(good_debts) with pytest.raises(ValueError): ctr.update_debts(bad_debts) ctr.update_earnings(good_earnings)
def test_instantiation_and_update_methods(clp_params_df): """ Test (in)correct CorpTaxReturn instantiation and update_* methods """ good_btax_params = clp_params_df bad_btax_params = list() good_earnings = np.ones(16) bad1_earnings = np.ones(13) bad2_earnings = dict() good_data = Data() good_assets = Asset(clp_params_df) good_assets.calc_all() bad_assets = dict() good_debts = Debt(clp_params_df, np.ones(16)) good_debts.calc_all() bad_debts = dict() Corp = Corporation(good_btax_params) # test (in)correct instantiation with pytest.raises(ValueError): CorpTaxReturn(bad_btax_params, Corp.revenues, Corp.deductions, Corp.credits) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, bad1_earnings, Corp.deductions, Corp.credits) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, bad2_earnings, Corp.deductions, Corp.credits) CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits, data=Data()) CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits, assets=good_assets) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits, assets=bad_assets) CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits, debts=good_debts) with pytest.raises(ValueError): CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits, debts=bad_debts) # test update_* methods ctr = CorpTaxReturn(good_btax_params, Corp.revenues, Corp.deductions, Corp.credits) assert isinstance(ctr, CorpTaxReturn) ctr.update_assets(good_assets) with pytest.raises(ValueError): ctr.update_assets(bad_assets) ctr.update_debts(good_debts) with pytest.raises(ValueError): ctr.update_debts(bad_debts) ctr.update_earnings(good_earnings)
def test_constrain_history(clp_params_df): """ Test constrain_history method """ good_asset_forecast = np.ones(16) debt = Debt(clp_params_df, good_asset_forecast) debt.get_haircuts() debt.build_level_history() debt.build_flow_history() debt.originations[0] = -9.9 # triggers constrain_history logic debt.constrain_history() assert min(debt.originations) == 0.0