Skip to content

fix(test): make //tests/mappings/filter_directory work on Windows#1020

Merged
aiuto merged 1 commit intobazelbuild:mainfrom
rdesgroppes:fix-tests-mappings-filter_directory-on-windows
Feb 10, 2026
Merged

fix(test): make //tests/mappings/filter_directory work on Windows#1020
aiuto merged 1 commit intobazelbuild:mainfrom
rdesgroppes:fix-tests-mappings-filter_directory-on-windows

Conversation

@rdesgroppes
Copy link
Contributor

The filter_directory tests were failing on Windows:

ERROR: test_directory_structure_matches_global (__main__.DirectoryStructureTest.test_directory_structure_matches_global)
[...]
    os.path.isdir(real_directory_root),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[...]
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

This was because Rlocation() expects POSIX-style paths (forward slashes), but os.path.join() produces backslashes on Windows.

After fixing it, a second error appeared:

FAIL: test_directory_structure_matches_global (__main__.DirectoryStructureTest.test_directory_structure_matches_global)
AssertionError: Items in the first set but not the second:
'extra/a'
'extra/subdir/c'
'extra/b'
'extra/subdir/d'
Items in the second set but not the first:
'extra\\subdir\\c'
'extra\\a'
'extra\\b'
'extra\\subdir\\d' : Directory structure mismatch

This was because paths collected via os.walk() also produce backslashes on Windows against expected paths returned by Rlocation that always use forward slashes.

The change consists in leveraging pathlib for that purpose: Path().as_posix(), Path.rglob() and Path.relative_to().

This enables the 9 filter_directory tests in Windows CI.

The `filter_directory` tests were failing on Windows:
```
ERROR: test_directory_structure_matches_global (__main__.DirectoryStructureTest.test_directory_structure_matches_global)
[...]
    os.path.isdir(real_directory_root),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[...]
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
```

This was because `Rlocation()` expects POSIX-style paths (forward
slashes), but `os.path.join()` produces backslashes on Windows.

After fixing it, a second error appeared:
```
FAIL: test_directory_structure_matches_global (__main__.DirectoryStructureTest.test_directory_structure_matches_global)
AssertionError: Items in the first set but not the second:
'extra/a'
'extra/subdir/c'
'extra/b'
'extra/subdir/d'
Items in the second set but not the first:
'extra\\subdir\\c'
'extra\\a'
'extra\\b'
'extra\\subdir\\d' : Directory structure mismatch
```

This was because paths collected via `os.walk()` also produce
backslashes on Windows against expected paths returned by `Rlocation`
that always use forward slashes.

The change consists in leveraging `pathlib` for that purpose:
`Path().as_posix()`, `Path.rglob()` and `Path.relative_to()`.

This enables the 9 `filter_directory` tests in Windows CI.
@rdesgroppes rdesgroppes marked this pull request as ready for review February 8, 2026 07:41
@aiuto aiuto merged commit 2bd9281 into bazelbuild:main Feb 10, 2026
6 checks passed
@rdesgroppes rdesgroppes deleted the fix-tests-mappings-filter_directory-on-windows branch February 10, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants