Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
tz_local = tzlocal.unix._tz_from_env(
':' + os.path.join(self.path, 'test_data', 'Harare'))
self.assertEqual(tz_local.zone, 'local')
# Make sure the local timezone is the same as the Harare one above.
# We test this with a past date, so that we don't run into future changes
# of the Harare timezone.
dt = datetime(2012, 1, 1, 5)
self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt))
# Non-zoneinfo timezones are not supported in the TZ environment.
self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env,
'GMT+03:00')
# Test the _try function
os.environ['TZ'] = 'Africa/Harare'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertEqual(tz_harare.zone, 'Africa/Harare')
# With a zone that doesn't exist
os.environ['TZ'] = 'Just Nonsense'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertIsNone(tz_harare)
self.assertEqual(tz_harare.zone, 'Africa/Harare')
tz_local = tzlocal.unix._tz_from_env(':' + os.path.join(self.path, 'test_data', 'Harare'))
self.assertEqual(tz_local.zone, 'local')
# Make sure the local timezone is the same as the Harare one above.
# We test this with a past date, so that we don't run into future changes
# of the Harare timezone.
dt = datetime(2012, 1, 1, 5)
self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt))
# Non-zoneinfo timezones are not supported in the TZ environment.
self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env, 'GMT+03:00')
# Test the _try function
os.environ['TZ'] = 'Africa/Harare'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertEqual(tz_harare.zone, 'Africa/Harare')
# With a zone that doesn't exist
os.environ['TZ'] = 'Just Nonsense'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertIsNone(tz_harare)
# Make sure the local timezone is the same as the Harare one above.
# We test this with a past date, so that we don't run into future changes
# of the Harare timezone.
dt = datetime(2012, 1, 1, 5)
self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt))
# Non-zoneinfo timezones are not supported in the TZ environment.
self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env, 'GMT+03:00')
# Test the _try function
os.environ['TZ'] = 'Africa/Harare'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertEqual(tz_harare.zone, 'Africa/Harare')
# With a zone that doesn't exist
os.environ['TZ'] = 'Just Nonsense'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertIsNone(tz_harare)
self.assertEqual(tz_harare.zone, 'Africa/Harare')
tz_local = tzlocal.unix._tz_from_env(':' + os.path.join(self.path, 'test_data', 'Harare'))
self.assertEqual(tz_local.zone, 'local')
# Make sure the local timezone is the same as the Harare one above.
# We test this with a past date, so that we don't run into future changes
# of the Harare timezone.
dt = datetime(2012, 1, 1, 5)
self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt))
# Non-zoneinfo timezones are not supported in the TZ environment.
self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env, 'GMT+03:00')
# Test the _try function
os.environ['TZ'] = 'Africa/Harare'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertEqual(tz_harare.zone, 'Africa/Harare')
# With a zone that doesn't exist
os.environ['TZ'] = 'Just Nonsense'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertIsNone(tz_harare)
# We test this with a past date, so that we don't run into future changes
# of the Harare timezone.
dt = datetime(2012, 1, 1, 5)
self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt))
# Non-zoneinfo timezones are not supported in the TZ environment.
self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env,
'GMT+03:00')
# Test the _try function
os.environ['TZ'] = 'Africa/Harare'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertEqual(tz_harare.zone, 'Africa/Harare')
# With a zone that doesn't exist
os.environ['TZ'] = 'Just Nonsense'
tz_harare = tzlocal.unix._try_tz_from_env()
self.assertIsNone(tz_harare)