Skip to content

Commit

Permalink
Convert all parser raises tests to use ParserError
Browse files Browse the repository at this point in the history
ParserError is a subclass of ValueError, so this just makes the tests
stricter, and this can be considered a backwards-compatible change.
  • Loading branch information
pganssle committed Apr 23, 2019
1 parent 31e8c66 commit f764c8a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions dateutil/test/test_parser.py
Expand Up @@ -292,7 +292,7 @@ def test_strftime_formats_2003Sep25(self, fmt, dstr):

class TestInputTypes(object):
def test_empty_string_invalid(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse('')

def test_none_invalid(self):
Expand Down Expand Up @@ -479,17 +479,17 @@ def testISOStrippedFormatStrip2(self):
tzinfo=tzoffset(None, 10800)))

def testAMPMNoHour(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("AM")

with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("Jan 20, 2015 PM")

def testAMPMRange(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("13:44 AM")

with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("January 25, 1921 23:13 PM")

def testPertain(self):
Expand Down Expand Up @@ -565,15 +565,15 @@ def testUnspecifiedDayFallbackFebLeapYear(self):
datetime(2008, 2, 29))

def testErrorType01(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse('shouldfail')

def testCorrectErrorOnFuzzyWithTokens(self):
assertRaisesRegex(self, ValueError, 'Unknown string format',
assertRaisesRegex(self, ParserError, 'Unknown string format',
parse, '04/04/32/423', fuzzy_with_tokens=True)
assertRaisesRegex(self, ValueError, 'Unknown string format',
assertRaisesRegex(self, ParserError, 'Unknown string format',
parse, '04/04/04 +32423', fuzzy_with_tokens=True)
assertRaisesRegex(self, ValueError, 'Unknown string format',
assertRaisesRegex(self, ParserError, 'Unknown string format',
parse, '04/04/0d4', fuzzy_with_tokens=True)

def testIncreasingCTime(self):
Expand Down Expand Up @@ -714,7 +714,7 @@ def test_hmBY(self):
def test_validate_hour(self):
# See GH353
invalid = "201A-01-01T23:58:39.239769+03:00"
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(invalid)

def test_era_trailing_year(self):
Expand All @@ -736,31 +736,31 @@ def test_includes_timestr(self):
class TestOutOfBounds(object):

def test_no_year_zero(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("0000 Jun 20")

def test_out_of_bound_day(self):
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse("Feb 30, 2007")

def test_day_sanity(self, fuzzy):
dstr = "2014-15-25"
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(dstr, fuzzy=fuzzy)

def test_minute_sanity(self, fuzzy):
dstr = "2014-02-28 22:64"
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(dstr, fuzzy=fuzzy)

def test_hour_sanity(self, fuzzy):
dstr = "2014-02-28 25:16 PM"
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(dstr, fuzzy=fuzzy)

def test_second_sanity(self, fuzzy):
dstr = "2014-02-28 22:14:64"
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(dstr, fuzzy=fuzzy)


Expand Down Expand Up @@ -813,7 +813,7 @@ def test_four_letter_day(self):
@pytest.mark.xfail
def test_non_date_number(self):
dstr = '1,700'
with pytest.raises(ValueError):
with pytest.raises(ParserError):
parse(dstr)

@pytest.mark.xfail
Expand Down Expand Up @@ -935,7 +935,7 @@ def test_rounding_floatlike_strings(dtstr, dt):

@pytest.mark.parametrize('value', ['1: test', 'Nan'])
def test_decimal_error(value):
# GH 632, GH 662 - decimal.Decimal raises some non-ValueError exception when
# constructed with an invalid value
with pytest.raises(ValueError):
# GH 632, GH 662 - decimal.Decimal raises some non-ParserError exception
# when constructed with an invalid value
with pytest.raises(ParserError):
parse(value)

0 comments on commit f764c8a

Please sign in to comment.