Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_only_localtime(self):
local_path = os.path.split(__file__)[0]
tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'localtime'))
self.assertEqual(tz.zone, 'local')
dt = datetime(2012, 1, 1, 5)
self.assertEqual(pytz.timezone('Africa/Harare').localize(dt), tz.localize(dt))
def test_timezone(self):
# Most versions of Ubuntu
local_path = os.path.split(__file__)[0]
tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'timezone'))
self.assertEqual(tz.zone, 'Africa/Harare')
def test_vardbzoneinfo_setting(self):
# A ZONE setting in /etc/conf.d/clock, f ex Gentoo
tz = tzlocal.unix._get_localzone(_root=os.path.join(self.path, 'test_data', 'vardbzoneinfo'))
self.assertEqual(tz.zone, 'Africa/Harare')
def test_zone_setting(self):
# A ZONE setting in /etc/sysconfig/clock, f ex CentOS
tz = tzlocal.unix._get_localzone(_root=os.path.join(self.path, 'test_data', 'zone_setting'))
self.assertEqual(tz.zone, 'Africa/Harare')
def test_fail(self):
out = StringIO()
stderr = sys.stderr
try:
sys.stderr = out
tz = tzlocal.unix._get_localzone(
_root=os.path.join(self.path, 'test_data'))
finally:
sys.stderr = stderr
self.assertEqual(tz, pytz.utc)
self.assertIn('Can not find any timezone configuration',
out.getvalue())
def test_fail(self):
with self.assertRaises(pytz.exceptions.UnknownTimeZoneError):
tz = tzlocal.unix._get_localzone(_root=os.path.join(self.path, 'test_data'))
def test_timezone_setting(self):
# A ZONE setting in /etc/conf.d/clock, f ex Gentoo
tz = tzlocal.unix._get_localzone(_root=os.path.join(self.path, 'test_data', 'timezone_setting'))
self.assertEqual(tz.zone, 'Africa/Harare')
def test_only_localtime(self):
tz = tzlocal.unix._get_localzone(_root=os.path.join(self.path, 'test_data', 'localtime'))
self.assertEqual(tz.zone, 'local')
dt = datetime(2012, 1, 1, 5)
self.assertEqual(pytz.timezone('Africa/Harare').localize(dt), tz.localize(dt))
def test_only_localtime(self):
tz = tzlocal.unix._get_localzone(
_root=os.path.join(self.path, 'test_data', 'localtime'))
self.assertEqual(tz.zone, 'local')
dt = datetime(2012, 1, 1, 5)
self.assertEqual(
pytz.timezone('Africa/Harare').localize(dt), tz.localize(dt))