From e877a0d400750e0cf06a9199b11cf89b929d56f3 Mon Sep 17 00:00:00 2001 From: Scott Havens Date: Wed, 10 Jun 2020 15:01:16 -0600 Subject: [PATCH] made the time zone a raw string, fixing issue #96 --- smrf/framework/CoreConfig.ini | 1 + smrf/utils/utils.py | 20 ++++++++++++++++++++ tests/test_base_config.ini | 2 +- tests/test_model_framework.py | 10 ++++++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/smrf/framework/CoreConfig.ini b/smrf/framework/CoreConfig.ini index 9228d3e7..aee20e00 100755 --- a/smrf/framework/CoreConfig.ini +++ b/smrf/framework/CoreConfig.ini @@ -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 ################################################################################ diff --git a/smrf/utils/utils.py b/smrf/utils/utils.py index bd08fed9..14da5001 100755 --- a/smrf/utils/utils.py +++ b/smrf/utils/utils.py @@ -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. diff --git a/tests/test_base_config.ini b/tests/test_base_config.ini index e21b198f..1a607383 100644 --- a/tests/test_base_config.ini +++ b/tests/test_base_config.ini @@ -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 ################################################################################ diff --git a/tests/test_model_framework.py b/tests/test_model_framework.py index a6fa5d5a..f0b16662 100644 --- a/tests/test_model_framework.py +++ b/tests/test_model_framework.py @@ -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,