Test issue fix, had problems on zerodev1 which ChatGPT helped me finesse. This is the fix Codex was instructed to make
This commit is contained in:
parent
387cd1c57d
commit
aa2b5d3fcd
1 changed files with 39 additions and 2 deletions
|
|
@ -62,14 +62,35 @@ print(json.dumps({
|
|||
"""
|
||||
|
||||
|
||||
def _pythonpath_entry_path(entry):
|
||||
if not entry:
|
||||
# Empty PYTHONPATH entries mean the subprocess cwd.
|
||||
return os.path.realpath(REPO_ROOT)
|
||||
if os.path.isabs(entry):
|
||||
return os.path.realpath(entry)
|
||||
return os.path.realpath(os.path.join(REPO_ROOT, entry))
|
||||
|
||||
|
||||
def _is_cpp_backend_path(entry):
|
||||
path = _pythonpath_entry_path(entry)
|
||||
cpp_dir = os.path.realpath(CPP_BUILD_DIR)
|
||||
return path == cpp_dir or path.startswith(cpp_dir + os.sep)
|
||||
|
||||
|
||||
def _parent_pythonpath_entries(include_cpp):
|
||||
entries = os.environ.get("PYTHONPATH", "").split(os.pathsep)
|
||||
if include_cpp:
|
||||
return [entry for entry in entries if entry]
|
||||
return [entry for entry in entries if entry and not _is_cpp_backend_path(entry)]
|
||||
|
||||
|
||||
def run_probe(backend, include_cpp):
|
||||
env = os.environ.copy()
|
||||
env["BLE_RETICULUM_FRAGMENTATION_BACKEND"] = backend
|
||||
pythonpath = [SRC_DIR]
|
||||
if include_cpp:
|
||||
pythonpath.append(CPP_BUILD_DIR)
|
||||
if env.get("PYTHONPATH"):
|
||||
pythonpath.append(env["PYTHONPATH"])
|
||||
pythonpath.extend(_parent_pythonpath_entries(include_cpp))
|
||||
env["PYTHONPATH"] = os.pathsep.join(pythonpath)
|
||||
|
||||
completed = subprocess.run(
|
||||
|
|
@ -105,6 +126,22 @@ def test_python_backend_still_works_when_cpp_backend_is_unavailable():
|
|||
assert result["deframed"] == "616263"
|
||||
|
||||
|
||||
def test_include_cpp_false_filters_parent_pythonpath(monkeypatch):
|
||||
parent_pythonpath = os.pathsep.join(
|
||||
[
|
||||
"migration/protocol_core",
|
||||
SRC_DIR,
|
||||
os.path.join(CPP_BUILD_DIR, "build", "lib.fake-platform"),
|
||||
]
|
||||
)
|
||||
monkeypatch.setenv("PYTHONPATH", parent_pythonpath)
|
||||
|
||||
result = run_probe("auto", include_cpp=False)
|
||||
|
||||
assert result["backend"] == "python"
|
||||
assert result["fragmenter_module"] == "ble_reticulum.BLEFragmentation"
|
||||
|
||||
|
||||
def test_auto_backend_prefers_cpp_when_available():
|
||||
result = run_probe("auto", include_cpp=True)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue