mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-11 13:43:37 +00:00
Keep importlib.metadata as the primary source for installed packages, but avoid PackageNotFoundError when nanobot is imported directly from a source tree. Made-with: Cursor
42 lines
990 B
Python
42 lines
990 B
Python
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
import tomllib
|
|
|
|
|
|
def test_source_checkout_import_uses_pyproject_version_without_metadata() -> None:
|
|
repo_root = Path(__file__).resolve().parents[1]
|
|
expected = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))["project"][
|
|
"version"
|
|
]
|
|
script = textwrap.dedent(
|
|
f"""
|
|
import sys
|
|
import types
|
|
|
|
sys.path.insert(0, {str(repo_root)!r})
|
|
fake = types.ModuleType("nanobot.nanobot")
|
|
fake.Nanobot = object
|
|
fake.RunResult = object
|
|
sys.modules["nanobot.nanobot"] = fake
|
|
|
|
import nanobot
|
|
|
|
print(nanobot.__version__)
|
|
"""
|
|
)
|
|
|
|
proc = subprocess.run(
|
|
[sys.executable, "-S", "-c", script],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
assert proc.returncode == 0, proc.stderr
|
|
assert proc.stdout.strip() == expected
|