Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown veg_ values cause issues in albedo decay methods #215

Open
wants to merge 1 commit into
base: release-0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ oset==0.1.3
pandas==0.22.0
pbr==3.1.1
progressbar2==3.6.2
pybtex==0.21
pybtex==0.24
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version 0.21 won't build with the latest setup tools due to use_2to3 being a deprecated option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this package needed and where is it used? The current version removed a lot of requirements that aren't needed.

pybtex-docutils==0.2.1
pycodestyle==2.3.1
pyflakes==1.5.0
Expand Down
45 changes: 41 additions & 4 deletions tests/test_configurations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest
import os, shutil
from inicheck.tools import get_user_config, check_config
from inicheck.tools import get_user_config, check_config, cast_all_variables
from copy import deepcopy

from smrf.framework.model_framework import can_i_run_smrf
from smrf.framework.model_framework import can_i_run_smrf, SMRF
from smrf.distribute.albedo import albedo


class SMRFTestCase(unittest.TestCase):
Expand Down Expand Up @@ -42,7 +44,8 @@ def tearDown(self):
try:
if os.path.isfile(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path): shutil.rmtree(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(e)

Expand Down Expand Up @@ -83,7 +86,6 @@ def setUpClass(cls):
# print(e)



class TestConfigurations(SMRFTestCase):

def test_base_run(self):
Expand All @@ -99,3 +101,38 @@ def test_base_run(self):
# test the base run with the config file
result = can_i_run_smrf(self.base_config)
self.assertTrue(result)


class TestConfigPermutations(unittest.TestCase):

def setUp(self) -> None:
config_file = os.path.join(
os.path.dirname(__file__), "test_base_config.ini"
)
self.base_config = get_user_config(config_file, modules='smrf')

def test_albedo_veg_unknown_values(self):
config_updates = {
"start_decay": ['1998-01-12'],
"end_decay": ['1998-07-01'],
"decay_method": ["date_method"],
"veg_1000": ["0.2"]
}
base_config = deepcopy(self.base_config)
base_config.raw_cfg["albedo"].update(config_updates)

base_config.apply_recipes()
test_config = cast_all_variables(base_config, base_config.mcfg)

warnings, errors = check_config(test_config)
self.assertTrue(len(errors) == 0)

# the issue is that we parse this as ['0.2']
self.assertEqual(test_config.cfg["albedo"]["veg_1000"], ['0.2'])
smrf_obj = SMRF(test_config)
albedo_obj = albedo(smrf_obj.ucfg.cfg["albedo"])

# show that we parsed the unknown values correctly in albedo section
self.assertEqual(0.2, albedo_obj.veg["1000"])
# default values still come in correctly
self.assertEqual(0.36, albedo_obj.veg["41"])