pytest-dev / pyfakefs

Provides a fake file system that mocks the Python file system modules.
https://pytest-pyfakefs.readthedocs.io
Apache License 2.0
651 stars 91 forks source link

pyfakefs `PurePosixPath` reports Windows reserved names as reserved on Python3.12+ #1067

Closed lengau closed 1 month ago

lengau commented 1 month ago

Describe the bug Windows reserved paths are not reported as reserved in PureWindowsPath with Python 3.12+

How To Reproduce

import pathlib
import pyfakefs
import pytest

WINDOWS_RESERVED_NAMES = (
    "CON", "PRN", "AUX", "NUL",
    "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
    "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
)

@pytest.mark.parametrize(
    "reserved_name", WINDOWS_RESERVED_NAMES
)
def test_real_fs_com1(reserved_name):
    assert not pathlib.PurePosixPath(reserved_name).is_reserved()
    assert not pathlib.PurePosixPath(reserved_name + ".txt").is_reserved()

@pytest.mark.parametrize(
    "reserved_name", WINDOWS_RESERVED_NAMES
)
def test_fake_fs_com1(fs, reserved_name):
    assert not pathlib.PurePosixPath(reserved_name).is_reserved()
    assert not pathlib.PurePosixPath(reserved_name + ".txt").is_reserved()

Your environment

Linux-6.11.0-8-generic-x86_64-with-glibc2.40
Python 3.11.10 (main, Sep  9 2024, 22:11:19) [Clang 18.1.8 ]
pyfakefs 5.7.dev0
pytest 8.3.3