Skip to content

Fix support of Python 3.8 (revamped) #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"python": [
"2.7",
"3.6",
"3.7"
"3.7",
"3.8"
],
"cache": "pip",
"install": [
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, os.path.abspath("../src"))

os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.django.settings"

# -- General configuration ------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[pytest]
DJANGO_SETTINGS_MODULE = tests.settings
DJANGO_SETTINGS_MODULE = tests.django.settings
norecursedirs = .git .*
addopts = -rsxX --showlocals --tb=native --nomigrations --cov=dockerflow --cov-report xml --cov-report term --cov-report html
addopts = -rsxX --showlocals --tb=native --cov=dockerflow --cov-report xml --cov-report term --cov-report html --cov-append
django_find_project = false
python_paths = .
4 changes: 2 additions & 2 deletions src/dockerflow/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def __init__(self, fmt=None, datefmt=None, style="%", logger_name="Dockerflow"):
# positional arguments we have to do a version check here
# to decide whether to pass the style argument or not.
if sys.version_info[:2] < (3, 1):
parent_init(self, format, datefmt)
parent_init(self, fmt, datefmt)
else:
parent_init(self, format, datefmt, style)
parent_init(self, fmt=fmt, datefmt=datefmt, style=style)
self.logger_name = logger_name
self.hostname = socket.gethostname()

Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
Empty file added tests/django/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
28 changes: 18 additions & 10 deletions tests/test_django.py → tests/django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
from dockerflow.django import checks
from dockerflow.django.middleware import DockerflowMiddleware

try:
from django.utils.deprecation import MiddlewareMixin
except ImportError: # pragma: no cover
MiddlewareMixin = object


@pytest.fixture
def reset_checks():
Expand Down Expand Up @@ -57,8 +62,8 @@ def test_heartbeat(dockerflow_middleware, reset_checks, rf, settings):
assert response.status_code == 200

settings.DOCKERFLOW_CHECKS = [
"tests.django_checks.warning",
"tests.django_checks.error",
"tests.django.django_checks.warning",
"tests.django.django_checks.error",
]
checks.register()
response = dockerflow_middleware.process_request(request)
Expand Down Expand Up @@ -138,18 +143,21 @@ def test_request_summary_exception(


def test_request_summary_failed_request(
caplog, dockerflow_middleware, dockerflow_request
admin_user, caplog, dockerflow_middleware, dockerflow_request
):
dockerflow_middleware.process_request(dockerflow_request)

class HostileMiddleware(object):
class HostileMiddleware(MiddlewareMixin):
def process_request(self, request):
# simulating resetting request changes
delattr(dockerflow_request, "_id")
delattr(dockerflow_request, "_start_timestamp")
return None
delattr(request, "_id")
delattr(request, "_start_timestamp")

response = HostileMiddleware().process_request(dockerflow_request)
def process_response(self, request, response):
return response

hostile_middleware = HostileMiddleware()
response = dockerflow_middleware.process_request(dockerflow_request)
response = hostile_middleware.process_request(dockerflow_request)
response = hostile_middleware.process_response(dockerflow_request, response)
dockerflow_middleware.process_response(dockerflow_request, response)
assert len(caplog.records) == 1
record = caplog.records[0]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 0 additions & 30 deletions tests/requirements.txt

This file was deleted.

11 changes: 11 additions & 0 deletions tests/requirements/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
pytest
pytest-coverage
pytest-mock
pytest-pythonpath
mock
redis<3.2.0
fakeredis
jsonschema
6 changes: 6 additions & 0 deletions tests/requirements/django.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
django-redis
pytest-django
# these are constrained by the files in tests/constraints/*.txt
# to support a triple stack Django/Flask/Sanic
Django; python_version >= '3.0'
Django<2.0; python_version < '3.0'
2 changes: 2 additions & 0 deletions tests/requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sphinx
sphinxcontrib-httpdomain
8 changes: 8 additions & 0 deletions tests/requirements/flask.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# these are constrained by the files in tests/constraints/*.txt
# to support a triple stack Django/Flask/Sanic
Flask
Flask-Redis
Flask-SQLAlchemy
Flask-Login
Flask-Migrate
blinker
5 changes: 5 additions & 0 deletions tests/requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flake8
flake8-black
flake8-isort
twine
check-manifest
7 changes: 7 additions & 0 deletions tests/requirements/sanic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# these are constrained by the files in tests/constraints/*.txt
# to support a triple stack Django/Flask/Sanic
aiohttp
aioredis
Sanic
sanic_redis
uvloop>=0.14.0rc1
File renamed without changes.
47 changes: 29 additions & 18 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,59 @@
usedevelop = True
minversion = 1.8
envlist =
py36-lint,
py36-dj{111,21,22}-docs,
py38-lint,
py38-docs,
# the version matrix according to the Django docs:
# https://docs.djangoproject.com/en/2.0/faq/install/#what-python-version-can-i-use-with-django
py{27,36}-dj111-tests,
py{36,37}-dj{21,22}-tests,
py{27,36}-fl{011,012,10}-tests,
py{36,37}-s19-tests,
# py{36,37,38}-dj30-tests,
py{27,36,37,38}-fl{011,012,10}-tests,
py{36,37,38}-s19-tests,

[testenv]
basepython =
py27: python2.7
py36: python3.6
py37: python3.7
py38: python3.8
usedevelop = true
pip_pre = true
setenv =
DJANGO_SETTINGS_MODULE = tests.settings
DJANGO_SETTINGS_MODULE = tests.django.settings
PYTHONPATH = {toxinidir}
# sanic integration requires python >= 3.5
tests-py{27,34}: PYTEST_ADDOPTS = --ignore=tests/test_sanic.py
deps =
-rtests/requirements.txt
-rtests/requirements/default.txt
dj{111,21,22,30}: -rtests/requirements/django.txt
fl{011,012,10}: -rtests/requirements/flask.txt
s19: -rtests/requirements/sanic.txt
dj111: -ctests/constraints/django-1.11.txt
dj21: -ctests/constraints/django-2.1.txt
dj21: -ctests/constraints/django-2.2.txt
dj22: -ctests/constraints/django-2.2.txt
# dj30: -ctests/constraints/django-3.0.txt
fl011: -ctests/constraints/flask-0.11.txt
fl012: -ctests/constraints/flask-0.12.txt
fl10: -ctests/constraints/flask-1.0.txt
s19: -ctests/constraints/sanic-19.txt
commands =
python --version
tests: pytest {posargs:tests}
docs: sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
dj{111,21,22,30}-tests: pytest tests/core/ tests/django --nomigrations {posargs:}
fl{011,012,10}-tests: pytest tests/core/ tests/flask/ {posargs:}
s19: pytest tests/core/ tests/sanic/

[testenv:py36-lint]
basepython = python3.6
[testenv:py38-docs]
basepython = python3.8
deps =
flake8
flake8-black
flake8-isort
twine
check-manifest
-rtests/requirements/default.txt
-rtests/requirements/docs.txt
-rtests/requirements/django.txt
-rtests/requirements/flask.txt
-rtests/requirements/sanic.txt
commands = sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html

[testenv:py38-lint]
basepython = python3.8
deps = -rtests/requirements/lint.txt
commands =
flake8 src/dockerflow tests/
check-manifest -v
Expand Down