From 1181a35dd06d48c779208a6d2a4b3672dd38d812 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Fri, 29 Dec 2017 00:31:07 +0100 Subject: [PATCH] Ported tests from nose2 to pytest --- .gitignore | 2 ++ README.rst | 4 ++-- requirements-test.txt | 2 +- setup.cfg | 5 +++++ setup.py | 2 +- .../blueprints/authorization/test_registry.py | 10 +++++----- tests/services/country/test_service.py | 6 +++--- tests/services/news/test_models.py | 18 +++++++++--------- .../models/test_article_availability.py | 18 +++++++++--------- .../cart/models/test_cart_item_creation.py | 6 +++--- tests/services/text_markup/test_service.py | 6 +++--- tests/services/ticketing/test_models.py | 18 +++++++++--------- .../ticketing/test_service_assignment.py | 8 +++++--- tests/services/ticketing/test_user_check_in.py | 6 ++++-- tests/services/user/test_models_age.py | 6 +++--- tests/services/user/test_models_birthday.py | 10 +++++----- tests/services/user/test_models_full_name.py | 6 +++--- tests/services/user_avatar/test_models.py | 10 +++++----- .../user_avatar/test_models_image_path.py | 6 +++--- .../services/verification_token/test_models.py | 6 +++--- tests/util/datetime/test_calc.py | 10 +++++----- tests/util/datetime/test_datetimerange.py | 6 +++--- tests/util/datetime/test_monthday.py | 10 +++++----- tests/util/image/test_dimensions.py | 6 +++--- tests/util/image/test_image.py | 10 +++++----- tests/util/test_authorization.py | 12 ++++++------ tests/util/test_checkdigit.py | 6 +++--- tests/util/test_iterables.py | 14 +++++++------- tests/util/test_money.py | 10 +++++----- tox.ini | 2 +- 30 files changed, 126 insertions(+), 115 deletions(-) create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 67e5e1c69..6afbddb09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Python 3 bytecode __pycache__ +.eggs + # virtual environment venv diff --git a/README.rst b/README.rst index 08600234f..8089303d4 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/requirements-test.txt b/requirements-test.txt index 506833441..102b05671 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,3 @@ freezegun >= 0.3.8 -nose2 >= 0.6.5 +pytest >= 3.3 tox >= 2.3.2 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..7eebebf32 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[aliases] +test = pytest + +[tool:pytest] +testpaths = tests diff --git a/setup.py b/setup.py index dcc842940..58007111a 100644 --- a/setup.py +++ b/setup.py @@ -41,6 +41,6 @@ setup( ], packages=['byceps'], install_requires=requirements, + setup_requires=['pytest-runner'], tests_require=requirements_test, - test_suite='nose2.collector.collector', ) diff --git a/tests/blueprints/authorization/test_registry.py b/tests/blueprints/authorization/test_registry.py index eddb527f6..825983e8d 100644 --- a/tests/blueprints/authorization/test_registry.py +++ b/tests/blueprints/authorization/test_registry.py @@ -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() diff --git a/tests/services/country/test_service.py b/tests/services/country/test_service.py index 847003cb7..fd59b78be 100644 --- a/tests/services/country/test_service.py +++ b/tests/services/country/test_service.py @@ -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() diff --git a/tests/services/news/test_models.py b/tests/services/news/test_models.py index 5ccefc810..afc95e437 100644 --- a/tests/services/news/test_models.py +++ b/tests/services/news/test_models.py @@ -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 diff --git a/tests/services/shop/article/models/test_article_availability.py b/tests/services/shop/article/models/test_article_availability.py index 30564a242..233d50ac5 100644 --- a/tests/services/shop/article/models/test_article_availability.py +++ b/tests/services/shop/article/models/test_article_availability.py @@ -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, diff --git a/tests/services/shop/cart/models/test_cart_item_creation.py b/tests/services/shop/cart/models/test_cart_item_creation.py index aa39568b1..3df734b84 100644 --- a/tests/services/shop/cart/models/test_cart_item_creation.py +++ b/tests/services/shop/cart/models/test_cart_item_creation.py @@ -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) diff --git a/tests/services/text_markup/test_service.py b/tests/services/text_markup/test_service.py index d087d1d6e..dd964c5d2 100644 --- a/tests/services/text_markup/test_service.py +++ b/tests/services/text_markup/test_service.py @@ -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]', '

foo]bar schrieb:

\n
blah
', @@ -79,6 +79,6 @@ def test_quote_with_author(): '[quote author=""]careful.[/quote]', '

<AngleBracketeer> schrieb:

\n
careful.
', ), -) +]) def test_quote_with_author_whose_name_contains_square_brackets(text, expected): assert render_html(text) == expected diff --git a/tests/services/ticketing/test_models.py b/tests/services/ticketing/test_models.py index 98a29fcd8..fd2776487 100644 --- a/tests/services/ticketing/test_models.py +++ b/tests/services/ticketing/test_models.py @@ -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) diff --git a/tests/services/ticketing/test_service_assignment.py b/tests/services/ticketing/test_service_assignment.py index 4a124a4be..3139f83df 100644 --- a/tests/services/ticketing/test_service_assignment.py +++ b/tests/services/ticketing/test_service_assignment.py @@ -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) # -------------------------------------------------------------------- # diff --git a/tests/services/ticketing/test_user_check_in.py b/tests/services/ticketing/test_user_check_in.py index 25d9bc22b..56c6f58dc 100644 --- a/tests/services/ticketing/test_user_check_in.py +++ b/tests/services/ticketing/test_user_check_in.py @@ -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) # -------------------------------------------------------------------- # diff --git a/tests/services/user/test_models_age.py b/tests/services/user/test_models_age.py index 922795e7c..1964f14a5 100644 --- a/tests/services/user/test_models_age.py +++ b/tests/services/user/test_models_age.py @@ -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)) diff --git a/tests/services/user/test_models_birthday.py b/tests/services/user/test_models_birthday.py index 17941f182..b601c5fde 100644 --- a/tests/services/user/test_models_birthday.py +++ b/tests/services/user/test_models_birthday.py @@ -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)) diff --git a/tests/services/user/test_models_full_name.py b/tests/services/user/test_models_full_name.py index f8f20d994..412953d98 100644 --- a/tests/services/user/test_models_full_name.py +++ b/tests/services/user/test_models_full_name.py @@ -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) diff --git a/tests/services/user_avatar/test_models.py b/tests/services/user_avatar/test_models.py index 2c834cedf..70f081f02 100644 --- a/tests/services/user_avatar/test_models.py +++ b/tests/services/user_avatar/test_models.py @@ -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) diff --git a/tests/services/user_avatar/test_models_image_path.py b/tests/services/user_avatar/test_models_image_path.py index bf8c0d6da..9f5270c6c 100644 --- a/tests/services/user_avatar/test_models_image_path.py +++ b/tests/services/user_avatar/test_models_image_path.py @@ -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() diff --git a/tests/services/verification_token/test_models.py b/tests/services/verification_token/test_models.py index 896634fe6..85ed08d37 100644 --- a/tests/services/verification_token/test_models.py +++ b/tests/services/verification_token/test_models.py @@ -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) diff --git a/tests/util/datetime/test_calc.py b/tests/util/datetime/test_calc.py index 865ecc04e..65562cbab 100644 --- a/tests/util/datetime/test_calc.py +++ b/tests/util/datetime/test_calc.py @@ -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) diff --git a/tests/util/datetime/test_datetimerange.py b/tests/util/datetime/test_datetimerange.py index eaa65e0e2..1ffde4ab0 100644 --- a/tests/util/datetime/test_datetimerange.py +++ b/tests/util/datetime/test_datetimerange.py @@ -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) diff --git a/tests/util/datetime/test_monthday.py b/tests/util/datetime/test_monthday.py index 7fb78534b..f792a725b 100644 --- a/tests/util/datetime/test_monthday.py +++ b/tests/util/datetime/test_monthday.py @@ -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) diff --git a/tests/util/image/test_dimensions.py b/tests/util/image/test_dimensions.py index e3e601637..f80d0b47c 100644 --- a/tests/util/image/test_dimensions.py +++ b/tests/util/image/test_dimensions.py @@ -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) diff --git a/tests/util/image/test_image.py b/tests/util/image/test_image.py index 80a21aba2..0027bf752 100644 --- a/tests/util/image/test_image.py +++ b/tests/util/image/test_image.py @@ -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) diff --git a/tests/util/test_authorization.py b/tests/util/test_authorization.py index dc63c8646..5298d80df 100644 --- a/tests/util/test_authorization.py +++ b/tests/util/test_authorization.py @@ -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']) diff --git a/tests/util/test_checkdigit.py b/tests/util/test_checkdigit.py index fc530b3d3..71d22aec8 100644 --- a/tests/util/test_checkdigit.py +++ b/tests/util/test_checkdigit.py @@ -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 diff --git a/tests/util/test_iterables.py b/tests/util/test_iterables.py index afec8751a..a04557f95 100644 --- a/tests/util/test_iterables.py +++ b/tests/util/test_iterables.py @@ -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 diff --git a/tests/util/test_money.py b/tests/util/test_money.py index 8c6a3751c..7fbe102db 100644 --- a/tests/util/test_money.py +++ b/tests/util/test_money.py @@ -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 diff --git a/tox.ini b/tox.ini index 6fade45aa..b50cc0903 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py34,py35,py36 [testenv] -commands = nose2 +commands = py.test deps = -rrequirements.txt -rrequirements-test.txt -- 2.34.2