Skip to content

Commit 5800927

Browse files
committed
Fix test to handle Windows path separators with pathlib
Use pathlib.Path().as_posix() for cross-platform path comparison. This handles both Unix (/) and Windows (\) path separators correctly by normalizing both sides of the comparison. Also update CLAUDE.md to document preference for pathlib over os.path for path operations in tests and new code.
1 parent 733ecf2 commit 5800927

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ myext-package_setting = value
393393
- **Formatting**: Black-compatible (max line length: 120)
394394
- **Import sorting**: isort with `force_alphabetical_sort = true`, `force_single_line = true`
395395
- **Type hints**: Use throughout (Python 3.8+ compatible)
396+
- **Path handling**: Prefer `pathlib.Path` over `os.path` for path operations
397+
- Use `pathlib.Path().as_posix()` for cross-platform path comparison
398+
- Use `/` operator for path joining: `Path("dir") / "file.txt"`
399+
- Only use `os.path.join()` in production code where needed for compatibility
396400
- **Logging**: Use `logger = logging.getLogger("mxdev")` from [logging.py](src/mxdev/logging.py)
397401
- **Docstrings**: Document public APIs and complex logic
398402

tests/test_config.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,30 @@ def test_per_package_target_override():
201201
# Package without custom target should use default-target
202202
pkg_default = config.packages["package.with.default.target"]
203203
assert pkg_default["target"] == "./sources"
204-
assert pkg_default["path"] == "./sources/package.with.default.target"
204+
# Normalize paths for comparison (handles both Unix / and Windows \)
205+
assert (
206+
pathlib.Path(pkg_default["path"]).as_posix()
207+
== pathlib.Path(pkg_default["target"])
208+
.joinpath("package.with.default.target")
209+
.as_posix()
210+
)
205211

206212
# Package with custom target should use its own target
207213
pkg_custom = config.packages["package.with.custom.target"]
208214
assert pkg_custom["target"] == "custom-dir"
209-
# BUG: This will fail because config.py uses wrong variable at line 103
210-
assert pkg_custom["path"] == "custom-dir/package.with.custom.target"
215+
assert (
216+
pathlib.Path(pkg_custom["path"]).as_posix()
217+
== pathlib.Path(pkg_custom["target"])
218+
.joinpath("package.with.custom.target")
219+
.as_posix()
220+
)
211221

212222
# Package with interpolated target should use the interpolated value
213223
pkg_interpolated = config.packages["package.with.interpolated.target"]
214224
assert pkg_interpolated["target"] == "documentation"
215-
# BUG: This will also fail for the same reason
216-
assert pkg_interpolated["path"] == "documentation/package.with.interpolated.target"
225+
assert (
226+
pathlib.Path(pkg_interpolated["path"]).as_posix()
227+
== pathlib.Path(pkg_interpolated["target"])
228+
.joinpath("package.with.interpolated.target")
229+
.as_posix()
230+
)

0 commit comments

Comments
 (0)