mirror of
https://github.com/beetbox/beets.git
synced 2025-12-28 19:42:42 +01:00
Rename exception: InvalidQuery → InvalidQueryError
Follow PEP8.
This commit is contained in:
parent
3804eb5b52
commit
f4b4847919
3 changed files with 9 additions and 8 deletions
|
|
@ -20,12 +20,12 @@ from beets import util
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class InvalidQuery(ValueError):
|
||||
class InvalidQueryError(ValueError):
|
||||
def __init__(self, what, expected, detail=None):
|
||||
message = "{0!r} is not {1}".format(what, expected)
|
||||
if detail:
|
||||
message = "{0}: {1}".format(message, detail)
|
||||
super(InvalidQuery, self).__init__(message)
|
||||
super(InvalidQueryError, self).__init__(message)
|
||||
|
||||
|
||||
class Query(object):
|
||||
|
|
@ -154,7 +154,8 @@ class RegexpQuery(StringFieldQuery):
|
|||
self.pattern = re.compile(self.pattern)
|
||||
except re.error as exc:
|
||||
# Invalid regular expression.
|
||||
raise InvalidQuery(pattern, "a regular expression", format(exc))
|
||||
raise InvalidQueryError(pattern, "a regular expression",
|
||||
format(exc))
|
||||
|
||||
@classmethod
|
||||
def string_match(cls, pattern, value):
|
||||
|
|
@ -214,7 +215,7 @@ class NumericQuery(FieldQuery):
|
|||
try:
|
||||
return float(s)
|
||||
except ValueError:
|
||||
raise InvalidQuery(s, "an int or a float")
|
||||
raise InvalidQueryError(s, "an int or a float")
|
||||
|
||||
def __init__(self, field, pattern, fast=True):
|
||||
super(NumericQuery, self).__init__(field, pattern, fast)
|
||||
|
|
|
|||
|
|
@ -961,7 +961,7 @@ def main(args=None):
|
|||
except confit.ConfigError as exc:
|
||||
log.error(u'configuration error: {0}', exc)
|
||||
sys.exit(1)
|
||||
except db_query.InvalidQuery as exc:
|
||||
except db_query.InvalidQueryError as exc:
|
||||
log.error(u'invalid query: {0}', exc)
|
||||
sys.exit(1)
|
||||
except IOError as exc:
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import helper
|
|||
import beets.library
|
||||
from beets import dbcore
|
||||
from beets.dbcore import types
|
||||
from beets.dbcore.query import NoneQuery, InvalidQuery
|
||||
from beets.dbcore.query import NoneQuery, InvalidQueryError
|
||||
from beets.library import Library, Item
|
||||
|
||||
|
||||
|
|
@ -276,11 +276,11 @@ class GetTest(DummyDataTestCase):
|
|||
self.assertFalse(results)
|
||||
|
||||
def test_invalid_query(self):
|
||||
with self.assertRaises(InvalidQuery) as raised:
|
||||
with self.assertRaises(InvalidQueryError) as raised:
|
||||
dbcore.query.NumericQuery('year', '199a')
|
||||
self.assertIn('not an int', str(raised.exception))
|
||||
|
||||
with self.assertRaises(InvalidQuery) as raised:
|
||||
with self.assertRaises(InvalidQueryError) as raised:
|
||||
dbcore.query.RegexpQuery('year', '199(')
|
||||
self.assertIn('not a regular expression', str(raised.exception))
|
||||
self.assertIn('unbalanced parenthesis', str(raised.exception))
|
||||
|
|
|
|||
Loading…
Reference in a new issue