From 3830a6de2b10cbe3a9e2a864fb16b426639a7abc Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Wed, 4 Oct 2023 11:21:09 -0600 Subject: [PATCH] Add a test of parse_isoduration and run it in black --- python/ctsm/test/test_unit_iso_utils.py | 27 +++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/python/ctsm/test/test_unit_iso_utils.py b/python/ctsm/test/test_unit_iso_utils.py index c087b23f64..c58beef52e 100755 --- a/python/ctsm/test/test_unit_iso_utils.py +++ b/python/ctsm/test/test_unit_iso_utils.py @@ -4,7 +4,6 @@ """ import unittest -import os from ctsm import unit_testing from ctsm.utils import parse_isoduration, get_isosplit @@ -22,15 +21,31 @@ def test_iso_split_for_Year(self): Tests the get_isosplit function for a strings with Years """ iso_string = "0Y" - self.assertEqual( get_isosplit(iso_string, "Y"), ("0", "") ) + self.assertEqual(get_isosplit(iso_string, "Y"), ("0", "")) iso_string = "1Y" - self.assertEqual( get_isosplit(iso_string, "Y"), ("1", "") ) + self.assertEqual(get_isosplit(iso_string, "Y"), ("1", "")) iso_string = "4Y" - self.assertEqual( get_isosplit(iso_string, "Y"), ("4", "") ) + self.assertEqual(get_isosplit(iso_string, "Y"), ("4", "")) iso_string = "100Y" - self.assertEqual( get_isosplit(iso_string, "Y"), ("100", "") ) + self.assertEqual(get_isosplit(iso_string, "Y"), ("100", "")) iso_string = "999999Y" - self.assertEqual( get_isosplit(iso_string, "Y"), ("999999", "") ) + self.assertEqual(get_isosplit(iso_string, "Y"), ("999999", "")) + + def test_parse_isoduration_for_Years(self): + """ + Tests the parse_isoduration function for iso strings with Years + """ + days_in_year = 365 + iso_string = "0Y" + self.assertEqual(parse_isoduration(iso_string), 0) + iso_string = "1Y" + self.assertEqual(parse_isoduration(iso_string), days_in_year) + iso_string = "4Y" + self.assertEqual(parse_isoduration(iso_string), 4 * days_in_year) + iso_string = "100Y" + self.assertEqual(parse_isoduration(iso_string), 100 * days_in_year) + iso_string = "999999Y" + self.assertEqual(parse_isoduration(iso_string), 999999 * days_in_year) if __name__ == "__main__":