Skip weekday type tests if babel not installed
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
|
babel = None
|
||||||
|
try:
|
||||||
|
import babel
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
import six
|
import six
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
|
from sqlalchemy_utils.exceptions import ImproperlyConfigured
|
||||||
from sqlalchemy_utils.primitives import WeekDay, WeekDays
|
from sqlalchemy_utils.primitives import WeekDay, WeekDays
|
||||||
from .scalar_coercible import ScalarCoercible
|
from .scalar_coercible import ScalarCoercible
|
||||||
from .bit import BitType
|
from .bit import BitType
|
||||||
@@ -48,6 +54,14 @@ class WeekDaysType(types.TypeDecorator, ScalarCoercible):
|
|||||||
|
|
||||||
impl = BitType(WeekDay.NUM_WEEK_DAYS)
|
impl = BitType(WeekDay.NUM_WEEK_DAYS)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
if babel is None:
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"'babel' package is required to use 'WeekDaysType'"
|
||||||
|
)
|
||||||
|
|
||||||
|
super(WeekDaysType, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comparator_factory(self):
|
def comparator_factory(self):
|
||||||
return self.impl.comparator_factory
|
return self.impl.comparator_factory
|
||||||
|
@@ -1,16 +1,18 @@
|
|||||||
from babel import Locale
|
import pytest
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy_utils.types import WeekDaysType
|
from sqlalchemy_utils.types import WeekDaysType
|
||||||
|
from sqlalchemy_utils.types.weekdays import babel
|
||||||
from sqlalchemy_utils.primitives import WeekDays
|
from sqlalchemy_utils.primitives import WeekDays
|
||||||
from sqlalchemy_utils import i18n
|
from sqlalchemy_utils import i18n
|
||||||
|
|
||||||
from tests import TestCase
|
from tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif('babel is None')
|
||||||
class WeekDaysTypeTestCase(TestCase):
|
class WeekDaysTypeTestCase(TestCase):
|
||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
TestCase.setup_method(self, method)
|
TestCase.setup_method(self, method)
|
||||||
i18n.get_locale = lambda: Locale('en')
|
i18n.get_locale = lambda: babel.Locale('en')
|
||||||
|
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class Schedule(self.Base):
|
class Schedule(self.Base):
|
||||||
|
Reference in New Issue
Block a user