Make text files default to ASCII, as on a Windows or C-locale machine. The platform default decides how ``open()`` and ``os.fdopen()`` treat a text file when no encoding is given. Python reads it from the OS, so the tests stand in for it by filling it in when a caller leaves it out.
(monkeypatch)
| 219 | |
| 220 | @pytest.fixture |
| 221 | def ascii_default_encoding(monkeypatch): |
| 222 | """Make text files default to ASCII, as on a Windows or C-locale machine. |
| 223 | |
| 224 | The platform default decides how ``open()`` and ``os.fdopen()`` treat a text |
| 225 | file when no encoding is given. Python reads it from the OS, so the tests |
| 226 | stand in for it by filling it in when a caller leaves it out. |
| 227 | """ |
| 228 | real_open = open |
| 229 | real_fdopen = os.fdopen |
| 230 | |
| 231 | def default_ascii(real): |
| 232 | def wrapper(*args, **kwargs): |
| 233 | mode = args[1] if len(args) > 1 else kwargs.get("mode", "r") |
| 234 | if "b" not in mode: |
| 235 | kwargs.setdefault("encoding", "ascii") |
| 236 | return real(*args, **kwargs) |
| 237 | |
| 238 | return wrapper |
| 239 | |
| 240 | monkeypatch.setattr("builtins.open", default_ascii(real_open)) |
| 241 | monkeypatch.setattr(os, "fdopen", default_ascii(real_fdopen)) |
| 242 | |
| 243 | |
| 244 | def test_load_env_vars_reads_a_utf8_env_file(tmp_path, ascii_default_encoding): |
nothing calls this directly
no test coverage detected