Skip to content

Commit

Permalink
Handle some Deprecations (pypi#10410)
Browse files Browse the repository at this point in the history
* Fix PytestCollectionWarning

When collecting tests, this class raises a warning since it's named
`Test*`:

    PytestCollectionWarning: cannot collect test class 'TestAdminFlagValues'
    because it has a __new__ constructor

Set an attribute that informs pytest to ignore this class, and thus
remove the warning.

Refs: https://docs.pytest.org/en/6.2.x/example/pythoncollection.html#customizing-test-collection
(last lines)

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* Fix PytestDeprecationWarning

Current test warns:

    PytestDeprecationWarning: The --strict option is deprecated, use --strict-markers instead.

Marked as deprecated in pytest-dev/pytest#7985
Released in pytest 6.2.0

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* Fix DeprecationWarning pyramid import

The import paths for these modules has changed in Pyramid 2.0, and
raises warnings.
There are other Pyramid 2.0 warnings, but are more involved than
changing an import path, and should be addressed as another commit.

Refs: Pylons/pyramid#3563

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* Fix DeprecationWarning for jinja.contextfilter

A few instances of this warning are raised:

    DeprecationWarning: 'contextfilter' is renamed to 'pass_context',
    the old name will be removed in Jinja 3.1.

Replace the usages accordingly.

Refs: pallets/jinja#1389

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* Fix DeprecationWarning for jinja.Markup

The pass-through import of markup.Markup() has been deprecated in Jinja
3.0, and will be removed in Jinja 3.1. Warnings raised:

    DeprecationWarning: 'jinja2.Markup' is deprecated and will be removed in Jinja 3.1.
    Import 'markupsafe.Markup' instead.

Replace the import paths.

TODO: Determine if the requirements/main.in needs to be changed as well.

Refs: pallets/jinja#1391

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

* Fix DeprecationWarning for babel.numbers.from_number

Warnings raised:

    DeprecationWarning: Use babel.numbers.format_decimal() instead.

Deprecated since 2.6.0

Refs: python-babel/babel#538

Signed-off-by: Mike Fiedler <miketheman@gmail.com>

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
2 people authored and domdfcoding committed Jun 7, 2022
1 parent 4b30a04 commit d0eedd7
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bin/tests
Expand Up @@ -33,6 +33,6 @@ fi
set -x

# Actually run our tests.
python -m coverage run -m pytest --strict $COMMAND_ARGS
python -m coverage run -m pytest --strict-markers $COMMAND_ARGS
python -m coverage html
python -m coverage report -m --fail-under 100
1 change: 1 addition & 0 deletions tests/unit/admin/test_flags.py
Expand Up @@ -16,6 +16,7 @@


class TestAdminFlagValues(enum.Enum):
__test__ = False
NOT_A_REAL_FLAG = "not-a-real-flag"
THIS_FLAG_IS_ENABLED = "this-flag-is-enabled"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/i18n/test_filters.py
Expand Up @@ -70,7 +70,7 @@ def test_format_rfc822_datetime(monkeypatch):
def test_format_number(monkeypatch):
formatted = pretend.stub()
format_number = pretend.call_recorder(lambda *a, **kw: formatted)
monkeypatch.setattr(babel.numbers, "format_number", format_number)
monkeypatch.setattr(babel.numbers, "format_decimal", format_number)

request = pretend.stub(locale=pretend.stub())
ctx = pretend.stub(get=pretend.call_recorder(lambda k: request))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/packaging/test_models.py
Expand Up @@ -15,8 +15,8 @@
import pretend
import pytest

from pyramid.authorization import Allow
from pyramid.location import lineage
from pyramid.security import Allow

from warehouse.packaging.models import Dependency, DependencyKind, File, ProjectFactory

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_config.py
Expand Up @@ -16,8 +16,8 @@
import pytest

from pyramid import renderers
from pyramid.authorization import Allow, Authenticated
from pyramid.httpexceptions import HTTPForbidden, HTTPUnauthorized
from pyramid.security import Allow, Authenticated
from pyramid.tweens import EXCVIEW

from warehouse import config
Expand Down
8 changes: 4 additions & 4 deletions warehouse/accounts/forms.py
Expand Up @@ -16,7 +16,7 @@
from email.headerregistry import Address

import disposable_email_domains
import jinja2
import markupsafe
import wtforms
import wtforms.fields
import wtforms.fields.html5
Expand Down Expand Up @@ -181,7 +181,7 @@ def validate_new_password(self, field):
field.data, tags=["method:new_password"]
):
raise wtforms.validators.ValidationError(
jinja2.Markup(self._breach_service.failure_message)
markupsafe.Markup(self._breach_service.failure_message)
)


Expand Down Expand Up @@ -278,7 +278,7 @@ def validate_password(self, field):
is_disabled, disabled_for = self.user_service.is_disabled(userid)
if is_disabled and disabled_for == DisableReason.CompromisedPassword:
raise wtforms.validators.ValidationError(
jinja2.Markup(self.breach_service.failure_message)
markupsafe.Markup(self.breach_service.failure_message)
)

# Do our typical validation of the password.
Expand All @@ -297,7 +297,7 @@ def validate_password(self, field):
user.id, reason=DisableReason.CompromisedPassword
)
raise wtforms.validators.ValidationError(
jinja2.Markup(self.breach_service.failure_message)
markupsafe.Markup(self.breach_service.failure_message)
)


Expand Down
2 changes: 1 addition & 1 deletion warehouse/config.py
Expand Up @@ -18,9 +18,9 @@
import transaction

from pyramid import renderers
from pyramid.authorization import Allow, Authenticated
from pyramid.config import Configurator as _Configurator
from pyramid.response import Response
from pyramid.security import Allow, Authenticated
from pyramid.tweens import EXCVIEW
from pyramid_rpc.xmlrpc import XMLRPCRenderer

Expand Down
2 changes: 1 addition & 1 deletion warehouse/filters.py
Expand Up @@ -63,7 +63,7 @@ def _camo_url(request, url):
return urllib.parse.urljoin(camo_url, path)


@jinja2.contextfilter
@jinja2.pass_context
def camoify(ctx, value):
request = ctx.get("request") or get_current_request()

Expand Down
10 changes: 5 additions & 5 deletions warehouse/i18n/filters.py
Expand Up @@ -19,28 +19,28 @@
from pyramid.threadlocal import get_current_request


@jinja2.contextfilter
@jinja2.pass_context
def format_date(ctx, *args, **kwargs):
request = ctx.get("request") or get_current_request()
kwargs.setdefault("locale", request.locale)
return babel.dates.format_date(*args, **kwargs)


@jinja2.contextfilter
@jinja2.pass_context
def format_datetime(ctx, *args, **kwargs):
request = ctx.get("request") or get_current_request()
kwargs.setdefault("locale", request.locale)
return babel.dates.format_datetime(*args, **kwargs)


@jinja2.contextfilter
@jinja2.pass_context
def format_rfc822_datetime(ctx, dt, *args, **kwargs):
return email.utils.formatdate(dt.timestamp(), usegmt=True)


@jinja2.contextfilter
@jinja2.pass_context
def format_number(ctx, number, locale=None):
request = ctx.get("request") or get_current_request()
if locale is None:
locale = request.locale
return babel.numbers.format_number(number, locale=locale)
return babel.numbers.format_decimal(number, locale=locale)
2 changes: 1 addition & 1 deletion warehouse/packaging/models.py
Expand Up @@ -18,7 +18,7 @@
import packaging.utils

from citext import CIText
from pyramid.security import Allow
from pyramid.authorization import Allow
from pyramid.threadlocal import get_current_request
from sqlalchemy import (
BigInteger,
Expand Down
4 changes: 2 additions & 2 deletions warehouse/policy.py
Expand Up @@ -13,7 +13,7 @@
import os.path

import html5lib
import jinja2
import markupsafe
import mistune

import warehouse
Expand All @@ -39,7 +39,7 @@ def markdown_view(request):

title = html.find("//h1[1]").text

return {"title": title, "html": jinja2.Markup(rendered)}
return {"title": title, "html": markupsafe.Markup(rendered)}

return markdown_view

Expand Down

0 comments on commit d0eedd7

Please sign in to comment.