Skip to content

Commit 86dcf31

Browse files
thomas-manginclaude
andcommitted
fix: Normalize repo paths in configuration export test
The expected JSON fixture contained hardcoded absolute paths, causing test failures on different machines. Normalize repo root paths before comparison for portability. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5f08dd8 commit 86dcf31

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/unit/configuration/test_configuration_export.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import json
9+
import re
910
import pytest
1011
from pathlib import Path
1112

@@ -18,6 +19,14 @@
1819
# Directory containing ExaBGP example configs
1920
CONFIG_DIR = Path(__file__).parent.parent.parent.parent / 'etc' / 'exabgp'
2021

22+
# Pattern matching absolute paths to the exabgp repo root
23+
_REPO_PATH_RE = re.compile(r'(?<=")/[^"]*?(?=/etc/exabgp/)')
24+
25+
26+
def _normalize_repo_paths(text: str) -> str:
27+
"""Replace absolute repo paths with a placeholder for portable comparison."""
28+
return _REPO_PATH_RE.sub('<REPO>', text)
29+
2130

2231
def get_config_fixtures() -> list[tuple[Path, Path]]:
2332
"""Find all config files with matching expected JSON."""
@@ -48,8 +57,8 @@ def test_configuration_export_matches_expected(conf_file: Path, expected_file: P
4857
expected = json.load(f)
4958
expected_json = json.dumps(expected, sort_keys=True, indent=2)
5059

51-
# Compare
52-
assert actual_json == expected_json, (
60+
# Compare (normalize absolute repo paths for portability)
61+
assert _normalize_repo_paths(actual_json) == _normalize_repo_paths(expected_json), (
5362
f'Configuration mismatch for {conf_file.name}\n'
5463
f'Run: ./sbin/exabgp configuration export {conf_file} > {expected_file}\n'
5564
f'to update expected output'

0 commit comments

Comments
 (0)