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

SorrTask904 Unit test find_min_max_timestamps_from_intervals() #911

Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 134 additions & 2 deletions dataflow/core/test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime
import logging
from typing import Tuple

import pandas as pd
import pytz

import dataflow.core.utils as dtfcorutil
import helpers.hunit_test as hunitest
Expand Down Expand Up @@ -149,7 +151,9 @@ def test3(self) -> None:
1 <= 0
################################################################################
"""
self.assert_equal(actual_error_message, expected_error_message, fuzzy_match=True)
self.assert_equal(
actual_error_message, expected_error_message, fuzzy_match=True
)

def test4(self) -> None:
"""
Expand Down Expand Up @@ -186,7 +190,9 @@ def test5(self) -> None:
names=[None, 'id']))' is '<class 'tuple'>' instead of '<class 'pandas.core.frame.DataFrame'>'
################################################################################
"""
self.assert_equal(actual_error_message, expected_error_message, fuzzy_match=True)
self.assert_equal(
actual_error_message, expected_error_message, fuzzy_match=True
)

def test6(self) -> None:
"""
Expand All @@ -201,3 +207,129 @@ def test6(self) -> None:
actual_df = dtfcorutil.convert_to_multiindex(df, asset_id_col)
# Compare the result.
self.assert_multiindex_columns_equal(expected_df_columns, actual_df)


class TestFindMinMaxTimestampsFromIntervals(hunitest.TestCase):
neha2801-create marked this conversation as resolved.
Show resolved Hide resolved
def test1(self) -> None:
"""
Check for the case when no intervals are provided.
"""
intervals = None
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (None, None)
self.assertEqual(expected, actual)
neha2801-create marked this conversation as resolved.
Show resolved Hide resolved

def test2(self) -> None:
"""
Check for a single interval where both endpoints are empty.
"""
intervals = [(None, None)]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (None, None)
self.assertEqual(expected, actual)

def test3(self) -> None:
"""
Check for a single interval with valid endpoints.
"""
intervals = [
(
datetime.datetime(2022, 1, 1, 10, 0, 0),
datetime.datetime(2022, 1, 1, 11, 0, 0),
)
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (
datetime.datetime(2022, 1, 1, 10, 0, 0),
datetime.datetime(2022, 1, 1, 11, 0, 0),
)
self.assertEqual(expected, actual)

def test4(self) -> None:
"""
Check for a single interval where both endpoints are the same.
"""
intervals = [
(
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
)
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
)
self.assertEqual(expected, actual)

def test5(self) -> None:
"""
Check for multiple intervals with a mix of valid and empty endpoints.
"""
intervals = [
(pd.Timestamp(2022, 1, 1, 10, tz="UTC"), None),
(None, pd.Timestamp(2022, 1, 1, 11, tz="UTC")),
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (None, None)
self.assertEqual(expected, actual)

def test6(self) -> None:
"""
Check for multiple intervals with valid endpoints.
"""
intervals = [
(
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
pd.Timestamp(2022, 1, 1, 11, tz="UTC"),
),
(
pd.Timestamp(2022, 1, 1, 6, tz="UTC"),
pd.Timestamp(2022, 1, 1, 9, tz="UTC"),
),
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (
pd.Timestamp(2022, 1, 1, 6, tz="UTC"),
pd.Timestamp(2022, 1, 1, 11, tz="UTC"),
)
self.assertEqual(expected, actual)

def test7(self) -> None:
"""
Check for multiple intervals with valid endpoints of different time
zones.
"""
intervals = [
(
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
pd.Timestamp(2022, 1, 1, 11, tz="UTC"),
),
(
pd.Timestamp(2022, 1, 1, 10, tz="EST"),
pd.Timestamp(2022, 1, 1, 11, tz="EST"),
),
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected = (
pd.Timestamp(2022, 1, 1, 10, tz="UTC"),
pd.Timestamp(2022, 1, 1, 11, tz="EST"),
)
self.assertEqual(expected, actual)

def test8(self) -> None:
"""
Check for an interval with different endpoint types.
"""
intervals = [
(
datetime.datetime(2022, 1, 1, 10, 0, 0, tzinfo=pytz.utc),
neha2801-create marked this conversation as resolved.
Show resolved Hide resolved
pd.Timestamp(2022, 1, 1, 11, tz="UTC"),
)
]
actual = dtfcorutil.find_min_max_timestamps_from_intervals(intervals)
expected_min_max = (
neha2801-create marked this conversation as resolved.
Show resolved Hide resolved
datetime.datetime(2022, 1, 1, 10, 0, 0, tzinfo=pytz.utc),
pd.Timestamp(2022, 1, 1, 11, tz="UTC"),
)
self.assertEqual(expected_min_max, actual)
Loading