Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove coverage misses from tests/ #171

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 9 additions & 29 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
import re
import sys
from datetime import date
from datetime import datetime
Expand Down Expand Up @@ -236,17 +235,15 @@ def test_numbers():
def y(fmt, s, e, str_equals=False):
p = parse.compile(fmt)
r = p.parse(s)
if r is None:
pytest.fail("%r (%r) did not match %r" % (fmt, p._expression, s))
assert r is not None
r = r.fixed[0]
if str_equals:
assert str(r) == str(e)
else:
assert r == e

def n(fmt, s, e):
if parse.parse(fmt, s) is not None:
pytest.fail("%r matched %r" % (fmt, s))
assert parse.parse(fmt, s) is None

y("a {:d} b", "a 0 b", 0)
y("a {:d} b", "a 12 b", 12)
Expand Down Expand Up @@ -435,25 +432,10 @@ def test_datetimes():
def y(fmt, s, e, tz=None):
p = parse.compile(fmt)
r = p.parse(s)
if r is None:
pytest.fail("%r (%r) did not match %r" % (fmt, p._expression, s))
assert r is not None
r = r.fixed[0]
try:
assert r == e, "%r found %r in %r, not %r" % (fmt, r, s, e)
except ValueError:
pytest.fail("%r found %r in %r, not %r" % (fmt, r, s, e))

if tz is not None:
assert r.tzinfo == tz, "%r found TZ %r in %r, not %r" % (
fmt,
r.tzinfo,
s,
e,
)

def n(fmt, s, e):
if parse.parse(fmt, s) is not None:
pytest.fail("%r matched %r" % (fmt, s))
assert r == e
assert tz is None or r.tzinfo == tz

utc = parse.FixedTzOffset(0, "UTC")
assert repr(utc) == "<FixedTzOffset UTC 0:00:00>"
Expand Down Expand Up @@ -731,15 +713,13 @@ def test_mixed_type_variant():
assert r.fixed[21] == "spam"


@pytest.mark.skipif(sys.version_info >= (3, 5), reason="Python 3.5 removed the limit of 100 named groups in a regular expression")
def test_too_many_fields():
# Python 3.5 removed the limit of 100 named groups in a regular expression,
# so only test for the exception if the limit exists.
try:
re.compile("".join("(?P<n{n}>{n}-)".format(n=i) for i in range(101)))
except AssertionError:
p = parse.compile("{:ti}" * 15)
with pytest.raises(parse.TooManyFields):
p.parse("")
p = parse.compile("{:ti}" * 15)
with pytest.raises(parse.TooManyFields):
p.parse("")


def test_letters():
Expand Down