Skip to content

Commit

Permalink
Fix loading of some timezones with empty posix spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Mar 17, 2019
1 parent 23f290f commit 94d28b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pendulum/tz/zoneinfo/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections import namedtuple
from struct import unpack
from typing import List, Dict
from typing import Dict, List, Optional

from pytzdata.exceptions import TimezoneNotFound

Expand Down Expand Up @@ -200,12 +200,15 @@ def _parse_abbrs(

return abbrs

def _parse_posix_tz(self, fd): # type: (...) -> PosixTimezone
def _parse_posix_tz(self, fd): # type: (...) -> Optional[PosixTimezone]
s = fd.read().decode("utf-8")

if not s.startswith("\n") or not s.endswith("\n"):
raise InvalidZoneinfoFile('Invalid posix rule in file "{}"'.format(fd.name))

s = s.strip()

if not s:
return

return posix_spec(s)
9 changes: 4 additions & 5 deletions tests/tz/test_timezones.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import pytest

import pendulum

Expand All @@ -9,8 +10,6 @@ def test_timezones():
assert "America/Argentina/Buenos_Aires" in zones


def test_timezones_are_loadable():
zones = pendulum.timezones

for zone in zones:
pendulum.timezone(zone)
@pytest.mark.parametrize("zone", [zone for zone in pendulum.timezones])
def test_timezones_are_loadable(zone):
pendulum.timezone(zone)

0 comments on commit 94d28b0

Please sign in to comment.