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

Rename error #2523

Merged
merged 4 commits into from
May 1, 2017
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, query, explanation):
super(InvalidQueryError, self).__init__(message)


class InvalidQueryArgumentTypeError(ParsingError):
class InvalidQueryArgumentValueError(ParsingError):
"""Represent a query argument that could not be converted as expected.
It exists to be caught in upper stack levels so a meaningful (i.e. with the
Expand All @@ -57,7 +57,7 @@ def __init__(self, what, expected, detail=None):
message = u"'{0}' is not {1}".format(what, expected)
if detail:
message = u"{0}: {1}".format(message, detail)
super(InvalidQueryArgumentTypeError, self).__init__(message)
super(InvalidQueryArgumentValueError, self).__init__(message)


class Query(object):
Expand Down Expand Up @@ -211,9 +211,9 @@ def __init__(self, field, pattern, fast=True):
self.pattern = re.compile(self.pattern)
except re.error as exc:
# Invalid regular expression.
raise InvalidQueryArgumentTypeError(pattern,
u"a regular expression",
format(exc))
raise InvalidQueryArgumentValueError(pattern,
u"a regular expression",
format(exc))

@staticmethod
def _normalize(s):
Expand Down Expand Up @@ -285,7 +285,7 @@ def _convert(self, s):
try:
return float(s)
except ValueError:
raise InvalidQueryArgumentTypeError(s, u"an int or a float")
raise InvalidQueryArgumentValueError(s, u"an int or a float")

def __init__(self, field, pattern, fast=True):
super(NumericQuery, self).__init__(field, pattern, fast)
Expand Down Expand Up @@ -548,7 +548,7 @@ def __init__(self, date, precision):
@classmethod
def parse(cls, string):
"""Parse a date and return a `Period` object, or `None` if the
string is empty, or raise an InvalidQueryArgumentTypeError if
string is empty, or raise an InvalidQueryArgumentValueError if
the string could not be parsed to a date.
"""
if not string:
Expand All @@ -562,8 +562,8 @@ def parse(cls, string):
# Parsing failed.
pass
if date is None:
raise InvalidQueryArgumentTypeError(string,
'a valid datetime string')
raise InvalidQueryArgumentValueError(string,
'a valid datetime string')
precision = cls.precisions[ordinal]
return cls(date, precision)

Expand Down Expand Up @@ -685,7 +685,7 @@ def _convert(self, s):
try:
return float(s)
except ValueError:
raise InvalidQueryArgumentTypeError(
raise InvalidQueryArgumentValueError(
s,
u"a M:SS string or a float")

Expand Down
2 changes: 1 addition & 1 deletion beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ def _fetch(self, model_cls, query, sort=None):
query, parsed_sort = parse_query_string(query, model_cls)
elif isinstance(query, (list, tuple)):
query, parsed_sort = parse_query_parts(query, model_cls)
except dbcore.query.InvalidQueryArgumentTypeError as exc:
except dbcore.query.InvalidQueryArgumentValueError as exc:
raise dbcore.InvalidQueryError(query, exc)

# Any non-null sort specified by the parsed query overrides the
Expand Down
8 changes: 4 additions & 4 deletions test/test_datequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import unittest
import time
from beets.dbcore.query import _parse_periods, DateInterval, DateQuery,\
InvalidQueryArgumentTypeError
InvalidQueryArgumentValueError


def _date(string):
Expand Down Expand Up @@ -118,11 +118,11 @@ def test_single_day_nonmatch_fast(self):

class DateQueryConstructTest(unittest.TestCase):
def test_long_numbers(self):
with self.assertRaises(InvalidQueryArgumentTypeError):
with self.assertRaises(InvalidQueryArgumentValueError):
DateQuery('added', '1409830085..1412422089')

def test_too_many_components(self):
with self.assertRaises(InvalidQueryArgumentTypeError):
with self.assertRaises(InvalidQueryArgumentValueError):
DateQuery('added', '12-34-56-78')

def test_invalid_date_query(self):
Expand All @@ -137,7 +137,7 @@ def test_invalid_date_query(self):
'..2aa'
]
for q in q_list:
with self.assertRaises(InvalidQueryArgumentTypeError):
with self.assertRaises(InvalidQueryArgumentValueError):
DateQuery('added', q)


Expand Down
6 changes: 3 additions & 3 deletions test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from beets import dbcore
from beets.dbcore import types
from beets.dbcore.query import (NoneQuery, ParsingError,
InvalidQueryArgumentTypeError)
InvalidQueryArgumentValueError)
from beets.library import Library, Item
from beets import util
import platform
Expand Down Expand Up @@ -301,11 +301,11 @@ def test_numeric_search_negative(self):
self.assertFalse(results)

def test_invalid_query(self):
with self.assertRaises(InvalidQueryArgumentTypeError) as raised:
with self.assertRaises(InvalidQueryArgumentValueError) as raised:
dbcore.query.NumericQuery('year', u'199a')
self.assertIn(u'not an int', six.text_type(raised.exception))

with self.assertRaises(InvalidQueryArgumentTypeError) as raised:
with self.assertRaises(InvalidQueryArgumentValueError) as raised:
dbcore.query.RegexpQuery('year', u'199(')
exception_text = six.text_type(raised.exception)
self.assertIn(u'not a regular expression', exception_text)
Expand Down