Files
youknowdot 75e77c30e3 Update ten leaf stdlib modules to Python 3.15 (#9208)
* Update ten leaf standard-library modules to Python 3.15

Migrate mail, TOML, zoneinfo and CLI leaves in dependency order with canonical tests and preserved RustPython guards.

Assisted-by: OpenAI Codex:model version unavailable

* Defer warning initialization for lazy standard-library imports

Match CPython startup option processing and load the Python display helper on the first native warning.

Assisted-by: OpenAI Codex:model version unavailable

* Update the canonical webbrowser consumer for argparse colors

Copy the complete pinned CPython 3.15 webbrowser module and tests via update_lib. The canonical CLI test disables coloring while preserving all assertions. This consumer overlaps the pending HTTP/doc split #9193.

Assisted-by: OpenAI Codex:model version unavailable
2026-10-19 20:31:03 +09:00

48 lines
1.6 KiB
Python
Vendored

# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021 Taneli Hukkinen
# Licensed to PSF under a Contributor Agreement.
import json
from pathlib import Path
import unittest
from . import burntsushi, tomllib
DATA_DIR = Path(__file__).parent / "data"
VALID_FILES = tuple((DATA_DIR / "valid").glob("**/*.toml"))
assert VALID_FILES, "Valid TOML test files not found"
_expected_files = []
for p in VALID_FILES:
json_path = p.with_suffix(".json")
text = json.loads(json_path.read_bytes().decode())
_expected_files.append(text)
VALID_FILES_EXPECTED = tuple(_expected_files)
INVALID_FILES = tuple((DATA_DIR / "invalid").glob("**/*.toml"))
assert INVALID_FILES, "Invalid TOML test files not found"
class TestData(unittest.TestCase):
def test_invalid(self):
for invalid in INVALID_FILES:
with self.subTest(msg=invalid.stem):
toml_bytes = invalid.read_bytes()
try:
toml_str = toml_bytes.decode()
except UnicodeDecodeError:
# Some BurntSushi tests are not valid UTF-8. Skip those.
continue
with self.assertRaises(tomllib.TOMLDecodeError):
tomllib.loads(toml_str)
def test_valid(self):
for valid, expected in zip(VALID_FILES, VALID_FILES_EXPECTED):
with self.subTest(msg=valid.stem):
toml_str = valid.read_bytes().decode()
actual = tomllib.loads(toml_str)
actual = burntsushi.convert(actual)
expected = burntsushi.normalize(expected)
self.assertEqual(actual, expected)