Skip to content

Commit

Permalink
Adapt to Python 3.14 alpha 5
Browse files Browse the repository at this point in the history
- do not patch globber.scandir in 3.14
- switch off copy file range optimization
  (Linux only)
  • Loading branch information
mrbean-bremen committed Feb 23, 2025
1 parent e8ae593 commit cd7d62c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
# python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
include:
- python-version: "pypy-3.7"
os: ubuntu-22.04
Expand Down
15 changes: 14 additions & 1 deletion pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ def __init__(
self._dyn_patcher: Optional[DynamicPatcher] = None
self._patching = False
self._paused = False
self.has_copy_file_range = False
self.has_copy_file = False

def checkcache(self, filename=None):
"""Calls the original linecache.checkcache making sure no fake OS calls
Expand Down Expand Up @@ -990,6 +992,14 @@ def setUp(self, doctester: Any = None) -> None:
if self.has_fcopy_file:
shutil._HAS_FCOPYFILE = False # type: ignore[attr-defined]

self.has_copy_file_range = (
sys.platform == "linux"
and hasattr(shutil, "_USE_CP_COPY_FILE_RANGE")
and shutil._USE_CP_COPY_FILE_RANGE
)
if self.has_copy_file_range:
shutil._USE_CP_COPY_FILE_RANGE = False # type: ignore[attr-defined]

# do not use the fd functions, as they may not be available in the target OS
if hasattr(shutil, "_use_fd_functions"):
shutil._use_fd_functions = False # type: ignore[module-attr]
Expand Down Expand Up @@ -1047,7 +1057,8 @@ def _set_glob_os_functions(self):
if sys.version_info >= (3, 13):
globber = glob._StringGlobber # type: ignore[module-attr]
globber.lstat = staticmethod(os.lstat)
globber.scandir = staticmethod(os.scandir)
if sys.version_info < (3, 14):
globber.scandir = staticmethod(os.scandir)

def patch_functions(self) -> None:
assert self._stubs is not None
Expand Down Expand Up @@ -1124,6 +1135,8 @@ def tearDown(self, doctester: Any = None):
self.stop_patching()
if self.has_fcopy_file:
shutil._HAS_FCOPYFILE = True # type: ignore[attr-defined]
if self.has_copy_file_range:
shutil._USE_CP_COPY_FILE_RANGE = True # type: ignore[attr-defined]

reset_ids()
if self.is_doc_test:
Expand Down

0 comments on commit cd7d62c

Please sign in to comment.