Skip to content

Commit

Permalink
Add test for '_parse_user_dt()'
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Jan 20, 2023
1 parent 5d9a91d commit 4d5df3f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest

from .context import yfinance as yf

import datetime as _dt
import pandas as _pd
import pytz as _pytz

class TestUtils(unittest.TestCase):

def test_parse_user_dt(self):
""" Purpose of _parse_user_dt() is to take any remotely-valid
representation of a datetime, combine with specified timezone and
return a localized datetime (well it's timestamp).
"""
tz_name = "America/New_York"
tz = _pytz.timezone(tz_name)
dt_answer = tz.localize(_dt.datetime(2023,1,1))

# All possible versions of 'dt_answer'
values = ["2023-01-01", _dt.date(2023,1,1), _dt.datetime(2023,1,1), _pd.Timestamp(_dt.date(2023,1,1))]
# - now add localized versions
values.append(tz.localize(_dt.datetime(2023,1,1)))
values.append(_pd.Timestamp(_dt.date(2023,1,1)).tz_localize(tz_name))
values.append(_pd.Timestamp(_dt.date(2023,1,1)).tz_localize(tz_name).timestamp())

for v in values:
v2 = yf.utils._parse_user_dt(v, tz_name)
self.assertEqual(v2, dt_answer.timestamp())

0 comments on commit 4d5df3f

Please sign in to comment.