Skip to content

Commit e42fc6c

Browse files
committed
Adapt to work with pypy 3.10
- adapt to some changed behavior - add another SKIPMODULE for pytest - add tests for more pypy versions - see #859
1 parent 78d173b commit e42fc6c

File tree

9 files changed

+35
-10
lines changed

9 files changed

+35
-10
lines changed

.github/workflows/testsuite.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
include:
3030
- python-version: "pypy-3.7"
3131
os: ubuntu-latest
32+
- python-version: "pypy-3.9"
33+
os: ubuntu-latest
34+
- python-version: "pypy-3.10"
35+
os: ubuntu-latest
3236

3337
steps:
3438
- uses: actions/checkout@v3

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ The released versions correspond to PyPI releases.
1111
* Adapt to changes in Python 3.12 beta1 (only working partially,
1212
see [#830](../../issues/830) and [#831](../../issues/831)).
1313
* Adapt to changes in `shutil` in Python 3.12 beta2 (see [#814](../../issues/814)).
14+
* Fix support for newer PyPi versions (see [#859](../../issues/859)).
1415

1516
### Documentation
1617
* Added a note regarding the incompatibility of the built-in `sqlite3` module with
1718
`pyfakefs` (see [#850](../../issues/850))
1819

1920
### Infrastructure
2021
* Added pytype check for non-test modules in CI (see [#599](../../issues/599)).
22+
* Added tests for different pypy3 versions.
2123

2224
## [Version 5.2.2](https://pypi.python.org/pypi/pyfakefs/5.2.2) (2023-04-13)
2325
Fixes a regression in 5.2.0

pyfakefs/fake_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from pyfakefs.fake_file import AnyFileWrapper
3535
from pyfakefs.fake_open import FakeFileOpen
36+
from pyfakefs.helpers import IS_PYPY
3637

3738
if TYPE_CHECKING:
3839
from pyfakefs.fake_filesystem import FakeFilesystem
@@ -124,7 +125,7 @@ def open_code(self, path):
124125
function may be overridden by an earlier call to the
125126
PyFile_SetOpenCodeHook(). This behavior is not reproduced here.
126127
"""
127-
if not isinstance(path, str):
128+
if not isinstance(path, str) and not IS_PYPY:
128129
raise TypeError("open_code() argument 'path' must be str, not int")
129130
patch_mode = self.filesystem.patch_open_code
130131
if (

pyfakefs/fake_os.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ def handle_original_call(f: Callable) -> Callable:
13481348

13491349
@functools.wraps(f)
13501350
def wrapped(*args, **kwargs):
1351-
if not f.__name__.startswith("_") and FakeOsModule.use_original:
1351+
if FakeOsModule.use_original:
13521352
# remove the `self` argument for FakeOsModule methods
13531353
if args and isinstance(args[0], FakeOsModule):
13541354
args = args[1:]
@@ -1358,7 +1358,8 @@ def wrapped(*args, **kwargs):
13581358
return wrapped
13591359

13601360
for name, fn in inspect.getmembers(FakeOsModule, inspect.isfunction):
1361-
setattr(FakeOsModule, name, handle_original_call(fn))
1361+
if not fn.__name__.startswith("_"):
1362+
setattr(FakeOsModule, name, handle_original_call(fn))
13621363

13631364

13641365
@contextmanager

pyfakefs/fake_pathlib.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from pyfakefs.fake_filesystem import FakeFilesystem
4848
from pyfakefs.fake_open import FakeFileOpen
4949
from pyfakefs.fake_os import FakeOsModule, use_original_os
50+
from pyfakefs.helpers import IS_PYPY
5051

5152

5253
def init_module(filesystem):
@@ -130,9 +131,8 @@ def chmod(self, pathobj, *args, **kwargs):
130131
"chmod() got an unexpected keyword " "argument 'follow_symlinks'"
131132
)
132133

133-
if (
134-
not kwargs["follow_symlinks"]
135-
and os.chmod not in os.supports_follow_symlinks
134+
if not kwargs["follow_symlinks"] and (
135+
os.chmod not in os.supports_follow_symlinks or IS_PYPY
136136
):
137137
raise NotImplementedError(
138138
"`follow_symlinks` for chmod() is not available " "on this system"
@@ -916,7 +916,8 @@ def wrapped(*args, **kwargs):
916916
return wrapped
917917

918918
for name, fn in inspect.getmembers(RealPath, inspect.isfunction):
919-
setattr(RealPath, name, with_original_os(fn))
919+
if not name.startswith("__"):
920+
setattr(RealPath, name, with_original_os(fn))
920921

921922

922923
class RealPathlibPathModule:

pyfakefs/pytest_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def my_fakefs_test(fs):
1010
"""
1111
import py
1212
import pytest
13+
from _pytest import capture
1314

1415
from pyfakefs.fake_filesystem_unittest import Patcher
1516

@@ -20,6 +21,7 @@ def my_fakefs_test(fs):
2021

2122
Patcher.SKIPMODULES.add(py)
2223
Patcher.SKIPMODULES.add(pytest)
24+
Patcher.SKIPMODULES.add(capture)
2325
if pathlib is not None:
2426
Patcher.SKIPMODULES.add(pathlib)
2527

pyfakefs/tests/fake_filesystem_shutil_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pathlib import Path
2626

2727
from pyfakefs import fake_filesystem_unittest
28-
from pyfakefs.helpers import get_uid, set_uid, is_root
28+
from pyfakefs.helpers import get_uid, set_uid, is_root, IS_PYPY
2929
from pyfakefs.tests.test_utils import RealFsTestMixin
3030

3131
is_windows = sys.platform == "win32"
@@ -231,6 +231,7 @@ def test_copystat(self):
231231
self.assertAlmostEqual(src_stat.st_atime, dst_stat.st_atime, places=2)
232232
self.assertAlmostEqual(src_stat.st_mtime, dst_stat.st_mtime, places=2)
233233

234+
@unittest.skipIf(IS_PYPY, "Functionality not supported in PyPy")
234235
def test_copystat_symlinks(self):
235236
"""Regression test for #799"""
236237
self.skip_if_symlink_not_supported()

pyfakefs/tests/fake_open_test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import unittest
2626

2727
from pyfakefs import fake_filesystem, helpers
28-
from pyfakefs.helpers import is_root
28+
from pyfakefs.helpers import is_root, IS_PYPY
2929
from pyfakefs.fake_io import FakeIoModule
3030
from pyfakefs.fake_filesystem_unittest import PatchMode
3131
from pyfakefs.tests.test_utils import RealFsTestCase
@@ -1057,10 +1057,19 @@ def tearDown(self):
10571057
self.filesystem.patch_open_code = False
10581058
super(FakeFilePatchedOpenCodeTest, self).tearDown()
10591059

1060+
@unittest.skipIf(IS_PYPY, "Different behavior in PyPy")
10601061
def test_invalid_path(self):
10611062
with self.assertRaises(TypeError):
10621063
self.open_code(4)
10631064

1065+
@unittest.skipIf(not IS_PYPY, "Different behavior in PyPy")
1066+
def test_open_code_fd_pypy(self):
1067+
file_path = self.make_path("foo")
1068+
self.create_file(file_path, contents="test")
1069+
fd = self.os.open(file_path, os.O_RDONLY)
1070+
with self.open_code(fd) as f:
1071+
assert f.read() == b"test"
1072+
10641073
def test_byte_contents_open_code(self):
10651074
byte_fractions = b"\xe2\x85\x93 \xe2\x85\x94 \xe2\x85\x95 \xe2\x85\x96"
10661075
file_path = self.make_path("foo")
@@ -1090,6 +1099,7 @@ def setUp(self):
10901099
else:
10911100
self.open_code = self.fake_io_module.open_code
10921101

1102+
@unittest.skipIf(IS_PYPY, "Different behavior in PyPy")
10931103
def test_invalid_path(self):
10941104
with self.assertRaises(TypeError):
10951105
self.open_code(4)

pyfakefs/tests/patched_packages_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
with pyfakefs.
1616
"""
1717
import os
18+
import sys
1819
import unittest
1920

2021
from pyfakefs import fake_filesystem_unittest
@@ -36,7 +37,9 @@
3637
openpyxl = None
3738

3839

39-
@unittest.skipIf(IS_PYPY, "Has a problem with current PyPy")
40+
@unittest.skipIf(
41+
IS_PYPY and sys.version_info < (3, 8), "Has a problem with older PyPy versions"
42+
)
4043
class TestPatchedPackages(fake_filesystem_unittest.TestCase):
4144
def setUp(self):
4245
self.setUpPyfakefs()

0 commit comments

Comments
 (0)