Skip to content

Commit

Permalink
fixup! Add tests for gettz zone supports startswith
Browse files Browse the repository at this point in the history
  • Loading branch information
pganssle committed Nov 2, 2019
1 parent 3cba501 commit cf847fd
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions dateutil/test/test_tz.py
Expand Up @@ -1101,36 +1101,35 @@ def test_gettz_badzone_unicode():
tzi = tz.gettz('🐼')
assert tzi is None


@pytest.mark.gettz
@pytest.mark.parametrize(
'badzone', [
"badzone,exc_reason",
[
pytest.param(
b'America/New_York',
id='bytes on python 3',
b"America/New_York",
".*should be str, not bytes.*",
id="bytes on Python 3",
marks=[
pytest.mark.xfail(
raises=TypeError,
reason='bytes.startswith first arg must be bytes, not str',
),
pytest.mark.skipif(
sys.version_info < (3, 0),
reason='bytes are str in Python 2',
PY2, reason="bytes arguments accepted in Python 2"
)
]
],
),
pytest.param(
object(),
id='no startswith() method',
marks=pytest.mark.xfail(
raises=AttributeError,
reason='object must support startswith with str prefix',
),
)
]
None,
id="no startswith()",
marks=[
pytest.mark.xfail(reason="AttributeError instead of TypeError",
raises=AttributeError),
],
),
],
)
def test_gettz_zone_startswith(badzone):
tz.gettz(badzone)
def test_gettz_zone_wrong_type(badzone, exc_reason):
with pytest.raises(TypeError, match=exc_reason):
tz.gettz(badzone)


@pytest.mark.gettz
Expand Down

0 comments on commit cf847fd

Please sign in to comment.