|
6 | 6 | from io import StringIO |
7 | 7 | import os |
8 | 8 | from pathlib import Path |
| 9 | +import subprocess |
| 10 | +import sys |
9 | 11 | from threading import Event |
10 | 12 | from types import SimpleNamespace |
11 | 13 | from typing import Any, Literal, cast |
@@ -134,7 +136,7 @@ def __init__(self, files: dict[str, str], path: str | None = None) -> None: |
134 | 136 | def joinpath(self, path: str) -> 'FakeResourceTree': |
135 | 137 | return FakeResourceTree(self.files, path) |
136 | 138 |
|
137 | | - def open(self, mode: str) -> StringIO: |
| 139 | + def open(self, mode: str, encoding: str | None = None) -> StringIO: |
138 | 140 | assert self.path is not None |
139 | 141 | if self.path not in self.files: |
140 | 142 | raise FileNotFoundError(self.path) |
@@ -820,6 +822,23 @@ def test_repl_picker_helpers_cover_present_and_missing_resources(monkeypatch: py |
820 | 822 | assert repl_mode._tips_picker() == r'/? or /help for help!' |
821 | 823 |
|
822 | 824 |
|
| 825 | +def test_repl_picker_helpers_do_not_use_locale_encoding() -> None: |
| 826 | + # EncodingWarning is raised for any open() that falls back to the locale encoding. |
| 827 | + script = '\n'.join(( |
| 828 | + 'from mycli.main_modes import repl', |
| 829 | + 'repl._contributors_picker()', |
| 830 | + 'repl._sponsors_picker()', |
| 831 | + 'repl._tips_picker()', |
| 832 | + )) |
| 833 | + result = subprocess.run( |
| 834 | + [sys.executable, '-X', 'warn_default_encoding', '-W', 'error::EncodingWarning', '-c', script], |
| 835 | + capture_output=True, |
| 836 | + encoding='utf8', |
| 837 | + errors='replace', |
| 838 | + ) |
| 839 | + assert result.returncode == 0, result.stderr |
| 840 | + |
| 841 | + |
823 | 842 | def test_configure_editor_uses_configured_editor(monkeypatch: pytest.MonkeyPatch) -> None: |
824 | 843 | cli = make_repl_cli() |
825 | 844 | cli.config['editor']['editor_command'] = 'nano' |
|
0 commit comments