MCPcopy Create free account
hub / github.com/crewAIInc/crewAI / ascii_default_encoding

Function ascii_default_encoding

lib/cli/tests/test_utils.py:221–241  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

219
220@pytest.fixture
221def 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
244def test_load_env_vars_reads_a_utf8_env_file(tmp_path, ascii_default_encoding):

Callers

nothing calls this directly

Calls 1

default_asciiFunction · 0.85

Tested by

no test coverage detected