Repository navigation
ci: add Python 3.14 unit and framework smoke-test coverage #133
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
10a4393
ci: test Python 3.14 and exercise framework smoke tests
suppagoddo 35de141
ci: collect results from all Python and backend matrix jobs
suppagoddo 48b9b9d
fix(smoketest): let Quart create its event loop on Python 3.14
suppagoddo 5da967a
ci: exercise Python 3.14 with supported Sanic dependency
suppagoddo 4042c8c
fix(sanic): tolerate missing format keys in modern logging defaults
suppagoddo a70f63b
docs: reflect Python 3.14 CI coverage
suppagoddo 17b4098
docs: align maintenance guide with Python 3.14 matrix
suppagoddo 382202c
test(sanic): guard JSON formatter compatibility across logging config…
suppagoddo 1402278
test: correct subprocess script interpolation
suppagoddo 2b29ec2
test(sanic): instantiate the formatter selected by Sanic config
suppagoddo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| sanic==20.3.0 | ||
| # Preserve coverage of the legacy Sanic integration on Python 3.9. | ||
| sanic==20.3.0; python_version < "3.10" | ||
| # Sanic 25.12+ supports Python 3.14; 20.3.0 pulls in httpx importing removed cgi. | ||
| sanic>=25.12,<26; python_version >= "3.10" | ||
| requests | ||
| pytest | ||
| -e . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """Regression tests for Sanic default logging formatter compatibility. | ||
|
|
||
| Sanic 24+ removes the legacy 'format' keys from generic/access formatters. | ||
| Run each initialization in a fresh Python process because json_logging.init_sanic() | ||
| changes process-global state and intentionally cannot be called twice. | ||
| """ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import textwrap | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("config_shape", ["legacy", "modern", "installed"]) | ||
| def test_init_sanic_handles_logging_formats_and_emits_json(config_shape): | ||
| """Both old and new Sanic config shapes initialize and produce parseable JSON records.""" | ||
| code = textwrap.dedent(""" | ||
| import io | ||
| import json | ||
| import logging | ||
| import sanic.log | ||
| import json_logging | ||
|
|
||
| config_shape = %(config_shape)r | ||
| if config_shape != "installed": | ||
| formatters = { | ||
| "generic": {"format": "%%(message)s"} if config_shape == "legacy" else {}, | ||
| "access": {"format": "%%(message)s"} if config_shape == "legacy" else {}, | ||
| } | ||
| sanic.log.LOGGING_CONFIG_DEFAULTS = { | ||
| "disable_existing_loggers": True, | ||
| "formatters": formatters, | ||
| } | ||
|
|
||
| json_logging.init_sanic(enable_json=True) | ||
| defaults = sanic.log.LOGGING_CONFIG_DEFAULTS | ||
| assert defaults["disable_existing_loggers"] is False | ||
| logger = logging.getLogger("sanic-formatter-test") | ||
| logger.setLevel(logging.INFO) | ||
| logger.propagate = False | ||
|
|
||
| for name in ("generic", "access"): | ||
| formatter_config = defaults["formatters"][name] | ||
| assert formatter_config["class"] == "json_logging.JSONLogFormatter" | ||
| assert "format" not in formatter_config | ||
|
|
||
| output = io.StringIO() | ||
| handler = logging.StreamHandler(output) | ||
| formatter_class = getattr(json_logging, formatter_config["class"].rsplit(".", 1)[-1]) | ||
| handler.setFormatter(formatter_class()) | ||
| logger.addHandler(handler) | ||
| try: | ||
| logger.info("sanic json logging", extra={"service": name}) | ||
| finally: | ||
| logger.removeHandler(handler) | ||
| handler.close() | ||
| record = json.loads(output.getvalue().strip()) | ||
| assert record["type"] == "log" | ||
| assert record["msg"] == "sanic json logging" | ||
| assert record["service"] == name | ||
| print("PASS") | ||
| """ % {"config_shape": config_shape}) | ||
| env = dict(os.environ, PYTHONWARNINGS="ignore") | ||
| result = subprocess.run( | ||
| [sys.executable, "-c", code], cwd=str(ROOT), env=env, | ||
| capture_output=True, text=True, timeout=40, | ||
| ) | ||
| assert result.returncode == 0, result.stdout + result.stderr | ||
| assert "PASS" in result.stdout |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.