~homeworkprod/byceps

1181a35dd06d48c779208a6d2a4b3672dd38d812 — Jochen Kupperschmidt 5 years ago 9f63b62
Ported tests from nose2 to pytest
M .gitignore => .gitignore +2 -0
@@ 1,6 1,8 @@
# Python 3 bytecode
__pycache__

.eggs

# virtual environment
venv


M README.rst => README.rst +2 -2
@@ 39,7 39,7 @@ See ``docs/installation.rst``.
Testing
=======

In the activated virtual environment, install tox_ and nose2_:
In the activated virtual environment, install tox_ and pytest_:

.. code:: sh



@@ 56,7 56,7 @@ for the Python versions specified in `tox.ini`.


.. _tox: http://tox.testrun.org/
.. _nose2: https://github.com/nose-devs/nose2
.. _pytest: http://pytest.org/


Serving

M requirements-test.txt => requirements-test.txt +1 -1
@@ 1,3 1,3 @@
freezegun >= 0.3.8
nose2 >= 0.6.5
pytest >= 3.3
tox >= 2.3.2

A setup.cfg => setup.cfg +5 -0
@@ 0,0 1,5 @@
[aliases]
test = pytest

[tool:pytest]
testpaths = tests

M setup.py => setup.py +1 -1
@@ 41,6 41,6 @@ setup(
    ],
    packages=['byceps'],
    install_requires=requirements,
    setup_requires=['pytest-runner'],
    tests_require=requirements_test,
    test_suite='nose2.collector.collector',
)

M tests/blueprints/authorization/test_registry.py => tests/blueprints/authorization/test_registry.py +5 -5
@@ 5,7 5,7 @@

from unittest.mock import patch

from nose2.tools import params
import pytest

with patch('flask.current_app'):
    from byceps.blueprints.authorization.registry import PermissionRegistry


@@ 15,23 15,23 @@ from byceps.util.authorization import create_permission_enum
ItemPermission = create_permission_enum('item', ['view', 'create', 'update'])


@params(
@pytest.mark.parametrize('permission_id, expected', [
    ('item.create'   , ItemPermission.create),  # enum member exists
    ('item.delete'   , None                 ),  # enum exists, but member does not
    ('article.create', None                 ),  # enum does not exist
)
])
def test_get_enum_member(permission_id, expected):
    registry = create_registry_with_registered_enum()

    assert registry.get_enum_member(permission_id) == expected


@params(
@pytest.mark.parametrize('permission_ids, expected', [
    ({'item.create', 'item.create'   }, {ItemPermission.create                       }),  # duplicates are ignored
    ({'item.create', 'item.update'   }, {ItemPermission.create, ItemPermission.update}),  # multiple different enums are returned
    ({'item.create', 'article.create'}, {ItemPermission.create                       }),  # unknown IDs are ignored
    ({'article.create'               }, frozenset()                                   ),  # unknown IDs are ignored
)
])
def test_get_enum_members(permission_ids, expected):
    registry = create_registry_with_registered_enum()


M tests/services/country/test_service.py => tests/services/country/test_service.py +3 -3
@@ 3,17 3,17 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.services.country import service as country_service

from tests.helpers import app_context


@params(
@pytest.mark.parametrize('name, alpha2, alpha3', [
    ('Deutschland', 'DE', 'DEU'),
    ('Österreich' , 'AT', 'AUT'),
)
])
def test_get_countries_contains_country(name, alpha2, alpha3):
    with app_context():
        countries = country_service.get_countries()

M tests/services/news/test_models.py => tests/services/news/test_models.py +9 -9
@@ 3,8 3,6 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params

from testfixtures.news import create_current_version_association, \
    create_item, create_item_version



@@ 21,15 19,17 @@ class ItemTestCase(AbstractAppTestCase):

        self.create_brand_and_party()

    @params(
        ('without-image', None          , None                                        ),
        ('with-image'   , 'breaking.png', 'http://example.com/brand/news/breaking.png'),
    )
    def test_image_url(self, slug, image_url_path, expected):
        item = self.create_item_with_version(slug, image_url_path)
    def test_image_url_with_image(self):
        item = self.create_item_with_version('with-image', 'breaking.png')

        with current_party_set(self.app, self.party), self.app.app_context():
            assert item.image_url == 'http://example.com/brand/news/breaking.png'

    def test_image_url_without_image(self):
        item = self.create_item_with_version('without-image', None)

        with current_party_set(self.app, self.party), self.app.app_context():
            self.assertEqual(item.image_url, expected)
            assert item.image_url is None

    # -------------------------------------------------------------------- #
    # helpers

M tests/services/shop/article/models/test_article_availability.py => tests/services/shop/article/models/test_article_availability.py +9 -9
@@ 6,12 6,12 @@
from datetime import datetime

from freezegun import freeze_time
from nose2.tools import params
import pytest

from testfixtures.shop_article import create_article


@params(
@pytest.mark.parametrize('now, expected', [
    (datetime(2014,  4,  8, 12,  0,  0), False),
    (datetime(2014,  9, 15, 17, 59, 59), False),
    (datetime(2014,  9, 15, 18,  0,  0), True ),


@@ 19,7 19,7 @@ from testfixtures.shop_article import create_article
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), False),
    (datetime(2014, 11,  4, 12,  0,  0), False),
)
])
def test_is_available_with_start_and_end(now, expected):
    article = create_article(
        available_from=datetime(2014, 9, 15, 18, 0, 0),


@@ 29,7 29,7 @@ def test_is_available_with_start_and_end(now, expected):
        assert article.is_available == expected


@params(
@pytest.mark.parametrize('now, expected', [
    (datetime(2014,  4,  8, 12,  0,  0), False),
    (datetime(2014,  9, 15, 17, 59, 59), False),
    (datetime(2014,  9, 15, 18,  0,  0), True ),


@@ 37,7 37,7 @@ def test_is_available_with_start_and_end(now, expected):
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), True ),
    (datetime(2014, 11,  4, 12,  0,  0), True ),
)
])
def test_is_available_with_start_and_without_end(now, expected):
    article = create_article(
        available_from=datetime(2014, 9, 15, 18, 0, 0),


@@ 47,7 47,7 @@ def test_is_available_with_start_and_without_end(now, expected):
        assert article.is_available == expected


@params(
@pytest.mark.parametrize('now, expected', [
    (datetime(2014,  4,  8, 12,  0,  0), True ),
    (datetime(2014,  9, 15, 17, 59, 59), True ),
    (datetime(2014,  9, 15, 18,  0,  0), True ),


@@ 55,7 55,7 @@ def test_is_available_with_start_and_without_end(now, expected):
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), False),
    (datetime(2014, 11,  4, 12,  0,  0), False),
)
])
def test_is_available_without_start_and_with_end(now, expected):
    article = create_article(
        available_from=None,


@@ 65,7 65,7 @@ def test_is_available_without_start_and_with_end(now, expected):
        assert article.is_available == expected


@params(
@pytest.mark.parametrize('now, expected', [
    (datetime(2014,  4,  8, 12,  0,  0), True ),
    (datetime(2014,  9, 15, 17, 59, 59), True ),
    (datetime(2014,  9, 15, 18,  0,  0), True ),


@@ 73,7 73,7 @@ def test_is_available_without_start_and_with_end(now, expected):
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), True ),
    (datetime(2014, 11,  4, 12,  0,  0), True ),
)
])
def test_is_available_without_start_and_without_end(now, expected):
    article = create_article(
        available_from=None,

M tests/services/shop/cart/models/test_cart_item_creation.py => tests/services/shop/cart/models/test_cart_item_creation.py +3 -3
@@ 3,7 3,7 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools.such import helper
from pytest import raises

from byceps.services.shop.cart.models import CartItem



@@ 19,12 19,12 @@ def test_init_with_positive_quantity():


def test_init_with_zero_quantity():
    with helper.assertRaises(ValueError):
    with raises(ValueError):
        create_item(0)


def test_init_with_negative_quantity():
    with helper.assertRaises(ValueError):
    with raises(ValueError):
        create_item(-1)



M tests/services/text_markup/test_service.py => tests/services/text_markup/test_service.py +3 -3
@@ 3,7 3,7 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.services.text_markup.service import render_html



@@ 50,7 50,7 @@ def test_quote_with_author():
    assert render_html(text) == expected


@params(
@pytest.mark.parametrize('text, expected', [
    (
        '[quote author="foo]bar"]blah[/quote]',
        '<p class="quote-intro"><cite>foo]bar</cite> schrieb:</p>\n<blockquote>blah</blockquote>',


@@ 79,6 79,6 @@ def test_quote_with_author():
        '[quote author="<AngleBracketeer>"]careful.[/quote]',
        '<p class="quote-intro"><cite>&lt;AngleBracketeer&gt;</cite> schrieb:</p>\n<blockquote>careful.</blockquote>',
    ),
)
])
def test_quote_with_author_whose_name_contains_square_brackets(text, expected):
    assert render_html(text) == expected

M tests/services/ticketing/test_models.py => tests/services/ticketing/test_models.py +9 -9
@@ 5,7 5,7 @@

from uuid import UUID

from nose2.tools import params
import pytest

from byceps.services.ticketing.models.ticket import Ticket



@@ 20,17 20,17 @@ user2 = create_user('User2')
user3 = create_user('User3')


@params(
@pytest.mark.parametrize('bundle_id, expected', [
    (ANY_BUNDLE_ID, True ),
    (None,          False),
)
])
def test_belongs_to_bundle(bundle_id, expected):
    ticket = create_ticket(user1.id, bundle_id=bundle_id)

    assert ticket.belongs_to_bundle == expected


@params(
@pytest.mark.parametrize('owned_by_id, seat_managed_by_id, user_managed_by_id, user_id, expected', [
    (user1.id, None    , None    , user1.id, True ),
    (user1.id, user1.id, None    , user1.id, True ),
    (user1.id, None    , user1.id, user1.id, True ),


@@ 44,7 44,7 @@ def test_belongs_to_bundle(bundle_id, expected):
    (user2.id, user1.id, None    , user1.id, True ),
    (user2.id, None    , user1.id, user1.id, True ),
    (user2.id, user1.id, user1.id, user1.id, True ),
)
])
def test_is_managed_by(owned_by_id, seat_managed_by_id, user_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           seat_managed_by_id=seat_managed_by_id,


@@ 53,7 53,7 @@ def test_is_managed_by(owned_by_id, seat_managed_by_id, user_managed_by_id, user
    assert ticket.is_managed_by(user_id) == expected


@params(
@pytest.mark.parametrize('owned_by_id, seat_managed_by_id, user_id, expected', [
    (user1.id, None    , user1.id, True ),
    (user1.id, user1.id, user1.id, True ),



@@ 62,7 62,7 @@ def test_is_managed_by(owned_by_id, seat_managed_by_id, user_managed_by_id, user

    (user2.id, None    , user1.id, False),
    (user2.id, user1.id, user1.id, True ),
)
])
def test_is_seat_managed_by(owned_by_id, seat_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           seat_managed_by_id=seat_managed_by_id)


@@ 70,7 70,7 @@ def test_is_seat_managed_by(owned_by_id, seat_managed_by_id, user_id, expected):
    assert ticket.is_seat_managed_by(user_id) == expected


@params(
@pytest.mark.parametrize('owned_by_id, user_managed_by_id, user_id, expected', [
    (user1.id, None    , user1.id, True ),
    (user1.id, user1.id, user1.id, True ),



@@ 79,7 79,7 @@ def test_is_seat_managed_by(owned_by_id, seat_managed_by_id, user_id, expected):

    (user2.id, None    , user1.id, False),
    (user2.id, user1.id, user1.id, True ),
)
])
def test_is_user_managed_by(owned_by_id, user_managed_by_id, user_id, expected):
    ticket = create_ticket(owned_by_id,
                           user_managed_by_id=user_managed_by_id)

M tests/services/ticketing/test_service_assignment.py => tests/services/ticketing/test_service_assignment.py +5 -3
@@ 3,6 3,8 @@
:License: Modified BSD, see LICENSE for details.
"""

from pytest import raises

from byceps.services.seating import area_service, seat_service
from byceps.services.ticketing import category_service, event_service, \
    ticket_bundle_service, ticket_service


@@ 194,7 196,7 @@ class TicketAssignmentServiceTestCase(AbstractAppTestCase):
    def test_occupy_seat_with_invalid_id(self):
        invalid_seat_id = 'ffffffff-ffff-ffff-ffff-ffffffffffff'

        with self.assertRaises(ValueError):
        with raises(ValueError):
            ticket_service.occupy_seat(self.ticket.id, invalid_seat_id,
                                       self.owner.id)



@@ 209,7 211,7 @@ class TicketAssignmentServiceTestCase(AbstractAppTestCase):
        area = self.create_area('main', 'Main Hall')
        seat = seat_service.create_seat(area, 0, 0, self.category_id)

        with self.assertRaises(SeatChangeDeniedForBundledTicket):
        with raises(SeatChangeDeniedForBundledTicket):
            ticket_service.occupy_seat(bundled_ticket.id, seat.id,
                                       self.owner.id)



@@ 221,7 223,7 @@ class TicketAssignmentServiceTestCase(AbstractAppTestCase):

        assert self.ticket.category_id != other_category_id

        with self.assertRaises(TicketCategoryMismatch):
        with raises(TicketCategoryMismatch):
            ticket_service.occupy_seat(self.ticket.id, seat.id, self.owner.id)

    # -------------------------------------------------------------------- #

M tests/services/ticketing/test_user_check_in.py => tests/services/ticketing/test_user_check_in.py +4 -2
@@ 3,6 3,8 @@
:License: Modified BSD, see LICENSE for details.
"""

from pytest import raises

from byceps.services.ticketing import category_service, event_service, \
    ticket_service
from byceps.services.ticketing.ticket_service import TicketIsRevoked, \


@@ 62,7 64,7 @@ class UserCheckInTest(AbstractAppTestCase):
        ticket.used_by_id = self.user_id
        self.db.session.commit()

        with self.assertRaises(TicketIsRevoked):
        with raises(TicketIsRevoked):
            ticket_service.check_in_user(ticket.id, self.orga_id)

    def test_check_in_user_with_ticket_user_already_checked_in(self):


@@ 72,7 74,7 @@ class UserCheckInTest(AbstractAppTestCase):
        ticket.user_checked_in = True
        self.db.session.commit()

        with self.assertRaises(UserAlreadyCheckIn):
        with raises(UserAlreadyCheckIn):
            ticket_service.check_in_user(ticket.id, self.orga_id)

    # -------------------------------------------------------------------- #

M tests/services/user/test_models_age.py => tests/services/user/test_models_age.py +3 -3
@@ 6,19 6,19 @@
from datetime import date

from freezegun import freeze_time
from nose2.tools import params
import pytest

from testfixtures.user import create_user_with_detail


@params(
@pytest.mark.parametrize('today_text, expected', [
    ('2014-03-17', 19),
    ('2014-03-18', 20),
    ('2014-03-19', 20),
    ('2015-03-17', 20),
    ('2015-03-18', 21),
    ('2015-03-19', 21),
)
])
def test_age(today_text, expected):
    user = create_user_with_detail(date_of_birth=date(1994, 3, 18))


M tests/services/user/test_models_birthday.py => tests/services/user/test_models_birthday.py +5 -5
@@ 6,17 6,17 @@
from datetime import date

from freezegun import freeze_time
from nose2.tools import params
import pytest

from testfixtures.user import create_user_with_detail


@params(
@pytest.mark.parametrize('today_text, expected', [
    ('2014-03-16',   2),
    ('2014-03-17',   1),
    ('2014-03-18',   0),
    ('2014-03-19', 364),
)
])
def test_days_until_next_birthday(today_text, expected):
    user = create_user_with_detail(date_of_birth=date(1994, 3, 18))



@@ 24,14 24,14 @@ def test_days_until_next_birthday(today_text, expected):
        assert user.detail.days_until_next_birthday == expected


@params(
@pytest.mark.parametrize('today_text, expected', [
    ('1994-03-17', False),
    ('1994-03-18', True ),
    ('1994-03-19', False),
    ('2014-03-17', False),
    ('2014-03-18', True ),
    ('2014-03-19', False),
)
])
def test_is_birthday_today(today_text, expected):
    user = create_user_with_detail(date_of_birth=date(1994, 3, 18))


M tests/services/user/test_models_full_name.py => tests/services/user/test_models_full_name.py +3 -3
@@ 3,17 3,17 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from testfixtures.user import create_user_with_detail


@params(
@pytest.mark.parametrize('first_names, last_name, expected', [
    (None,          None    , None                ),
    ('Giesbert Z.', None    , 'Giesbert Z.'       ),
    (None,          'Blümli', 'Blümli'            ),
    ('Giesbert Z.', 'Blümli', 'Giesbert Z. Blümli'),
)
])
def test_full_name(first_names, last_name, expected):
    user = create_user_with_detail(first_names=first_names,
                                   last_name=last_name)

M tests/services/user_avatar/test_models.py => tests/services/user_avatar/test_models.py +5 -5
@@ 5,7 5,7 @@

from datetime import datetime

from nose2.tools import params
import pytest

from byceps.util.image.models import ImageType



@@ 16,12 16,12 @@ from testfixtures.user_avatar import create_avatar
CREATED_AT = datetime(2014, 7, 29, 14, 43, 30, 196165)


@params(
@pytest.mark.parametrize('database_value, expected', [
    (None  , None          ),
    ('gif' , ImageType.gif ),
    ('jpeg', ImageType.jpeg),
    ('png' , ImageType.png ),
)
])
def test_hybrid_image_type_getter(database_value, expected):
    user = create_user()
    avatar = create_avatar(user.id)


@@ 31,12 31,12 @@ def test_hybrid_image_type_getter(database_value, expected):
    assert avatar.image_type == expected


@params(
@pytest.mark.parametrize('image_type, expected', [
    (None          , None  ),
    (ImageType.gif , 'gif' ),
    (ImageType.jpeg, 'jpeg'),
    (ImageType.png , 'png' ),
)
])
def test_hybrid_image_type_setter(image_type, expected):
    user = create_user()
    avatar = create_avatar(user.id)

M tests/services/user_avatar/test_models_image_path.py => tests/services/user_avatar/test_models_image_path.py +3 -3
@@ 6,7 6,7 @@
from pathlib import Path
from uuid import UUID

from nose2.tools import params
import pytest

from byceps.util.image.models import ImageType



@@ 16,7 16,7 @@ from testfixtures.user_avatar import create_avatar
from tests.helpers import app_context


@params(
@pytest.mark.parametrize('avatar_images_path, avatar_id, image_type, expected', [
    (
        Path('/var/data/avatars'),
        UUID('2e17cb15-d763-4f93-882a-371296a3c63f'),


@@ 29,7 29,7 @@ from tests.helpers import app_context
        ImageType.png,
        Path('/home/byceps/data/global/users/avatars/f0266761-c37e-4519-8cb8-5812d2bfe595.png'),
    ),
)
])
def test_path(avatar_images_path, avatar_id, image_type, expected):
    user = create_user()


M tests/services/verification_token/test_models.py => tests/services/verification_token/test_models.py +3 -3
@@ 6,7 6,7 @@
from datetime import datetime

from freezegun import freeze_time
from nose2.tools import params
import pytest

from byceps.services.verification_token.models import Purpose



@@ 14,7 14,7 @@ from testfixtures.user import create_user
from testfixtures.verification_token import create_verification_token


@params(
@pytest.mark.parametrize('purpose, now, expected', [
    (
        Purpose.email_address_confirmation,
        datetime(2014, 11, 26, 19, 54, 38),


@@ 45,7 45,7 @@ from testfixtures.verification_token import create_verification_token
        datetime(2014, 11, 27, 19, 54, 38),
        True,
    ),
)
])
def test_is_expired(purpose, now, expected):
    user = create_user()
    created_at = datetime(2014, 11, 26, 17, 44, 53)

M tests/util/datetime/test_calc.py => tests/util/datetime/test_calc.py +5 -5
@@ 5,7 5,7 @@

from datetime import date

from nose2.tools import params
import pytest

from byceps.util.datetime.calc import calculate_age, calculate_days_until



@@ 13,26 13,26 @@ from byceps.util.datetime.calc import calculate_age, calculate_days_until
SOME_DATE = date(1994, 3, 18)


@params(
@pytest.mark.parametrize('today, expected', [
    (date(2014, 3, 17), 19),
    (date(2014, 3, 18), 20),
    (date(2014, 3, 19), 20),
    (date(2015, 3, 17), 20),
    (date(2015, 3, 18), 21),
    (date(2015, 3, 19), 21),
)
])
def test_calculate_age(today, expected):
    actual = calculate_age(SOME_DATE, today)

    assert actual == expected


@params(
@pytest.mark.parametrize('today, expected', [
    (date(2014, 3, 16), 2),
    (date(2014, 3, 17), 1),
    (date(2014, 3, 18), 0),
    (date(2014, 3, 19), 364),
)
])
def test_calculate_days_until(today, expected):
    actual = calculate_days_until(SOME_DATE, today)


M tests/util/datetime/test_datetimerange.py => tests/util/datetime/test_datetimerange.py +3 -3
@@ 5,12 5,12 @@

from datetime import datetime

from nose2.tools import params
import pytest

from byceps.util.datetime.range import create_adjacent_ranges, DateTimeRange


@params(
@pytest.mark.parametrize('starts_at, ends_at, tested_datetime, expected', [
    (
        datetime(2014,  8, 15, 12,  0,  0),
        datetime(2014,  8, 15, 19, 30,  0),


@@ 53,7 53,7 @@ from byceps.util.datetime.range import create_adjacent_ranges, DateTimeRange
        datetime(2014,  8, 15, 19, 30,  1),
        False,
    ),
)
])
def test_contains(starts_at, ends_at, tested_datetime, expected):
    date_time_range = DateTimeRange(start=starts_at, end=ends_at)


M tests/util/datetime/test_monthday.py => tests/util/datetime/test_monthday.py +5 -5
@@ 5,17 5,17 @@

from datetime import date

from nose2.tools import params
import pytest

from byceps.util.datetime.monthday import MonthDay


@params(
@pytest.mark.parametrize('date, expected_month, expected_day', [
    (date(1994,  3, 18),  3, 18),
    (date(2012,  9, 27),  9, 27),
    (date(2015,  1,  1),  1,  1),
    (date(2022, 12, 31), 12, 31),
)
])
def test_of(date, expected_month, expected_day):
    month_day = MonthDay.of(date)



@@ 23,7 23,7 @@ def test_of(date, expected_month, expected_day):
    assert month_day.day == expected_day


@params(
@pytest.mark.parametrize('month, day, date, expected', [
    ( 3, 17, date(2005,  2, 17), False),
    ( 3, 17, date(2005,  3, 16), False),
    ( 3, 17, date(2005,  3, 17), True ),


@@ 33,7 33,7 @@ def test_of(date, expected_month, expected_day):
    ( 3, 17, date(2005,  4, 17), False),
    (12, 31, date(2010, 12, 30), False),
    (12, 31, date(2010, 12, 31), True ),
)
])
def test_matches(month, day, date, expected):
    month_day = MonthDay(month=month, day=day)


M tests/util/image/test_dimensions.py => tests/util/image/test_dimensions.py +3 -3
@@ 3,17 3,17 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.util.image.models import Dimensions


@params(
@pytest.mark.parametrize('width, height, expected', [
    ( 1,  1, True ),
    (12, 16, False),
    (16, 12, False),
    (16, 16, True ),
)
])
def test_is_square(width, height, expected):
    dimensions = Dimensions(width, height)


M tests/util/image/test_image.py => tests/util/image/test_image.py +5 -5
@@ 5,19 5,19 @@

from pathlib import Path

from nose2.tools import params
import pytest

from byceps.util.image import read_dimensions
from byceps.util.image.models import Dimensions, ImageType
from byceps.util.image.typeguess import guess_type


@params(
@pytest.mark.parametrize('filename_suffix, expected', [
    ('bmp',  None          ),
    ('gif',  ImageType.gif ),
    ('jpeg', ImageType.jpeg),
    ('png',  ImageType.png ),
)
])
def test_guess_type(filename_suffix, expected):
    with open_image_with_suffix(filename_suffix) as f:
        actual = guess_type(f)


@@ 25,12 25,12 @@ def test_guess_type(filename_suffix, expected):
    assert actual == expected


@params(
@pytest.mark.parametrize('filename_suffix, expected_width, expected_height', [
    ('bmp',   7, 11),
    ('gif',  17,  4),
    ('jpeg', 12,  7),
    ('png',   8, 25),
)
])
def test_read_dimensions(filename_suffix, expected_width, expected_height):
    expected = Dimensions(width=expected_width, height=expected_height)


M tests/util/test_authorization.py => tests/util/test_authorization.py +6 -6
@@ 3,27 3,27 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.util.authorization import create_permission_enum


@params(
    ('user',      ),
@pytest.mark.parametrize('key', [
    ('user'       ),
    ('board_topic'),
)
])
def test_key(key):
    enum = create_permission_enum(key, ['some_member'])

    assert enum.__key__ == key


@params(
@pytest.mark.parametrize('key, expected', [
    ('user',        'UserPermission'      ),
    ('board_topic', 'BoardTopicPermission'),
    ('foo_bar_baz', 'FooBarBazPermission' ),
    ('CASe_FReNzY', 'CaseFrenzyPermission'),
)
])
def test_name_derivation(key, expected):
    enum = create_permission_enum(key, ['some_member'])


M tests/util/test_checkdigit.py => tests/util/test_checkdigit.py +3 -3
@@ 3,12 3,12 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.util.checkdigit import calculate_check_digit


@params(
@pytest.mark.parametrize('chars, expected', [
    ('12',         5),
    ('123',        0),
    ('1245496594', 3),


@@ 30,6 30,6 @@ from byceps.util.checkdigit import calculate_check_digit
    ('6KWKDFD79A', 8),
    ('HXNPKGY4EX', 3),
    ('91BT',       2),
)
])
def test_calculate_check_digit(chars, expected):
    assert calculate_check_digit(chars) == expected

M tests/util/test_iterables.py => tests/util/test_iterables.py +7 -7
@@ 3,12 3,12 @@
:License: Modified BSD, see LICENSE for details.
"""

from nose2.tools import params
import pytest

from byceps.util.iterables import find, index_of, pairwise


@params(
@pytest.mark.parametrize('predicate, iterable, expected', [
    (
        lambda x: x > 3,
        [],


@@ 24,13 24,13 @@ from byceps.util.iterables import find, index_of, pairwise
        [2, 3, 4, 5],
        4,
    ),
)
])
def test_find(predicate, iterable, expected):
    actual = find(predicate, iterable)
    assert actual == expected


@params(
@pytest.mark.parametrize('predicate, iterable, expected', [
    (
        lambda x: x > 3,
        [],


@@ 51,13 51,13 @@ def test_find(predicate, iterable, expected):
        [2, 3, 4, 5],
        None,
    ),
)
])
def test_index_of(predicate, iterable, expected):
    actual = index_of(predicate, iterable)
    assert actual == expected


@params(
@pytest.mark.parametrize('iterable, expected', [
    (
        [],
        [],


@@ 70,7 70,7 @@ def test_index_of(predicate, iterable, expected):
        range(5),
        [(0, 1), (1, 2), (2, 3), (3, 4)],
    ),
)
])
def test_pairwise(iterable, expected):
    actual = pairwise(iterable)
    assert list(actual) == expected

M tests/util/test_money.py => tests/util/test_money.py +5 -5
@@ 5,13 5,13 @@

from decimal import Decimal

from nose2.tools import params
import pytest

from byceps.util.l10n import set_locale
from byceps.util.money import format_euro_amount, to_two_places


@params(
@pytest.mark.parametrize('value, expected', [
    (Decimal(      '0.00' ),         '0,00 €'),
    (Decimal(      '0.01' ),         '0,01 €'),
    (Decimal(      '0.5'  ),         '0,50 €'),


@@ 20,14 20,14 @@ from byceps.util.money import format_euro_amount, to_two_places
    (Decimal(    '123.456'),       '123,46 €'),
    (Decimal('1234567'    ), '1.234.567,00 €'),
    (Decimal('1234567.89' ), '1.234.567,89 €'),
)
])
def test_format_euro_amount(value, expected):
    set_locale('de_DE.UTF-8')

    assert format_euro_amount(value) == expected


@params(
@pytest.mark.parametrize('value, expected', [
    (Decimal(       '0'), Decimal(  '0.00')),
    (Decimal(     '0.1'), Decimal(  '0.10')),
    (Decimal(    '0.01'), Decimal(  '0.01')),


@@ 35,6 35,6 @@ def test_format_euro_amount(value, expected):
    (Decimal(   '0.009'), Decimal(  '0.01')),
    (Decimal('123.4500'), Decimal('123.45')),
    (Decimal('123.4567'), Decimal('123.46')),
)
])
def test_to_two_places(value, expected):
    assert to_two_places(value) == expected

M tox.ini => tox.ini +1 -1
@@ 2,7 2,7 @@
envlist = py34,py35,py36

[testenv]
commands = nose2
commands = py.test
deps =
    -rrequirements.txt
    -rrequirements-test.txt