Skip to content

Commit

Permalink
made the time zone a raw string, fixing issue USDA-ARS-NWRC#96
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthavens committed Jun 10, 2020
1 parent a9d16df commit e877a0d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions smrf/framework/CoreConfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ description = Date and time to end the data distribution that can be parsed by p

time_zone:
default = UTC,
type = RawString,
description = Time zone for all times provided and how the model will be run see pytz docs for information on what is accepted

################################################################################
Expand Down
20 changes: 20 additions & 0 deletions smrf/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ def type_func(self, value):
return value.upper()


class CheckRawString(CheckType):
"""
Custom `inicheck` checker that will not change the input string
"""

def __init__(self, **kwargs):
super(CheckRawString, self).__init__(**kwargs)

def type_func(self, value):
"""
Do not change the passed value at all
Args:
value: A single string
Returns:
value: A single string unchanged
"""

return value


def find_configs(directory):
"""
Searches through a directory and returns all the .ini fulll filenames.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ filename: ./RME/topo/topo.nc
time_step: 60
start_date: 1998-01-14 15:00:00
end_date: 1998-01-14 19:00:00
time_zone: utc
time_zone: UTC


################################################################################
Expand Down
10 changes: 8 additions & 2 deletions tests/test_model_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ class TestModelFrameworkMST(SMRFTestCase):
"""
Test timezone handling for MST.
"""
TIMEZONE = pytz.timezone('US/Mountain')
TIMEZONE = pytz.timezone('MST')

@classmethod
def setUpClass(cls):
super().setUpClass()
base_config = copy.deepcopy(cls.base_config)
base_config.cfg['time']['time_zone'] = str(cls.TIMEZONE)
base_config.cfg['time']['time_zone'] = 'MST'
cls.smrf = SMRF(base_config)

def test_timezone_error(self):
base_config = copy.deepcopy(self.base_config)
base_config.cfg['time']['time_zone'] = 'mst'
with self.assertRaises(Exception):
SMRF(base_config)

def test_start_date(self):
self.assertEqual(
self.smrf.start_date,
Expand Down

0 comments on commit e877a0d

Please sign in to comment.