File tree Expand file tree Collapse file tree 2 files changed +58
-3
lines changed
Expand file tree Collapse file tree 2 files changed +58
-3
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Tests for utils
3+
4+ To run all tests in suite from commandline:
5+ python -m unittest tests.utils
6+
7+ Specific test class:
8+ python -m unittest tests.utils.TestTicker
9+
10+ """
11+ # import pandas as pd
12+ # import numpy as np
13+
14+ from .context import yfinance as yf
15+ from .context import session_gbl
16+
17+ import unittest
18+ # import requests_cache
19+ import tempfile
20+
21+
22+ class TestUtils (unittest .TestCase ):
23+ session = None
24+
25+ @classmethod
26+ def setUpClass (cls ):
27+ cls .tempCacheDir = tempfile .TemporaryDirectory ()
28+ yf .set_tz_cache_location (cls .tempCacheDir .name )
29+
30+ @classmethod
31+ def tearDownClass (cls ):
32+ cls .tempCacheDir .cleanup ()
33+
34+ def test_storeTzNoRaise (self ):
35+ # storing TZ to cache should never raise exception
36+ tkr = 'AMZN'
37+ tz1 = "America/New_York"
38+ tz2 = "London/Europe"
39+ cache = yf .utils .get_tz_cache ()
40+ cache .store (tkr , tz1 )
41+ cache .store (tkr , tz2 )
42+
43+
44+ def suite ():
45+ suite = unittest .TestSuite ()
46+ suite .addTest (TestUtils ('Test utils' ))
47+ return suite
48+
49+
50+ if __name__ == '__main__' :
51+ unittest .main ()
Original file line number Diff line number Diff line change @@ -980,10 +980,14 @@ def lookup(self, tkr):
980980 def store (self , tkr , tz ):
981981 if tz is None :
982982 self .tz_db .delete (tkr )
983- elif self .tz_db .get (tkr ) is not None :
984- raise Exception ("Tkr {} tz already in cache" .format (tkr ))
985983 else :
986- self .tz_db .set (tkr , tz )
984+ tz_db = self .tz_db .get (tkr )
985+ if tz_db is not None :
986+ if tz != tz_db :
987+ get_yf_logger ().debug (f'{ tkr } : Overwriting cached TZ "{ tz_db } " with different TZ "{ tz } "' )
988+ self .tz_db .set (tkr , tz )
989+ else :
990+ self .tz_db .set (tkr , tz )
987991
988992 @property
989993 def _db_dir (self ):
You can’t perform that action at this time.
0 commit comments