|
7 | 7 | """ |
8 | 8 | from __future__ import annotations |
9 | 9 |
|
| 10 | +import io |
10 | 11 | import os |
11 | 12 | import runpy |
12 | 13 | import shutil |
@@ -117,9 +118,31 @@ def test_writes_imghdr_compat_module(self, tmp_path): |
117 | 118 |
|
118 | 119 | content = (output_dir / "imghdr.py").read_text(encoding="utf-8") |
119 | 120 | assert "tests = []" in content |
| 121 | + assert "stdlib imghdr extension hook" in content |
120 | 122 | assert "def what" in content |
121 | 123 | assert "jpeg" in content |
122 | 124 |
|
| 125 | + def test_imghdr_compat_module_detects_sphinx_image_formats(self, tmp_path): |
| 126 | + output_dir = tmp_path / "compat" |
| 127 | + write_sphinx_json_sitecustomize(output_dir) |
| 128 | + namespace = runpy.run_path(str(output_dir / "imghdr.py")) |
| 129 | + |
| 130 | + what = namespace["what"] |
| 131 | + |
| 132 | + assert what(io.BytesIO(b"\xff\xd8\xff\xe0")) == "jpeg" |
| 133 | + assert what(io.BytesIO(b"\x89PNG\r\n\x1a\nextra")) == "png" |
| 134 | + assert what(io.BytesIO(b"GIF89aextra")) == "gif" |
| 135 | + |
| 136 | + def test_imghdr_compat_module_preserves_tests_hook(self, tmp_path): |
| 137 | + output_dir = tmp_path / "compat" |
| 138 | + write_sphinx_json_sitecustomize(output_dir) |
| 139 | + namespace = runpy.run_path(str(output_dir / "imghdr.py")) |
| 140 | + |
| 141 | + tests = namespace["tests"] |
| 142 | + tests.append(lambda header, _file: "bmp" if header.startswith(b"BM") else None) |
| 143 | + |
| 144 | + assert namespace["what"](io.BytesIO(b"BMfake")) == "bmp" |
| 145 | + |
123 | 146 | def test_translation_proxy_patch_stringifies_proxy_objects( |
124 | 147 | self, tmp_path, monkeypatch |
125 | 148 | ): |
@@ -180,6 +203,16 @@ def test_bootstrap_requirements_include_setuptools_before_sphinx(self): |
180 | 203 |
|
181 | 204 | assert requirements == ["setuptools<70", "sphinx==3.4.3"] |
182 | 205 |
|
| 206 | + def test_bootstrap_requirements_include_setuptools_for_sphinx_4(self): |
| 207 | + requirements = build_sphinx_bootstrap_requirements("Sphinx < 5") |
| 208 | + |
| 209 | + assert requirements == ["setuptools<70", "Sphinx < 5"] |
| 210 | + |
| 211 | + def test_bootstrap_requirements_skip_setuptools_for_modern_sphinx(self): |
| 212 | + requirements = build_sphinx_bootstrap_requirements("sphinx~=8.2.0") |
| 213 | + |
| 214 | + assert requirements == ["sphinx~=8.2.0"] |
| 215 | + |
183 | 216 | def test_build_command_uses_json_builder_and_classic_theme(self, tmp_path): |
184 | 217 | sphinx_build = tmp_path / "bin" / "sphinx-build" |
185 | 218 | doc_dir = tmp_path / "cpython" / "Doc" |
|
0 commit comments