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

unti test for dassert_is_valid_timestamp #1097

Merged
54 changes: 54 additions & 0 deletions helpers/test/test_hdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,57 @@ def test2(self) -> None:
hdateti.dassert_str_is_date(date)
actual = str(err.exception)
self.check_string(actual)

# #############################################################################
# Test_dassert_is_valid_timestamp
# #############################################################################

class Test_dassert_is_valid_timestamp(hunitest.TestCase):
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved

def test1(self) -> None:
"""
Test by checking a timestamp with a timezone.
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved
"""
timestamp = pd.Timestamp("2021-01-04 09:30:00-05:00", tz="America/New_York")
# This should not raise any exceptions.
hdateti.dassert_is_valid_timestamp(timestamp)


jayati1397 marked this conversation as resolved.
Show resolved Hide resolved
def test2(self) -> None:
"""
Check timestamp without a timezone info, should raise an exception.
"""
timestamp = pd.Timestamp("2021-01-04 09:30:00")
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.
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved
self.assert_equal(act, exp, fuzzy_match=True)

def test3(self) -> None:
"""
Test by checking a timestamp as None.
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved
"""
timestamp = None
# This should not raise any exceptions.
hdateti.dassert_is_valid_timestamp(timestamp)

def test4(self) -> None:
"""
Test by passing a timestamp as a string, should raise an exception.
"""
timestamp = "2021-01-04 09:30:00"
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 '<class 'str'>' instead of '<class 'pandas._libs.tslibs.timestamps.Timestamp'>'
"""
#check.
self.assert_equal(act, exp, fuzzy_match=True)
Loading