diff --git a/helpers/test/test_hdatetime.py b/helpers/test/test_hdatetime.py index a389b17af5..7d06f24df8 100644 --- a/helpers/test/test_hdatetime.py +++ b/helpers/test/test_hdatetime.py @@ -775,6 +775,64 @@ def test2(self) -> None: self.check_string(actual) +# ############################################################################# +# Test_dassert_is_valid_timestamp +# ############################################################################# + + +class Test_dassert_is_valid_timestamp(hunitest.TestCase): + def test1(self) -> None: + """ + Test should not raise an exception when timestamp has a timezone. + """ + timestamp = pd.Timestamp( + "2021-01-04 09:30:00-05:00", tz="America/New_York" + ) + hdateti.dassert_is_valid_timestamp(timestamp) + + def test2(self) -> None: + """ + Test should raise an exception when timestamp is without timezone info. + """ + # Set inputs. + timestamp = pd.Timestamp("2021-01-04 09:30:00") + # Run. + with self.assertRaises(AssertionError) as cm: + hdateti.dassert_is_valid_timestamp(timestamp) + act = str(cm.exception) + exp = """ + * Failed assertion * + 'None' is not 'None' + datetime_='2021-01-04 09:30:00' doesn't have timezone info + """ + # Check. + self.assert_equal(act, exp, fuzzy_match=True) + + def test3(self) -> None: + """ + Test should not raise an exception when timestamp is none. + """ + timestamp = None + hdateti.dassert_is_valid_timestamp(timestamp) + + def test4(self) -> None: + """ + Test should raise an exception when timestamp is of type string. + """ + # Set input. + timestamp = "2021-01-04 09:30:00" + # Run. + with self.assertRaises(AssertionError) as cm: + hdateti.dassert_is_valid_timestamp(timestamp) + act = str(cm.exception) + exp = """ + * Failed assertion * + Instance of '2021-01-04 09:30:00' is '' instead of '' + """ + # Check. + self.assert_equal(act, exp, fuzzy_match=True) + + # ############################################################################# # Test_dassert_timestamp_lt # ############################################################################# @@ -856,4 +914,4 @@ def test6(self) -> None: """ start_timestamp = None end_timestamp = None - hdateti.dassert_timestamp_lt(start_timestamp, end_timestamp) + hdateti.dassert_timestamp_lt(start_timestamp, end_timestamp) \ No newline at end of file