def test_update_and_apply_growdiff(): gdiff = GrowDiff() # update GrowDiff instance diffs = { 'AWAGE': {2014: 0.01, 2016: 0.02} } gdiff.update_growdiff(diffs) expected_wage_diffs = [0.00, 0.01, 0.01, 0.02, 0.02] extra_years = GrowDiff.DEFAULT_NUM_YEARS - len(expected_wage_diffs) expected_wage_diffs.extend([0.02] * extra_years) assert np.allclose(gdiff._AWAGE, expected_wage_diffs, atol=0.0, rtol=0.0) # apply growdiff to GrowFactors instance gf = GrowFactors() syr = GrowDiff.JSON_START_YEAR nyrs = GrowDiff.DEFAULT_NUM_YEARS lyr = syr + nyrs - 1 pir_pre = gf.price_inflation_rates(syr, lyr) wgr_pre = gf.wage_growth_rates(syr, lyr) gfactors = GrowFactors() gdiff.apply_to(gfactors) pir_pst = gfactors.price_inflation_rates(syr, lyr) wgr_pst = gfactors.wage_growth_rates(syr, lyr) expected_wgr_pst = [wgr_pre[i] + expected_wage_diffs[i] for i in range(0, nyrs)] assert np.allclose(pir_pre, pir_pst, atol=0.0, rtol=0.0) assert np.allclose(wgr_pst, expected_wgr_pst, atol=1.0e-9, rtol=0.0)
def test_update_and_apply_growdiff(): gdiff = GrowDiff() # update GrowDiff instance diffs = {'AWAGE': {2014: 0.01, 2016: 0.02}} gdiff.update_growdiff(diffs) expected_wage_diffs = [0.00, 0.01, 0.01, 0.02, 0.02] extra_years = GrowDiff.DEFAULT_NUM_YEARS - len(expected_wage_diffs) expected_wage_diffs.extend([0.02] * extra_years) assert np.allclose(gdiff._AWAGE, expected_wage_diffs, atol=0.0, rtol=0.0) # apply growdiff to GrowFactors instance gf = GrowFactors() syr = GrowDiff.JSON_START_YEAR nyrs = GrowDiff.DEFAULT_NUM_YEARS lyr = syr + nyrs - 1 pir_pre = gf.price_inflation_rates(syr, lyr) wgr_pre = gf.wage_growth_rates(syr, lyr) gfactors = GrowFactors() gdiff.apply_to(gfactors) pir_pst = gfactors.price_inflation_rates(syr, lyr) wgr_pst = gfactors.wage_growth_rates(syr, lyr) expected_wgr_pst = [ wgr_pre[i] + expected_wage_diffs[i] for i in range(0, nyrs) ] assert np.allclose(pir_pre, pir_pst, atol=0.0, rtol=0.0) assert np.allclose(wgr_pst, expected_wgr_pst, atol=1.0e-9, rtol=0.0)
def test_improper_usage(bad_gf_file): """ Tests of improper usage of GrowFactors object. """ with pytest.raises(ValueError): gfo = GrowFactors(dict()) with pytest.raises(ValueError): gfo = GrowFactors(bad_gf_file.name) gfo = GrowFactors() fyr = gfo.first_year lyr = gfo.last_year with pytest.raises(ValueError): gfo.price_inflation_rates(fyr - 1, lyr) with pytest.raises(ValueError): gfo.price_inflation_rates(fyr, lyr + 1) # with pytest.raises(ValueError): # gfo.price_inflation_rates(lyr, fyr) with pytest.raises(ValueError): gfo.wage_growth_rates(fyr - 1, lyr) with pytest.raises(ValueError): gfo.wage_growth_rates(fyr, lyr + 1) # with pytest.raises(ValueError): # gfo.wage_growth_rates(lyr, fyr) with pytest.raises(ValueError): gfo.factor_value('BADNAME', fyr) with pytest.raises(ValueError): gfo.factor_value('CPI', fyr - 1) with pytest.raises(ValueError): gfo.factor_value('SALARY', lyr + 1)
def test_proper_usage(): """ Test proper usage of GrowFactors object. """ gfo = GrowFactors() pir = gfo.price_inflation_rates(2017, 2017) assert len(pir) == 1 wgr = gfo.wage_growth_rates(2017, 2017) assert len(wgr) == 1
def test_proper_usage(): """ Test proper usage of GrowFactors object. """ gfo = GrowFactors() pir = gfo.price_inflation_rates(2013, 2020) assert len(pir) == 8 wgr = gfo.wage_growth_rates(2013, 2021) assert len(wgr) == 9 val = gfo.factor_value('AWAGE', 2013) assert val > 1.0
def test_improper_usage(bad_gf_file): """ Tests of improper usage of GrowFactors object. """ with pytest.raises(ValueError): gfo = GrowFactors(dict()) with pytest.raises(ValueError): gfo = GrowFactors(bad_gf_file.name) gfo = GrowFactors() fyr = gfo.first_year lyr = gfo.last_year with pytest.raises(ValueError): gfo.price_inflation_rates(fyr - 1, lyr) with pytest.raises(ValueError): gfo.price_inflation_rates(fyr, lyr + 1) with pytest.raises(ValueError): gfo.price_inflation_rates(lyr, fyr) with pytest.raises(ValueError): gfo.wage_growth_rates(fyr - 1, lyr) with pytest.raises(ValueError): gfo.wage_growth_rates(fyr, lyr + 1) with pytest.raises(ValueError): gfo.wage_growth_rates(lyr, fyr) with pytest.raises(ValueError): gfo.factor_value('BADNAME', fyr) with pytest.raises(ValueError): gfo.factor_value('AWAGE', fyr - 1) with pytest.raises(ValueError): gfo.factor_value('AWAGE', lyr + 1)
def test_update_and_apply_growdiff(): syr = 2013 nyrs = 5 lyr = syr + nyrs - 1 gdiff = GrowDiff(start_year=syr, num_years=nyrs) # update GrowDiff instance diffs = {2014: {'_AWAGE': [0.01]}, 2016: {'_AWAGE': [0.02]}} gdiff.update_growdiff(diffs) expected_wage_diffs = [0.00, 0.01, 0.01, 0.02, 0.02] assert_allclose(gdiff._AWAGE, expected_wage_diffs, atol=0.0, rtol=0.0) # apply growdiff to GrowFactors instance gf = GrowFactors() pir_pre = gf.price_inflation_rates(syr, lyr) wgr_pre = gf.wage_growth_rates(syr, lyr) gfactors = GrowFactors() gdiff.apply_to(gfactors) pir_pst = gfactors.price_inflation_rates(syr, lyr) wgr_pst = gfactors.wage_growth_rates(syr, lyr) expected_wgr_pst = [ wgr_pre[i] + expected_wage_diffs[i] for i in range(0, nyrs) ] assert_allclose(pir_pre, pir_pst, atol=0.0, rtol=0.0) assert_allclose(wgr_pst, expected_wgr_pst, atol=1.0e-9, rtol=0.0)