def test_update_response(default_btax_params): """ Test update_response method """ asset = Asset(default_btax_params) assert asset.response is None response_df = pd.DataFrame() asset.update_response(response_df) assert isinstance(asset.response, pd.DataFrame)
def test_calc_depreciation_budget(default_btax_params): """ Test calcDep_budget method """ asset = Asset(default_btax_params) asset.get_ccr_data() asset.build_inv_matrix() asset.build_deprLaw_matrices() asset.calcDep_allyears()
def test_incorrect_instantiation(): """ Test incorrect Asset instantiation """ with pytest.raises(ValueError): Asset(list()) with pytest.raises(ValueError): Asset(pd.DataFrame(), corp=list()) with pytest.raises(ValueError): Asset(pd.DataFrame(), response=list())
def test_asset_capital_path(reform_number, corporate, reforms, actual_vs_expect): """ Test corp/non-corp capital path results under different reforms. """ asset = Asset(reforms[reform_number], corp=corporate) asset.calc_all() decimals = 2 capital_path = asset.capital_path.round(decimals) fname = 'asset_ref{}_{}_expect.csv'.format(reform_number, 'corp' if corporate else 'nonc') actual_vs_expect(capital_path, fname, precision=decimals)
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_calc_depreciation_allyears(puf_subsample, default_btax_params): """ Test calcDep_allyears method """ bizmod = BusinessModel({}, {}, investor_data=puf_subsample) bizmod.update_mtrlists() response_elasticities = { 'inv_usercost_c': -1.0, 'inv_usercost_nc': -0.5, 'inv_eatr_c': 0.0, 'inv_eatr_nc': 0.0, 'debt_taxshield_c': 0.4, 'debt_taxshield_nc': 0.2, 'mne_share_c': 0.0, 'mne_share_nc': 0.0, 'first_year_response': 2018 } bizmod.response = Response(response_elasticities, {}, {}) bizmod.response.calc_all() asset = Asset(default_btax_params, response=bizmod.response.investment_response) asset.calcDep_allyears()
def test_build_inv_matrix(default_btax_params): """ Test build_inv_matrix method with response """ resp_elasticities = {'inv_usercost_c': -1.0, 'inv_usercost_nc': -0.5} resp = Response(resp_elasticities, default_btax_params, default_bax_params) resp.calc_inv_response() asset = Asset(default_btax_params, response=resp.investment_response) asset.get_ccr_data() asset.build_inv_matrix() assert isinstance(asset.investment_history, pd.DataFrame)
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)