Skip to content

Commit

Permalink
Merge pull request #171 from r1chardj0n3s/cov
Browse files Browse the repository at this point in the history
remove coverage misses from tests/
  • Loading branch information
wimglenn authored Nov 25, 2023
2 parents 5687cf0 + e2ff32a commit 8f891d5
Showing 1 changed file with 9 additions and 29 deletions.
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

0 comments on commit 8f891d5

Please sign in to comment.