Change empty '_cached_instance' of dateutil after zonefile update.

Change add network_timezone tests.
This commit is contained in:
Prinz23 2018-09-05 00:01:34 +01:00 committed by JackDandy
parent 86086b900f
commit 07bb23bfa8
4 changed files with 59 additions and 1 deletions

View file

@ -3,6 +3,7 @@
* Update Beautiful Soup 4.6.0 (r449) to 4.6.3 (r475) * Update Beautiful Soup 4.6.0 (r449) to 4.6.3 (r475)
* Update CacheControl library 0.12.4 (bd94f7e) to 0.12.5 (cd91309) * Update CacheControl library 0.12.4 (bd94f7e) to 0.12.5 (cd91309)
* Update Certifi 2018.01.18 (e225253) to 2018.08.24 (8be9f89) * Update Certifi 2018.01.18 (e225253) to 2018.08.24 (8be9f89)
* Update dateutil module 2.7.2 (ff03c0f) to 2.7.2 (49690ee)
[develop changelog] [develop changelog]

View file

@ -181,7 +181,7 @@ def _update_zoneinfo():
# remove the old zoneinfo file # remove the old zoneinfo file
if cur_zoneinfo is not None: if cur_zoneinfo is not None:
old_file = helpers.real_path( old_file = helpers.real_path(
ek.ek(join, sickbeard.ZONEINFO_DIR, cur_zoneinfo)) ek.ek(os.path.join, sickbeard.ZONEINFO_DIR, cur_zoneinfo))
if ek.ek(os.path.exists, old_file): if ek.ek(os.path.exists, old_file):
ek.ek(os.remove, old_file) ek.ek(os.remove, old_file)
# rename downloaded file # rename downloaded file
@ -190,6 +190,11 @@ def _update_zoneinfo():
if '_CLASS_ZONE_INSTANCE' in gettz.func_globals: if '_CLASS_ZONE_INSTANCE' in gettz.func_globals:
gettz.func_globals.__setitem__('_CLASS_ZONE_INSTANCE', list()) gettz.func_globals.__setitem__('_CLASS_ZONE_INSTANCE', list())
tz.gettz.cache_clear() tz.gettz.cache_clear()
from dateutil.zoneinfo import get_zonefile_instance
try:
delattr(get_zonefile_instance, '_cached_instance')
except AttributeError:
pass
sb_timezone = get_tz() sb_timezone = get_tz()
except: except:

View file

@ -0,0 +1,51 @@
import unittest
import test_lib as test
import os.path
import datetime
from lib.dateutil import tz
import sickbeard
from sickbeard import network_timezones, helpers
import sickbeard.encodingKludge as ek
class NetworkTimezoneTests(test.SickbeardTestDBCase):
@classmethod
def tearDownClass(cls):
super(NetworkTimezoneTests, cls).tearDownClass()
cls.remove_zoneinfo()
try:
os.rmdir(sickbeard.ZONEINFO_DIR)
except (StandardError, Exception):
pass
@classmethod
def setUpClass(cls):
super(NetworkTimezoneTests, cls).setUpClass()
cls.remove_zoneinfo()
@classmethod
def remove_zoneinfo(cls):
# delete all existing zoneinfo files
for (path, dirs, files) in ek.ek(os.walk, helpers.real_path(sickbeard.ZONEINFO_DIR)):
for filename in files:
if filename.endswith('.tar.gz'):
file_w_path = ek.ek(os.path.join, path, filename)
try:
ek.ek(os.remove, file_w_path)
except (StandardError, Exception):
pass
def test_timezone(self):
network_timezones.update_network_dict()
network_timezones.sb_timezone = tz.gettz('CET', zoneinfo_priority=True)
d = datetime.date(2018, 9, 2).toordinal()
t = 'Monday 9:00 PM'
network = 'NBC'
r = network_timezones.parse_date_time(d, t, network)
local_date = datetime.datetime(2018, 9, 3, 3, 0, 0).replace(tzinfo=tz.gettz('CET', zoneinfo_priority=True))
self.assertEqual(r, local_date)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(NetworkTimezoneTests)
unittest.TextTestRunner(verbosity=2).run(suite)

View file

@ -96,6 +96,7 @@ createTestLogFolder()
sickbeard.logger.sb_log_instance.init_logging(False) sickbeard.logger.sb_log_instance.init_logging(False)
sickbeard.CACHE_DIR = os.path.join(TESTDIR, 'cache') sickbeard.CACHE_DIR = os.path.join(TESTDIR, 'cache')
sickbeard.ZONEINFO_DIR = os.path.join(TESTDIR, 'zoneinfo')
createTestCacheFolder() createTestCacheFolder()
#================= #=================