mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-07 21:21:30 +08:00
fix: resolve lint issues and remove obsolete Sphinx references
- Fix lint issues in test_gthread.py: - Remove unused imports (queue, partial, http) - Move fcntl import to top level - Remove unused variable assignment - Replace unnecessary lambdas with method references - Add blank lines before nested function definitions (E306) - Update .github/workflows/lint.yml: - Replace Sphinx docs check with MkDocs settings generator - docs/source directory no longer exists after MkDocs migration - Update tox.ini: - Remove docs/source/*.rst lint (directory doesn't exist) - Add tests/test_gthread.py to lint targets
This commit is contained in:
parent
47b9a18619
commit
0e175a2d34
12
.github/workflows/lint.yml
vendored
12
.github/workflows/lint.yml
vendored
@ -36,17 +36,17 @@ jobs:
|
|||||||
- name: Install Dependencies (non-toxic)
|
- name: Install Dependencies (non-toxic)
|
||||||
if: ${{ ! matrix.toxenv }}
|
if: ${{ ! matrix.toxenv }}
|
||||||
run: |
|
run: |
|
||||||
python -m pip install sphinx
|
python -m pip install --upgrade pip
|
||||||
- name: "Update docs"
|
python -m pip install -e .
|
||||||
|
- name: "Check generated docs"
|
||||||
if: ${{ ! matrix.toxenv }}
|
if: ${{ ! matrix.toxenv }}
|
||||||
run: |
|
run: |
|
||||||
# this will update docs/source/settings.rst - but will not create html output
|
# Regenerate settings.md and check for uncommitted changes
|
||||||
(cd docs && sphinx-build -b "dummy" -d _build/doctrees source "_build/dummy")
|
python scripts/build_settings_doc.py
|
||||||
git update-index --assume-unchanged docs/source/settings.rst
|
|
||||||
if unclean=$(git status --untracked-files=no --porcelain) && [ -z "$unclean" ]; then
|
if unclean=$(git status --untracked-files=no --porcelain) && [ -z "$unclean" ]; then
|
||||||
echo "no uncommitted changes in working tree (as it should be)"
|
echo "no uncommitted changes in working tree (as it should be)"
|
||||||
else
|
else
|
||||||
echo "did you forget to run `make -C docs html`?"
|
echo "did you forget to run 'python scripts/build_settings_doc.py'?"
|
||||||
echo "$unclean"
|
echo "$unclean"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -5,19 +5,17 @@
|
|||||||
"""Tests for the gthread worker."""
|
"""Tests for the gthread worker."""
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
|
import fcntl
|
||||||
import os
|
import os
|
||||||
import queue
|
|
||||||
import selectors
|
import selectors
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from functools import partial
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from gunicorn import http
|
|
||||||
from gunicorn.config import Config
|
from gunicorn.config import Config
|
||||||
from gunicorn.workers import gthread
|
from gunicorn.workers import gthread
|
||||||
|
|
||||||
@ -85,7 +83,7 @@ class TestTConn:
|
|||||||
sock = FakeSocket()
|
sock = FakeSocket()
|
||||||
sock.setblocking(True)
|
sock.setblocking(True)
|
||||||
|
|
||||||
conn = gthread.TConn(cfg, sock, ('127.0.0.1', 12345), ('127.0.0.1', 8000))
|
gthread.TConn(cfg, sock, ('127.0.0.1', 12345), ('127.0.0.1', 8000))
|
||||||
|
|
||||||
# TConn sets socket to non-blocking in __init__
|
# TConn sets socket to non-blocking in __init__
|
||||||
assert sock.blocking is False
|
assert sock.blocking is False
|
||||||
@ -147,7 +145,7 @@ class TestPollableMethodQueue:
|
|||||||
q.init()
|
q.init()
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
q.defer(lambda x: results.append(x), 42)
|
q.defer(results.append, 42)
|
||||||
|
|
||||||
# Simulate the selector reading from the pipe
|
# Simulate the selector reading from the pipe
|
||||||
q.run_callbacks(None)
|
q.run_callbacks(None)
|
||||||
@ -162,7 +160,7 @@ class TestPollableMethodQueue:
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
q.defer(lambda x: results.append(x), i)
|
q.defer(results.append, i)
|
||||||
|
|
||||||
q.run_callbacks(None)
|
q.run_callbacks(None)
|
||||||
|
|
||||||
@ -220,9 +218,6 @@ class TestPollableMethodQueue:
|
|||||||
|
|
||||||
def test_queue_nonblocking_pipe(self):
|
def test_queue_nonblocking_pipe(self):
|
||||||
"""Test that pipe is non-blocking (BSD compatibility)."""
|
"""Test that pipe is non-blocking (BSD compatibility)."""
|
||||||
import os
|
|
||||||
import fcntl
|
|
||||||
|
|
||||||
q = gthread.PollableMethodQueue()
|
q = gthread.PollableMethodQueue()
|
||||||
q.init()
|
q.init()
|
||||||
|
|
||||||
@ -889,18 +884,22 @@ class TestWorkerLiveness:
|
|||||||
# Track notify calls
|
# Track notify calls
|
||||||
notify_calls = []
|
notify_calls = []
|
||||||
original_notify = worker.notify
|
original_notify = worker.notify
|
||||||
|
|
||||||
def tracking_notify():
|
def tracking_notify():
|
||||||
notify_calls.append(time.monotonic())
|
notify_calls.append(time.monotonic())
|
||||||
original_notify()
|
original_notify()
|
||||||
|
|
||||||
worker.notify = tracking_notify
|
worker.notify = tracking_notify
|
||||||
|
|
||||||
# Mock poller.select to exit after first iteration
|
# Mock poller.select to exit after first iteration
|
||||||
call_count = [0]
|
call_count = [0]
|
||||||
|
|
||||||
def mock_select(timeout):
|
def mock_select(timeout):
|
||||||
call_count[0] += 1
|
call_count[0] += 1
|
||||||
if call_count[0] > 1:
|
if call_count[0] > 1:
|
||||||
worker.alive = False
|
worker.alive = False
|
||||||
return []
|
return []
|
||||||
|
|
||||||
worker.poller.select.side_effect = mock_select
|
worker.poller.select.side_effect = mock_select
|
||||||
|
|
||||||
# Mock is_parent_alive to return True
|
# Mock is_parent_alive to return True
|
||||||
@ -1010,6 +1009,7 @@ class TestSignalHandling:
|
|||||||
|
|
||||||
# Track iterations
|
# Track iterations
|
||||||
iterations = [0]
|
iterations = [0]
|
||||||
|
|
||||||
def mock_select(timeout):
|
def mock_select(timeout):
|
||||||
iterations[0] += 1
|
iterations[0] += 1
|
||||||
if iterations[0] == 1:
|
if iterations[0] == 1:
|
||||||
@ -1022,6 +1022,7 @@ class TestSignalHandling:
|
|||||||
# Connection finishes
|
# Connection finishes
|
||||||
worker.nr_conns = 0
|
worker.nr_conns = 0
|
||||||
return []
|
return []
|
||||||
|
|
||||||
worker.poller.select.side_effect = mock_select
|
worker.poller.select.side_effect = mock_select
|
||||||
worker.is_parent_alive = mock.Mock(return_value=True)
|
worker.is_parent_alive = mock.Mock(return_value=True)
|
||||||
|
|
||||||
@ -1096,9 +1097,11 @@ class TestWorkerArbiterIntegration:
|
|||||||
worker.ppid = 99999999 # Invalid ppid
|
worker.ppid = 99999999 # Invalid ppid
|
||||||
|
|
||||||
iterations = [0]
|
iterations = [0]
|
||||||
|
|
||||||
def mock_select(timeout):
|
def mock_select(timeout):
|
||||||
iterations[0] += 1
|
iterations[0] += 1
|
||||||
return []
|
return []
|
||||||
|
|
||||||
worker.poller.select.side_effect = mock_select
|
worker.poller.select.side_effect = mock_select
|
||||||
|
|
||||||
worker.run()
|
worker.run()
|
||||||
@ -1349,6 +1352,7 @@ class TestFinishBodySSL:
|
|||||||
|
|
||||||
# Create a mock message body that returns data then raises SSLWantReadError
|
# Create a mock message body that returns data then raises SSLWantReadError
|
||||||
call_count = [0]
|
call_count = [0]
|
||||||
|
|
||||||
def mock_read(size):
|
def mock_read(size):
|
||||||
call_count[0] += 1
|
call_count[0] += 1
|
||||||
if call_count[0] <= 2:
|
if call_count[0] <= 2:
|
||||||
|
|||||||
6
tox.ini
6
tox.ini
@ -33,6 +33,7 @@ commands =
|
|||||||
gunicorn \
|
gunicorn \
|
||||||
tests/test_arbiter.py \
|
tests/test_arbiter.py \
|
||||||
tests/test_config.py \
|
tests/test_config.py \
|
||||||
|
tests/test_gthread.py \
|
||||||
tests/test_http.py \
|
tests/test_http.py \
|
||||||
tests/test_invalid_requests.py \
|
tests/test_invalid_requests.py \
|
||||||
tests/test_logger.py \
|
tests/test_logger.py \
|
||||||
@ -48,16 +49,11 @@ deps =
|
|||||||
|
|
||||||
[testenv:docs-lint]
|
[testenv:docs-lint]
|
||||||
no_package = true
|
no_package = true
|
||||||
allowlist_externals =
|
|
||||||
rst-lint
|
|
||||||
bash
|
|
||||||
grep
|
|
||||||
deps =
|
deps =
|
||||||
restructuredtext_lint
|
restructuredtext_lint
|
||||||
pygments
|
pygments
|
||||||
commands =
|
commands =
|
||||||
rst-lint README.rst docs/README.rst
|
rst-lint README.rst docs/README.rst
|
||||||
bash -c "(set -o pipefail; rst-lint --encoding utf-8 docs/source/*.rst | grep -v 'Unknown interpreted text role\|Unknown directive type'); test $? == 1"
|
|
||||||
|
|
||||||
[testenv:pycodestyle]
|
[testenv:pycodestyle]
|
||||||
no_package = true
|
no_package = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user