def test_correct_update_growmodel(): gmod = GrowModel() gmod.update_growmodel({}) assert not gmod.is_ever_active() start_cyr = gmod.start_year active_cyr = 2018 gmod.update_growmodel({active_cyr: {'_active': [True]}}) for cyr in range(start_cyr, active_cyr): assert not gmod._active[cyr - start_cyr] for cyr in range(active_cyr, gmod.end_year + 1): assert gmod._active[cyr - start_cyr] assert gmod.is_ever_active() gmod.set_year(active_cyr - 1) assert not gmod.is_active()
def test_incorrect_update_growmodel(): with pytest.raises(ValueError): GrowModel().update_growmodel([]) with pytest.raises(ValueError): GrowModel().update_growmodel({2013: {'_active': [2]}}) with pytest.raises(ValueError): GrowModel().update_growmodel({2013: {'_active': [0.2]}}) with pytest.raises(ValueError): GrowModel().update_growmodel({2013: {'_activexxx': [True]}}) # year in update must be no less than start year gmod = GrowModel(start_year=2014) with pytest.raises(ValueError): gmod.update_growmodel({2013: {'_active': [True]}}) # year in update must be no less than current year gmod = GrowModel(start_year=2014) gmod.set_year(2015) with pytest.raises(ValueError): gmod.update_growmodel({2014: {'_active': [True]}}) # year in update must be no greater than end_year with pytest.raises(ValueError): GrowModel().update_growmodel({2040: {'_active': [True]}}) # invalid start year with pytest.raises(ValueError): GrowModel().update_growmodel({'notayear': {'_active': [True]}})