← Commit list

b6bf15bf5c

Dan Fandrich
Dan Fandrich
2026-08-29
SUCCESS Duration: 394s

Subject

tests: enable and fix some new Python ruff warnings

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

scripts/pythonlint.sh+9 -5
@@ -30,10 +30,14 @@
set -eu
ruff check --target-version=py38 \
---extend-select=B007,B016,C405,C416,COM818,D200,D213,D204,D401,\
+ --extend-select=B007,B016,C405,C416,COM818,D200,D213,D204,D401,\
D415,FURB129,N818,PERF401,PERF403,PIE790,PIE808,PLW0127,Q004,RUF010,SIM101,\
-SIM117,SIM118,TRY400,TRY401,RET503,RET504,UP004,B018,B904,RSE102,RET505,I001 \
---ignore=FA100 \
-"$@"
+SIM110,SIM117,SIM118,TRY400,TRY401,RET503,RET504,UP004,B018,B904,RSE102,RET505,\
+I001,PERF102,C419 \
+ --ignore=FA100 \
+ "$@"
# Checks that are in preview only, since --preview otherwise turns them all on
-ruff check --target-version=py38 --preview --select=E301,E302,E303,E304,E305,E306,E502 "$@"
+ruff check --target-version=py38 --preview \
+ --select=E301,E302,E303,E304,E305,E306,E502,FURB110,FURB113,FURB156,FURB171 \
+ --ignore=RUF027 \
+ "$@"
tests/http/scorecard.py+10 -10
@@ -196,7 +196,7 @@ class Card:
errors = []
col_has_stats = []
for idx, col in enumerate(cols):
- cellw = max([len(r[idx]["sval"]) for r in rows])
+ cellw = max(len(r[idx]["sval"]) for r in rows)
colw.append(max(cellw, len(col)))
col_has_stats.append(False)
for row in rows:
@@ -369,11 +369,11 @@ class ScoreRunner:
if err:
errors.append(err)
elif self._limit_rate:
- total_speed = sum([s['speed_download'] for s in r.stats])
+ total_speed = sum(s['speed_download'] for s in r.stats)
samples.append(total_speed / len(r.stats))
profiles.append(r.profile)
else:
- total_size = sum([s['size_download'] for s in r.stats])
+ total_size = sum(s['size_download'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
if self._limit_rate:
@@ -397,11 +397,11 @@ class ScoreRunner:
if err:
errors.append(err)
elif self._limit_rate:
- total_speed = sum([s['speed_download'] for s in r.stats])
+ total_speed = sum(s['speed_download'] for s in r.stats)
samples.append(total_speed / len(r.stats))
profiles.append(r.profile)
else:
- total_size = sum([s['size_download'] for s in r.stats])
+ total_size = sum(s['size_download'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
if self._limit_rate:
@@ -430,11 +430,11 @@ class ScoreRunner:
if err:
errors.append(err)
elif self._limit_rate:
- total_speed = sum([s['speed_download'] for s in r.stats])
+ total_speed = sum(s['speed_download'] for s in r.stats)
samples.append(total_speed / len(r.stats))
profiles.append(r.profile)
else:
- total_size = sum([s['size_download'] for s in r.stats])
+ total_size = sum(s['size_download'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
if self._limit_rate:
@@ -513,7 +513,7 @@ class ScoreRunner:
if err:
errors.append(err)
else:
- total_size = sum([s['size_upload'] for s in r.stats])
+ total_size = sum(s['size_upload'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
return Card.mk_mbs_cell(samples, profiles, errors)
@@ -533,7 +533,7 @@ class ScoreRunner:
if err:
errors.append(err)
else:
- total_size = sum([s['size_upload'] for s in r.stats])
+ total_size = sum(s['size_upload'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
return Card.mk_mbs_cell(samples, profiles, errors)
@@ -558,7 +558,7 @@ class ScoreRunner:
if err:
errors.append(err)
else:
- total_size = sum([s['size_upload'] for s in r.stats])
+ total_size = sum(s['size_upload'] for s in r.stats)
samples.append(total_size / r.duration.total_seconds())
profiles.append(r.profile)
return Card.mk_mbs_cell(samples, profiles, errors)
tests/http/test_07_upload.py+7 -6
@@ -27,6 +27,7 @@ import filecmp
import logging
import os
import re
+import string
import sys
from typing import List, Union
@@ -50,7 +51,7 @@ class TestUpload:
# upload small data, check that this is what was echoed
@pytest.mark.parametrize("proto", Env.http_protos())
def test_07_01_upload_1_small(self, env: Env, httpd, nghttpx, proto):
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto)
@@ -76,7 +77,7 @@ class TestUpload:
@pytest.mark.parametrize("proto", Env.http_protos())
def test_07_10_upload_sequential(self, env: Env, httpd, nghttpx, proto):
count = 20
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto)
@@ -91,7 +92,7 @@ class TestUpload:
def test_07_11_upload_parallel(self, env: Env, httpd, nghttpx, proto):
# limit since we use a separate connection in h1
count = 20
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
@@ -198,7 +199,7 @@ class TestUpload:
def test_07_20_upload_parallel(self, env: Env, httpd, nghttpx, proto):
# limit since we use a separate connection in h1
count = 10
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
@@ -372,7 +373,7 @@ class TestUpload:
def test_07_36_upload_30x(self, env: Env, httpd, nghttpx, redir, proto):
if proto == 'h3' and env.curl_uses_ossl_quic():
pytest.skip("OpenSSL's own QUIC is flaky here")
- data = '0123456789' * 10
+ data = string.digits * 10
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo{redir}?id=[0-0]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
@@ -388,7 +389,7 @@ class TestUpload:
def test_07_37_upload_307(self, env: Env, httpd, nghttpx, proto):
if proto == 'h3' and env.curl_uses_ossl_quic():
pytest.skip("OpenSSL's own QUIC is flaky here")
- data = '0123456789' * 10
+ data = string.digits * 10
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo307?id=[0-0]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
tests/http/test_08_caddy.py+2 -1
@@ -27,6 +27,7 @@ import filecmp
import logging
import os
import re
+import string
import pytest
from testenv import Caddy, CurlClient, Env, LocalClient
@@ -142,7 +143,7 @@ class TestCaddy:
def test_08_06_post_parallel(self, env: Env, httpd, caddy, proto):
# limit since we use a separate connection in h1
count = 20
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.domain2}:{caddy.port}/curltest/echo?id=[0-{count-1}]'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
tests/http/test_14_auth.py+3 -2
@@ -24,6 +24,7 @@
#
import logging
import os
+import string
import pytest
from testenv import CurlClient, Env
@@ -62,7 +63,7 @@ class TestAuth:
def test_14_03_digest_put_auth(self, env: Env, httpd, nghttpx, proto):
if not env.curl_has_feature('digest'):
pytest.skip("curl built without digest")
- data = '0123456789'
+ data = string.digits
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
@@ -75,7 +76,7 @@ class TestAuth:
def test_14_04_digest_large_pw(self, env: Env, httpd, nghttpx, proto):
if not env.curl_has_feature('digest'):
pytest.skip("curl built without digest")
- data = '0123456789'
+ data = string.digits
password = 'x' * 65535
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
tests/http/test_17_ssl_use.py+1 -1
@@ -143,7 +143,7 @@ class TestSSLUse:
assert r.json['SSL_TLS_SNI'] == env.domain1, f'{r.json}'
assert False, f'should not have succeeded: {r.json}'
# 3 - not allowed in the URL
- assert r.exit_code in [3], f'{r}'
+ assert r.exit_code == 3, f'{r}'
# use ip address for connect
@pytest.mark.parametrize("proto", Env.http_protos())
tests/http/testenv/certs.py+1 -1
@@ -224,7 +224,7 @@ class Credentials:
def issue_cert(self, spec: CertificateSpec,
chain: Optional[List['Credentials']] = None) -> 'Credentials':
- key_type = spec.key_type if spec.key_type else self.key_type
+ key_type = spec.key_type or self.key_type
creds = None
if self._store:
creds = self._store.load_credentials(
tests/http/testenv/client.py+2 -2
@@ -44,9 +44,9 @@ class LocalClient:
self.path = os.path.join(env.build_dir, 'tests/libtest/libtests')
self.env = env
self._run_env = run_env
- self._timeout = timeout if timeout else env.test_timeout
+ self._timeout = timeout or env.test_timeout
self._curl = os.environ.get('CURL', env.curl)
- self._run_dir = run_dir if run_dir else os.path.join(env.gen_dir, name)
+ self._run_dir = run_dir or os.path.join(env.gen_dir, name)
self._stdoutfile = f'{self._run_dir}/stdout'
self._stderrfile = f'{self._run_dir}/stderr'
self._rmrf(self._run_dir)
tests/http/testenv/curl.py+5 -5
@@ -100,7 +100,7 @@ class RunProfile:
self._stats = {}
for key in self.STAT_KEYS:
self._stats[key] = fmean([s[key] for s in self._samples], weights)
- self._stats['rss-max'] = max([s['rss'] for s in self._samples])
+ self._stats['rss-max'] = max(s['rss'] for s in self._samples)
else:
self._stats = None
self._psu = None
@@ -629,9 +629,9 @@ class CurlClient:
force_resolv: bool = True,
socks_args: Optional[List[str]] = None):
self.env = env
- self._timeout = timeout if timeout else env.test_timeout
+ self._timeout = timeout or env.test_timeout
self._curl = os.environ.get('CURL', env.curl)
- self._run_dir = run_dir if run_dir else os.path.join(env.gen_dir, 'curl')
+ self._run_dir = run_dir or os.path.join(env.gen_dir, 'curl')
self._stdoutfile = f'{self._run_dir}/curl.stdout'
self._stderrfile = f'{self._run_dir}/curl.stderr'
self._headerfile = f'{self._run_dir}/curl.headers'
@@ -655,7 +655,7 @@ class CurlClient:
self._socks_args = socks_args
self._silent = silent
self._run_env = run_env
- self._server_addr = server_addr if server_addr else '127.0.0.1'
+ self._server_addr = server_addr or '127.0.0.1'
self._force_resolv = force_resolv
self._rmrf(self._run_dir)
self._mkpath(self._run_dir)
@@ -1171,7 +1171,7 @@ class CurlClient:
if force_resolve and u.hostname and u.hostname != 'localhost' \
and not re.match(r'^(\d+|\[|:).*', u.hostname):
- port = u.port if u.port else 443
+ port = u.port or 443
args.extend([
'--resolve', f'{u.hostname}:{port}:{self._server_addr}',
])
tests/http/testenv/env.py+4 -6
@@ -27,6 +27,7 @@ import logging
import os
import re
import shutil
+import string
import subprocess
import tempfile
from configparser import ConfigParser, ExtendedInterpolation
@@ -493,10 +494,7 @@ class Env:
@staticmethod
def curl_uses_any_libs(libs: List[str]) -> bool:
- for libname in libs:
- if libname.lower() in Env.CONFIG.curl_props["libs"]:
- return True
- return False
+ return any(libname.lower() in Env.CONFIG.curl_props["libs"] for libname in libs)
@staticmethod
def curl_uses_ossl_quic() -> bool:
@@ -901,7 +899,7 @@ class Env:
"http/0.9",
]:
return self.https_port
- if alpn_proto in ["h3"]:
+ if alpn_proto == "h3":
return self.h3_port
return self.http_port
@@ -915,7 +913,7 @@ class Env:
raise RuntimeError("line_length less than 11 not supported")
os.makedirs(indir, exist_ok=True)
fpath = os.path.join(indir, fname)
- s10 = "0123456789"
+ s10 = string.digits
s = round((line_length / 10) + 1) * s10
s = s[0:line_length - 11]
with open(fpath, "w") as fd:
tests/http/testenv/h2o.py+5 -5
@@ -82,12 +82,12 @@ class H2o:
def dump_logs(self):
lines = []
- lines.append(f"stderr of {self._name}")
- lines.append("-------------------------------------------")
+ lines.extend([f"stderr of {self._name}",
+ "-------------------------------------------"])
self._dump_file(self._stderr, lines)
- lines.append("")
- lines.append(f"errorlog of {self._name}")
- lines.append("-------------------------------------------")
+ lines.extend(["",
+ f"errorlog of {self._name}",
+ "-------------------------------------------"])
self._dump_file(self._error_log, lines)
lines.append("")
return lines
tests/http/testenv/httpd.py+1 -1
@@ -314,7 +314,7 @@ class Httpd:
'AddEncoding x-gzip .gz .tgz .gzip',
'AddHandler type-map .var',
]
- conf.extend([f'Listen {port}' for _, port in self.ports.items()])
+ conf.extend([f'Listen {port}' for port in self.ports.values()])
if 'base' in self._extra_configs:
conf.extend(self._extra_configs['base'])
tests/smbserver.py+1 -1
@@ -304,7 +304,7 @@ class TestSmbServer(imp_smbserver.SMBSERVER):
def get_server_path(self, requested_filename):
log.debug("[SMB] Get server path '%s'", requested_filename)
- if requested_filename not in [VERIFIED_REQ]:
+ if requested_filename != VERIFIED_REQ:
raise SmbError(STATUS_NO_SUCH_FILE, "Could not find the file")
fid, filename = tempfile.mkstemp()