import ast from pathlib import Path MODULE = Path(__file__).parents[1] / "netbox_site_prefix" / "tables.py" def _load_first_word(): """Load the pure helper without requiring a local NetBox installation.""" module = ast.parse(MODULE.read_text(encoding="utf-8")) function = next( node for node in module.body if isinstance(node, ast.FunctionDef) and node.name == "first_word" ) namespace = {} exec(compile(ast.Module(body=[function], type_ignores=[]), str(MODULE), "exec"), namespace) return namespace["first_word"] def test_first_word(): first_word = _load_first_word() assert first_word("Berlin Campus West") == "Berlin" assert first_word(" DC01\tFrankfurt ") == "DC01" def test_first_word_handles_missing_or_blank_value(): first_word = _load_first_word() assert first_word(None) is None assert first_word(" ") is None