Skip to content

Commit

Permalink
Adapt to work with pypy 3.10
Browse files Browse the repository at this point in the history
- adapt to some changed behavior
- add another SKIPMODULE for pytest
- add tests for more pypy versions
- see #859
  • Loading branch information
mrbean-bremen committed Jul 9, 2023
1 parent 78d173b commit e42fc6c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
include:
- python-version: "pypy-3.7"
os: ubuntu-latest
- python-version: "pypy-3.9"
os: ubuntu-latest
- python-version: "pypy-3.10"
os: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ The released versions correspond to PyPI releases.
* Adapt to changes in Python 3.12 beta1 (only working partially,
see [#830](../../issues/830) and [#831](../../issues/831)).
* Adapt to changes in `shutil` in Python 3.12 beta2 (see [#814](../../issues/814)).
* Fix support for newer PyPi versions (see [#859](../../issues/859)).

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

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

## [Version 5.2.2](https://pypi.python.org/pypi/pyfakefs/5.2.2) (2023-04-13)
Fixes a regression in 5.2.0
Expand Down
3 changes: 2 additions & 1 deletion pyfakefs/fake_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

from pyfakefs.fake_file import AnyFileWrapper
from pyfakefs.fake_open import FakeFileOpen
from pyfakefs.helpers import IS_PYPY

if TYPE_CHECKING:
from pyfakefs.fake_filesystem import FakeFilesystem
Expand Down Expand Up @@ -124,7 +125,7 @@ def open_code(self, path):
function may be overridden by an earlier call to the
PyFile_SetOpenCodeHook(). This behavior is not reproduced here.
"""
if not isinstance(path, str):
if not isinstance(path, str) and not IS_PYPY:
raise TypeError("open_code() argument 'path' must be str, not int")
patch_mode = self.filesystem.patch_open_code
if (
Expand Down
5 changes: 3 additions & 2 deletions pyfakefs/fake_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ def handle_original_call(f: Callable) -> Callable:

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

for name, fn in inspect.getmembers(FakeOsModule, inspect.isfunction):
setattr(FakeOsModule, name, handle_original_call(fn))
if not fn.__name__.startswith("_"):
setattr(FakeOsModule, name, handle_original_call(fn))


@contextmanager
Expand Down
9 changes: 5 additions & 4 deletions pyfakefs/fake_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pyfakefs.fake_filesystem import FakeFilesystem
from pyfakefs.fake_open import FakeFileOpen
from pyfakefs.fake_os import FakeOsModule, use_original_os
from pyfakefs.helpers import IS_PYPY


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

if (
not kwargs["follow_symlinks"]
and os.chmod not in os.supports_follow_symlinks
if not kwargs["follow_symlinks"] and (
os.chmod not in os.supports_follow_symlinks or IS_PYPY
):
raise NotImplementedError(
"`follow_symlinks` for chmod() is not available " "on this system"
Expand Down Expand Up @@ -916,7 +916,8 @@ def wrapped(*args, **kwargs):
return wrapped

for name, fn in inspect.getmembers(RealPath, inspect.isfunction):
setattr(RealPath, name, with_original_os(fn))
if not name.startswith("__"):
setattr(RealPath, name, with_original_os(fn))


class RealPathlibPathModule:
Expand Down
2 changes: 2 additions & 0 deletions pyfakefs/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def my_fakefs_test(fs):
"""
import py
import pytest
from _pytest import capture

from pyfakefs.fake_filesystem_unittest import Patcher

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

Patcher.SKIPMODULES.add(py)
Patcher.SKIPMODULES.add(pytest)
Patcher.SKIPMODULES.add(capture)
if pathlib is not None:
Patcher.SKIPMODULES.add(pathlib)

Expand Down
3 changes: 2 additions & 1 deletion pyfakefs/tests/fake_filesystem_shutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pathlib import Path

from pyfakefs import fake_filesystem_unittest
from pyfakefs.helpers import get_uid, set_uid, is_root
from pyfakefs.helpers import get_uid, set_uid, is_root, IS_PYPY
from pyfakefs.tests.test_utils import RealFsTestMixin

is_windows = sys.platform == "win32"
Expand Down Expand Up @@ -231,6 +231,7 @@ def test_copystat(self):
self.assertAlmostEqual(src_stat.st_atime, dst_stat.st_atime, places=2)
self.assertAlmostEqual(src_stat.st_mtime, dst_stat.st_mtime, places=2)

@unittest.skipIf(IS_PYPY, "Functionality not supported in PyPy")
def test_copystat_symlinks(self):
"""Regression test for #799"""
self.skip_if_symlink_not_supported()
Expand Down
12 changes: 11 additions & 1 deletion pyfakefs/tests/fake_open_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import unittest

from pyfakefs import fake_filesystem, helpers
from pyfakefs.helpers import is_root
from pyfakefs.helpers import is_root, IS_PYPY
from pyfakefs.fake_io import FakeIoModule
from pyfakefs.fake_filesystem_unittest import PatchMode
from pyfakefs.tests.test_utils import RealFsTestCase
Expand Down Expand Up @@ -1057,10 +1057,19 @@ def tearDown(self):
self.filesystem.patch_open_code = False
super(FakeFilePatchedOpenCodeTest, self).tearDown()

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

@unittest.skipIf(not IS_PYPY, "Different behavior in PyPy")
def test_open_code_fd_pypy(self):
file_path = self.make_path("foo")
self.create_file(file_path, contents="test")
fd = self.os.open(file_path, os.O_RDONLY)
with self.open_code(fd) as f:
assert f.read() == b"test"

def test_byte_contents_open_code(self):
byte_fractions = b"\xe2\x85\x93 \xe2\x85\x94 \xe2\x85\x95 \xe2\x85\x96"
file_path = self.make_path("foo")
Expand Down Expand Up @@ -1090,6 +1099,7 @@ def setUp(self):
else:
self.open_code = self.fake_io_module.open_code

@unittest.skipIf(IS_PYPY, "Different behavior in PyPy")
def test_invalid_path(self):
with self.assertRaises(TypeError):
self.open_code(4)
Expand Down
5 changes: 4 additions & 1 deletion pyfakefs/tests/patched_packages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
with pyfakefs.
"""
import os
import sys
import unittest

from pyfakefs import fake_filesystem_unittest
Expand All @@ -36,7 +37,9 @@
openpyxl = None


@unittest.skipIf(IS_PYPY, "Has a problem with current PyPy")
@unittest.skipIf(
IS_PYPY and sys.version_info < (3, 8), "Has a problem with older PyPy versions"
)
class TestPatchedPackages(fake_filesystem_unittest.TestCase):
def setUp(self):
self.setUpPyfakefs()
Expand Down

0 comments on commit e42fc6c

Please sign in to comment.