diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2014-06-28 01:11:32 +0300 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2014-06-28 01:11:32 +0300 |
commit | e7e9f33082bbd571b287983564bbef1fdd079505 (patch) | |
tree | 0a488a77ea95a7c8a04a8e1272db86d1a33037ae | |
parent | e763f39eb01f27e22dd8588f75da9c2cbe916dab (diff) | |
download | apscheduler-e7e9f33082bbd571b287983564bbef1fdd079505.tar.gz |
Bail out if the name of the local timezone cannot be determined
-rw-r--r-- | apscheduler/util.py | 2 | ||||
-rw-r--r-- | tests/test_util.py | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/apscheduler/util.py b/apscheduler/util.py index 8504ac0..1544910 100644 --- a/apscheduler/util.py +++ b/apscheduler/util.py @@ -76,6 +76,8 @@ def astimezone(obj): if isinstance(obj, tzinfo): if not hasattr(obj, 'localize') or not hasattr(obj, 'normalize'): raise TypeError('Only timezones from the pytz library are supported') + if obj.zone == 'local': + raise ValueError('Unable to determine the name of the local timezone -- use an explicit timezone instead') return obj if obj is not None: raise TypeError('Expected tzinfo, got %s instead' % obj.__class__.__name__) diff --git a/tests/test_util.py b/tests/test_util.py index bf13476..d454f10 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -12,6 +12,11 @@ from apscheduler.util import ( datetime_repr, repr_escape) from tests.conftest import minpython, maxpython +try: + from unittest.mock import Mock +except ImportError: + from mock import Mock + class DummyClass(object): def meth(self): @@ -78,6 +83,11 @@ class TestAstimezone(object): exc = pytest.raises(TypeError, astimezone, tzinfo()) assert 'Only timezones from the pytz library are supported' in str(exc.value) + def test_bad_local_timezone(self): + zone = Mock(tzinfo, localize=None, normalize=None, zone='local') + exc = pytest.raises(ValueError, astimezone, zone) + assert 'Unable to determine the name of the local timezone' in str(exc.value) + def test_bad_value(self): exc = pytest.raises(TypeError, astimezone, 4) assert 'Expected tzinfo, got int instead' in str(exc.value) |