sqlalchemy_utils.primitives.WeekDays

Here are the examples of the python api sqlalchemy_utils.primitives.WeekDays taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

17 Examples 7

Example 1

Project: sqlalchemy-utils Source File: test_weekdays.py
    @pytest.mark.parametrize(
        'bit_string',
        [
            '000000',    # too short
            '00000000',  # too long
        ]
    )
    def test_constructor_with_bit_string_of_invalid_length(self, bit_string):
        with pytest.raises(ValueError):
            WeekDays(bit_string)

Example 2

Project: sqlalchemy-utils Source File: test_weekdays.py
    @pytest.mark.parametrize(
        'bit_string',
        [
            '0000000',
            '1000000',
            '0000001',
            '0101000',
            '1111111',
        ]
    )
    def test_as_bit_string(self, bit_string):
        days = WeekDays(bit_string)
        assert days.as_bit_string() == bit_string

Example 3

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_constructor_with_valid_bit_string(self):
        days = WeekDays('1000100')
        assert days._days == set([WeekDay(0), WeekDay(4)])

Example 4

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_constructor_with_bit_string_containing_invalid_characters(self):
        with pytest.raises(ValueError):
            WeekDays('foobarz')

Example 5

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_constructor_with_another_week_days_object(self):
        days = WeekDays('0000000')
        another_days = WeekDays(days)
        assert days._days == another_days._days

Example 6

Project: sqlalchemy-utils Source File: test_weekdays.py
Function: test_representation
    def test_representation(self):
        days = WeekDays('0000000')
        assert repr(days) == "WeekDays('0000000')"

Example 7

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_equality_with_equal_week_days_object(self):
        days = WeekDays('0001000')
        days2 = WeekDays('0001000')
        assert days == days2

Example 8

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_equality_with_unequal_week_days_object(self):
        days = WeekDays('0001000')
        days2 = WeekDays('1000000')
        assert days != days2

Example 9

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_equality_with_equal_bit_string(self):
        days = WeekDays('0001000')
        assert days == '0001000'

Example 10

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_equality_with_unequal_bit_string(self):
        days = WeekDays('0001000')
        assert days != '0101000'

Example 11

Project: sqlalchemy-utils Source File: test_weekdays.py
Function: test_equality_with_unsupported_comparison
    def test_equality_with_unsupported_comparison(self):
        days = WeekDays('0001000')
        assert days != 0

Example 12

Project: sqlalchemy-utils Source File: test_weekdays.py
    def test_iterator_starts_from_locales_first_week_day(self):
        i18n.get_locale = lambda: flexmock(first_week_day=1)
        days = WeekDays('1111111')
        indices = list(day.index for day in days)
        assert indices == [1, 2, 3, 4, 5, 6, 0]

Example 13

Project: sqlalchemy-utils Source File: test_weekdays.py
Function: test_unicode
    def test_unicode(self):
        i18n.get_locale = lambda: i18n.babel.Locale('fi')
        days = WeekDays('1000100')
        assert six.text_type(days) == u'maanantaina, perjantaina'

Example 14

Project: sqlalchemy-utils Source File: test_weekdays.py
Function: test_str
    def test_str(self):
        i18n.get_locale = lambda: i18n.babel.Locale('fi')
        days = WeekDays('1000100')
        assert str(days) == 'maanantaina, perjantaina'

Example 15

Project: wtforms-alchemy Source File: fields.py
Function: get_choices
    def _get_choices(self):
        days = WeekDays('1111111')
        for day in days:
            yield day.index, day.get_name(context='stand-alone')

Example 16

Project: wtforms-alchemy Source File: fields.py
Function: process_data
    def process_data(self, value):
        self.data = WeekDays(value) if value else None

Example 17

Project: wtforms-alchemy Source File: fields.py
Function: process_form_data
    def process_formdata(self, valuelist):
        self.data = WeekDays(self.coerce(x) for x in valuelist)