Skip to content

Commit

Permalink
Merge branch 'master' into KaizenTask1103_test_broker_with_multiple_o…
Browse files Browse the repository at this point in the history
…rders
  • Loading branch information
jayati1397 authored Aug 1, 2024
2 parents 1838087 + 423470c commit 25854d7
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion helpers/test/test_hdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<class 'str'>' instead of '<class 'pandas._libs.tslibs.timestamps.Timestamp'>'
"""
# Check.
self.assert_equal(act, exp, fuzzy_match=True)


# #############################################################################
# Test_dassert_timestamp_lt
# #############################################################################
Expand Down Expand Up @@ -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)

0 comments on commit 25854d7

Please sign in to comment.