From 22537140a7e9ecdfd3f7d927be6a5574fe629114 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 23 Aug 2023 18:50:55 +0200 Subject: [PATCH 1/3] Remove debug output accidentally left in - fixes #869 --- CHANGES.md | 3 +++ pyfakefs/fake_filesystem_unittest.py | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 79c4ea70..d40fcac6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ The released versions correspond to PyPI releases. ## Unreleased +### Fixes +* removed a leftover debug print statement (see [#869](../../issues/869)) + ## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-08-18) Fixes a rare problem on pytest shutdown. diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index c916fdb6..4604a650 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -632,7 +632,6 @@ def __init__( @classmethod def clear_fs_cache(cls) -> None: """Clear the module cache.""" - print("Clearing the cache") cls.CACHED_MODULES = set() cls.FS_MODULES = {} cls.FS_FUNCTIONS = {} From 11d5d7880030c94bdc94342c12bc6ada54cf8277 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 23 Aug 2023 20:11:08 +0200 Subject: [PATCH 2/3] Fix tests if HOME environment is missing - fixes #870 --- CHANGES.md | 1 + pyfakefs/tests/fake_filesystem_test.py | 26 +++++++----- .../tests/fake_filesystem_unittest_test.py | 1 + pyfakefs/tests/fake_pathlib_test.py | 41 +++++++++++-------- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d40fcac6..6e205173 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ The released versions correspond to PyPI releases. ### Fixes * removed a leftover debug print statement (see [#869](../../issues/869)) +* make sure tests work without HOME environment set (see [#870](../../issues/870)) ## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-08-18) Fixes a rare problem on pytest shutdown. diff --git a/pyfakefs/tests/fake_filesystem_test.py b/pyfakefs/tests/fake_filesystem_test.py index dda46383..696f8a82 100644 --- a/pyfakefs/tests/fake_filesystem_test.py +++ b/pyfakefs/tests/fake_filesystem_test.py @@ -20,6 +20,7 @@ import stat import sys import unittest +from unittest.mock import patch from pyfakefs import fake_filesystem, fake_os, fake_open from pyfakefs.fake_filesystem import ( @@ -1061,17 +1062,22 @@ def test_join_bytes(self): components = [b"foo", b"bar", b"baz"] self.assertEqual(b"foo!bar!baz", self.path.join(*components)) + @unittest.skipIf(sys.platform != "win32", "Windows specific test") + @patch.dict(os.environ, {"USERPROFILE": r"C:\Users\John"}) + def test_expand_user_windows(self): + self.assertEqual(self.path.expanduser("~"), "C:!Users!John") + + @unittest.skipIf(sys.platform == "win32", "Posix specific test") + @patch.dict(os.environ, {"HOME": "/home/john"}) def test_expand_user(self): - if self.is_windows: - self.assertEqual( - self.path.expanduser("~"), - self.os.environ["USERPROFILE"].replace("\\", "!"), - ) - else: - self.assertEqual( - self.path.expanduser("~"), - self.os.environ["HOME"].replace("/", "!"), - ) + self.assertEqual(self.path.expanduser("~"), "!home!john") + + @patch.dict(os.environ, {}, clear=True) + def test_expand_user_no_home_environment(self): + """Make sure this also works without HOME / USERPROFILE set""" + # we just check that it does not crash and has some result, + # as the result is system-dependent + self.assertTrue(self.path.expanduser("~")) @unittest.skipIf( TestCase.is_windows or TestCase.is_cygwin, diff --git a/pyfakefs/tests/fake_filesystem_unittest_test.py b/pyfakefs/tests/fake_filesystem_unittest_test.py index 6d3e6e68..86f1ae6c 100644 --- a/pyfakefs/tests/fake_filesystem_unittest_test.py +++ b/pyfakefs/tests/fake_filesystem_unittest_test.py @@ -815,6 +815,7 @@ class TestOtherFS(fake_filesystem_unittest.TestCase): def setUp(self): self.setUpPyfakefs() + @mock.patch.dict(os.environ, {"HOME": "/home/john"}) def test_real_file_with_home(self): """Regression test for #558""" self.fs.is_windows_fs = os.name != "nt" diff --git a/pyfakefs/tests/fake_pathlib_test.py b/pyfakefs/tests/fake_pathlib_test.py index d487f321..12820ba3 100644 --- a/pyfakefs/tests/fake_pathlib_test.py +++ b/pyfakefs/tests/fake_pathlib_test.py @@ -27,6 +27,7 @@ import unittest from collections import namedtuple from unittest import mock +from unittest.mock import patch from pyfakefs import fake_pathlib, fake_filesystem, fake_filesystem_unittest, fake_os from pyfakefs.fake_filesystem import OSType @@ -461,23 +462,31 @@ def test_cwd(self): self.path.cwd(), self.path(self.os.path.realpath(dir_path)) ) - def test_expanduser(self): - if is_windows: - self.assertEqual( - self.path("~").expanduser(), - self.path(os.environ["USERPROFILE"].replace("\\", "/")), - ) - else: - self.assertEqual(self.path("~").expanduser(), self.path(os.environ["HOME"])) + @unittest.skipIf(sys.platform != "win32", "Windows specific test") + @patch.dict(os.environ, {"USERPROFILE": r"C:\Users\John"}) + def test_expanduser_windows(self): + self.assertEqual( + self.path("~").expanduser(), + self.path("C:/Users/John"), + ) - def test_home(self): - if is_windows: - self.assertEqual( - self.path(os.environ["USERPROFILE"].replace("\\", "/")), - self.path.home(), - ) - else: - self.assertEqual(self.path(os.environ["HOME"]), self.path.home()) + @unittest.skipIf(sys.platform == "win32", "Posix specific test") + @patch.dict(os.environ, {"HOME": "/home/john"}) + def test_expanduser_posix(self): + self.assertEqual(self.path("~").expanduser(), self.path("/home/john")) + + @unittest.skipIf(sys.platform != "win32", "Windows specific test") + @patch.dict(os.environ, {"USERPROFILE": r"C:\Users\John"}) + def test_home_windows(self): + self.assertEqual( + self.path(self.path("C:/Users/John")), + self.path.home(), + ) + + @unittest.skipIf(sys.platform == "win32", "Posix specific test") + @patch.dict(os.environ, {"HOME": "/home/john"}) + def test_home_posix(self): + self.assertEqual(self.path("/home/john"), self.path.home()) class RealPathlibFileObjectPropertyTest(FakePathlibFileObjectPropertyTest): From c3898b8ff802a87342417be65eae51ec597e0a74 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Wed, 23 Aug 2023 20:55:34 +0200 Subject: [PATCH 3/3] Remove support for EOL Python 3.7 --- .github/workflows/testsuite.yml | 8 ++++---- CHANGES.md | 3 +++ README.md | 4 ++-- docs/intro.rst | 2 +- extra_requirements.txt | 2 +- setup.cfg | 3 +-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index bb6488c6..51b59b2a 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -25,7 +25,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12-dev"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12-dev"] include: - python-version: "pypy-3.7" os: ubuntu-latest @@ -100,8 +100,8 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - python-version: [3.9] - pytest-version: [3.0.0, 3.5.1, 4.0.2, 4.5.0, 5.0.1, 5.4.3, 6.0.2, 6.2.5, 7.0.1, 7.1.3, 7.2.0, 7.3.1] + python-version: ["3.9"] + pytest-version: [3.0.0, 3.5.1, 4.0.2, 4.5.0, 5.0.1, 5.4.3, 6.0.2, 6.2.5, 7.0.1, 7.1.3, 7.2.0, 7.3.1, 7.4.0] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -133,7 +133,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - python-version: [3.9] + python-version: ["3.10"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/CHANGES.md b/CHANGES.md index 6e205173..23958e8f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ The released versions correspond to PyPI releases. ## Unreleased +### Changes +* removed support for Python 3.7 (end of life) + ### Fixes * removed a leftover debug print statement (see [#869](../../issues/869)) * make sure tests work without HOME environment set (see [#870](../../issues/870)) diff --git a/README.md b/README.md index 97b72131..cbdf11f4 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ provides some additional features: under root ## Compatibility -pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS, and +pyfakefs works with CPython 3.8 and above, on Linux, Windows and macOS, and with PyPy3. pyfakefs works with [pytest](http://doc.pytest.org) version 3.0.0 or above, @@ -73,7 +73,7 @@ for more information about the limitations of pyfakefs. ### Continuous integration pyfakefs is currently automatically tested on Linux, macOS and Windows, with -Python 3.7 to 3.11, and with PyPy3 on Linux, using +Python 3.8 to 3.12, and with PyPy3 on Linux, using [GitHub Actions](https://github.com/pytest-dev/pyfakefs/actions). ### Running pyfakefs unit tests diff --git a/docs/intro.rst b/docs/intro.rst index 9d805df1..f022c09b 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -6,7 +6,7 @@ system that mocks the Python file system modules. Using pyfakefs, your tests operate on a fake file system in memory without touching the real disk. The software under test requires no modification to work with pyfakefs. -pyfakefs works with CPython 3.7 and above, on Linux, Windows and macOS, +pyfakefs works with CPython 3.8 and above, on Linux, Windows and macOS, and with PyPy3. pyfakefs works with `pytest `__ version 3.0.0 or above by diff --git a/extra_requirements.txt b/extra_requirements.txt index 7b8cab42..6c69b9cc 100644 --- a/extra_requirements.txt +++ b/extra_requirements.txt @@ -15,5 +15,5 @@ scandir>=1.8 # we use the latest version to see any problems with new versions pandas==1.3.5; python_version == '3.7' # pyup: ignore pandas==2.0.3; python_version > '3.7' -xlrd==2.0.1; python_version > '3.6' +xlrd==2.0.1 openpyxl==3.1.2 diff --git a/setup.cfg b/setup.cfg index be7953b7..a45a048f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,6 @@ classifiers = Intended Audience :: Developers License :: OSI Approved :: Apache Software License Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -50,7 +49,7 @@ universal = 0 [options] packages = find: install_requires = -python_requires = >=3.7 +python_requires = >=3.8 test_suite = pyfakefs.tests include_package_data = True