Hello community,
here is the log from the commit of package python-pyfakefs for openSUSE:Factory
checked in at 2018-12-21 08:22:31
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pyfakefs (Old)
and /work/SRC/openSUSE:Factory/.python-pyfakefs.new.28833 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pyfakefs"
Fri Dec 21 08:22:31 2018 rev:4 rq:660280 version:3.5.4
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-pyfakefs/python-pyfakefs.changes
2018-11-26 10:29:10.265107863 +0100
+++
/work/SRC/openSUSE:Factory/.python-pyfakefs.new.28833/python-pyfakefs.changes
2018-12-21 08:22:34.641504921 +0100
@@ -1,0 +2,8 @@
+Thu Dec 20 07:33:19 UTC 2018 - Karol Babioch <[email protected]>
+
+- Update to version 3.5.4
+ * added context manager class Pause for pause/resume
+ * fixed permission handling for root user
+ * avoid AttributeError triggered by modules without __module__ attribute
+
+-------------------------------------------------------------------
Old:
----
python-pyfakefs-3.5.3.tar.gz
New:
----
python-pyfakefs-3.5.4.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-pyfakefs.spec ++++++
--- /var/tmp/diff_new_pack.UCSkOu/_old 2018-12-21 08:22:35.105504487 +0100
+++ /var/tmp/diff_new_pack.UCSkOu/_new 2018-12-21 08:22:35.109504483 +0100
@@ -18,7 +18,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-pyfakefs
-Version: 3.5.3
+Version: 3.5.4
Release: 0
Summary: Fake file system that mocks the Python file system modules
License: Apache-2.0
++++++ python-pyfakefs-3.5.3.tar.gz -> python-pyfakefs-3.5.4.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.github/ISSUE_TEMPLATE/bug_report.md
new/pyfakefs-3.5.4/.github/ISSUE_TEMPLATE/bug_report.md
--- old/pyfakefs-3.5.3/.github/ISSUE_TEMPLATE/bug_report.md 1970-01-01
01:00:00.000000000 +0100
+++ new/pyfakefs-3.5.4/.github/ISSUE_TEMPLATE/bug_report.md 2018-12-19
20:07:15.000000000 +0100
@@ -0,0 +1,24 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+Please provide a stack trace if available.
+
+**How To Reproduce**
+Please provide a unit test or a minimal code snippet that reproduces the
+problem.
+
+**Your enviroment**
+Please run the following and paste the output.
+```bash
+python -c "import platform; print(platform.platform())"
+python -c "import sys; print('Python', sys.version)"
+python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs',
__version__)"
+```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/.github/ISSUE_TEMPLATE/feature_request.md
new/pyfakefs-3.5.4/.github/ISSUE_TEMPLATE/feature_request.md
--- old/pyfakefs-3.5.3/.github/ISSUE_TEMPLATE/feature_request.md
1970-01-01 01:00:00.000000000 +0100
+++ new/pyfakefs-3.5.4/.github/ISSUE_TEMPLATE/feature_request.md
2018-12-19 20:07:15.000000000 +0100
@@ -0,0 +1,17 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always
frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A description of any alternative solutions or features you've considered.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.travis/docker_tests.sh
new/pyfakefs-3.5.4/.travis/docker_tests.sh
--- old/pyfakefs-3.5.3/.travis/docker_tests.sh 1970-01-01 01:00:00.000000000
+0100
+++ new/pyfakefs-3.5.4/.travis/docker_tests.sh 2018-12-19 20:07:15.000000000
+0100
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [[ $VM == 'Docker' ]]; then
+ echo "Running tests in Docker image"
+ echo "============================="
+ docker build -t pyfakefs .
+ docker run -t pyfakefs
+fi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.travis/install.sh
new/pyfakefs-3.5.4/.travis/install.sh
--- old/pyfakefs-3.5.3/.travis/install.sh 2018-11-22 19:03:44.000000000
+0100
+++ new/pyfakefs-3.5.4/.travis/install.sh 2018-12-19 20:07:15.000000000
+0100
@@ -44,6 +44,8 @@
source ~/.venv/bin/activate
fi
+if ! [[ $VM == 'Docker' ]]; then
pip install -r requirements.txt
pip install -r extra_requirements.txt
pip install .
+fi
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.travis/run_pytest.sh
new/pyfakefs-3.5.4/.travis/run_pytest.sh
--- old/pyfakefs-3.5.3/.travis/run_pytest.sh 2018-11-22 19:03:44.000000000
+0100
+++ new/pyfakefs-3.5.4/.travis/run_pytest.sh 2018-12-19 20:07:15.000000000
+0100
@@ -4,9 +4,11 @@
source ~/.venv/bin/activate
fi
-python -m pytest pyfakefs/tests/pytest/pytest_plugin_test.py
-if [[ $PYTHON == 'py36' ]] || [[ $PYTHON == 'py37' ]]; then
- python -m pytest pyfakefs/tests/pytest/pytest_fixture_test.py
-fi
-python -m pytest pyfakefs/tests/pytest/pytest_plugin_failing_test.py >
./testresult.txt
-python -m pytest pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
+if ! [[ $VM == 'Docker' ]]; then
+ python -m pytest pyfakefs/tests/pytest/pytest_plugin_test.py
+ if [[ $PYTHON == 'py36' ]] || [[ $PYTHON == 'py37' ]]; then
+ python -m pytest pyfakefs/tests/pytest/pytest_fixture_test.py
+ fi
+ python -m pytest pyfakefs/tests/pytest/pytest_plugin_failing_test.py >
./testresult.txt
+ python -m pytest pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
+fi
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.travis/run_tests.sh
new/pyfakefs-3.5.4/.travis/run_tests.sh
--- old/pyfakefs-3.5.3/.travis/run_tests.sh 2018-11-22 19:03:44.000000000
+0100
+++ new/pyfakefs-3.5.4/.travis/run_tests.sh 2018-12-19 20:07:15.000000000
+0100
@@ -4,18 +4,28 @@
source ~/.venv/bin/activate
fi
-python --version
-pip --version
-pip install flake8
+if ! [[ $VM == 'Docker' ]]; then
+ python --version
+ pip --version
+ pip install flake8
-EXCLUDES='--exclude get-pip.py'
-if [[ $PYTHON == 'py27' ]] || [[ $PYTHON == 'pypy2' ]]; then
-
EXCLUDES=$EXCLUDES',pyfakefs/fake_pathlib.py,pyfakefs/tests/fake_pathlib_test.py'
-fi
+ EXCLUDES='--exclude get-pip.py'
+ if [[ $PYTHON == 'py27' ]] || [[ $PYTHON == 'pypy2' ]]; then
+
EXCLUDES=$EXCLUDES',pyfakefs/fake_pathlib.py,pyfakefs/tests/fake_pathlib_test.py'
+ fi
-# stop the build if there are Python syntax errors or undefined names
-flake8 . $EXCLUDES --count --select=E901,E999,F821,F822,F823 --show-source
--statistics
-# exit-zero treats all errors as warnings
-flake8 . $EXCLUDES --count --exit-zero --max-complexity=12 --statistics
-python -m pyfakefs.tests.all_tests
-python -m pyfakefs.tests.all_tests_without_extra_packages
+ # stop the build if there are Python syntax errors or undefined names
+ flake8 . $EXCLUDES --count --select=E901,E999,F821,F822,F823 --show-source
--statistics
+ # exit-zero treats all errors as warnings
+ flake8 . $EXCLUDES --count --exit-zero --max-complexity=12 --statistics
+ echo =======================================================
+ echo Running unit tests with extra packages as non-root user
+ python -m pyfakefs.tests.all_tests
+ echo ==========================================================
+ echo Running unit tests without extra packages as non-root user
+ python -m pyfakefs.tests.all_tests_without_extra_packages
+ echo ============================================
+ echo Running tests without extra packages as root
+ # provide the same path as non-root to get the correct virtualenv
+ sudo env "PATH=$PATH" python -m
pyfakefs.tests.all_tests_without_extra_packages
+fi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/.travis.yml
new/pyfakefs-3.5.4/.travis.yml
--- old/pyfakefs-3.5.3/.travis.yml 2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/.travis.yml 2018-12-19 20:07:15.000000000 +0100
@@ -43,6 +43,8 @@
- os: osx
language: generic
env: PYTHON=py37
+ - language: minimal
+ env: VM=Docker
install:
- ./.travis/install.sh
@@ -50,3 +52,4 @@
script:
- ./.travis/run_tests.sh
- ./.travis/run_pytest.sh
+ - ./.travis/docker_tests.sh
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/CHANGES.md
new/pyfakefs-3.5.4/CHANGES.md
--- old/pyfakefs-3.5.3/CHANGES.md 2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/CHANGES.md 2018-12-19 20:07:15.000000000 +0100
@@ -1,6 +1,19 @@
# pyfakefs Release Notes
The release versions are PyPi releases.
+## [Version 3.5.4](https://pypi.python.org/pypi/pyfakefs/3.5.4)
+
+#### New Features
+ * added context manager class `Pause` for pause/resume
+ (see [#448](../../issues/448))
+
+#### Fixes
+ * fixed `AttributeError` shown while displaying `fs` in a failing pytest
+ in Python 2
+ * fixed permission handling for root user
+ * avoid `AttributeError` triggered by modules without `__module__` attribute
+ (see [#460](../../issues/460))
+
## [Version 3.5.3](https://pypi.python.org/pypi/pyfakefs/3.5.3)
This is a minor release to have a version with passing tests for OpenSUSE
@@ -14,7 +27,7 @@
#### Fixes
* make tests for access time less strict to account for file systems that
do not change it immediately ([#453](../../issues/453))
-
+
## [Version 3.5.2](https://pypi.python.org/pypi/pyfakefs/3.5.2)
This is mostly a bug-fix release.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/Dockerfile
new/pyfakefs-3.5.4/Dockerfile
--- old/pyfakefs-3.5.3/Dockerfile 1970-01-01 01:00:00.000000000 +0100
+++ new/pyfakefs-3.5.4/Dockerfile 2018-12-19 20:07:15.000000000 +0100
@@ -0,0 +1,54 @@
+# Copyright 2018 John McGehee. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Prerequisites:
+# * Install Docker
+# * Clone pyfakefs
+#
+# To build and run the container:
+#
+# cd pyfakefs
+# docker build -t pyfakefs .
+# docker run -t pyfakefs
+
+FROM ubuntu
+MAINTAINER [email protected]
+
+# The Ubuntu base container does not specify a locale.
+# pyfakefs tests require at least the Latin1 character set.
+RUN apt-get update && apt-get install -y locales
+RUN locale-gen en_US.UTF-8
+ENV LANG en_US.UTF-8
+ENV LANGUAGE en_US:en
+ENV LC_ALL en_US.UTF-8
+
+RUN apt-get update && apt-get install -y \
+ python3-pip \
+ unzip \
+ wget
+RUN apt-get clean
+
+RUN useradd -u 1000 pyfakefs
+
+RUN wget https://github.com/jmcgeheeiv/pyfakefs/archive/master.zip \
+ && unzip master.zip \
+ && chown -R pyfakefs:pyfakefs /pyfakefs-master
+WORKDIR /pyfakefs-master
+RUN pip3 install -r requirements.txt
+RUN pip3 install -r extra_requirements.txt
+
+USER pyfakefs
+ENV PYTHONPATH /pyfakefs-master
+CMD ["python3", "-m", "pyfakefs.tests.all_tests"]
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/README.md new/pyfakefs-3.5.4/README.md
--- old/pyfakefs-3.5.3/README.md 2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/README.md 2018-12-19 20:07:15.000000000 +0100
@@ -69,11 +69,16 @@
### Running pyfakefs unit tests
-pyfakefs unit tests are available via two test scripts:
+#### On the command line
+pyfakefs unit tests can be run using `unittest` or `pytest`:
```bash
+$ cd pyfakefs/
+$ export PYTHONPATH=$PWD
+
$ python -m pyfakefs.tests.all_tests
-$ python -m pytest pyfakefs/tests/pytest_plugin_test.py
+$ python -m pyfakefs.tests.all_tests_without_extra_packages
+$ python -m pytest pyfakefs/tests/pytest/pytest_plugin_test.py
```
These scripts are called by `tox` and Travis-CI. `tox` can be used to run tests
@@ -83,6 +88,19 @@
$ tox
```
+#### In a Docker container
+
+The `Dockerfile` at the top of the repository will run the tests on the latest
+Ubuntu version. Build the container:
+```bash
+cd pyfakefs/
+docker build -t pyfakefs .
+```
+Run the unit tests in the container:
+```bash
+docker run -t pyfakefs
+```
+
### Contributing to pyfakefs
We always welcome contributions to the library. Check out the [Contributing
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/docs/conf.py
new/pyfakefs-3.5.4/docs/conf.py
--- old/pyfakefs-3.5.3/docs/conf.py 2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/docs/conf.py 2018-12-19 20:07:15.000000000 +0100
@@ -66,9 +66,9 @@
# built documents.
#
# The short X.Y version.
-version = '3.5.3'
+version = '3.5.4'
# The full version, including alpha/beta/rc tags.
-release = '3.5.3'
+release = '3.5.4'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/docs/usage.rst
new/pyfakefs-3.5.4/docs/usage.rst
--- old/pyfakefs-3.5.3/docs/usage.rst 2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/docs/usage.rst 2018-12-19 20:07:15.000000000 +0100
@@ -89,7 +89,29 @@
Customizing Patcher and TestCase
--------------------------------
-Pyfakefs automatically patches file system related modules that are:
+
+Both ``fake_filesystem_unittest.Patcher`` and
``fake_filesystem_unittest.TestCase``
+provide a few arguments to handle cases where patching does not work out of
+the box.
+In case of ``fake_filesystem_unittest.TestCase``, these arguments can either
+be set in the TestCase instance initialization, or passed to
``setUpPyfakefs()``.
+
+.. note:: If you need these arguments in ``PyTest``, you must
+ use ``Patcher`` directly instead of the ``fs`` fixture. Alternatively,
+ you can add your own fixture with the needed parameters.
+
+ An example for both approaches can be found in
+ `pytest_fixture_test.py
<https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/tests/pytest/pytest_fixture_test.py>`__
+ with the example fixture in `conftest.py
<https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/tests/pytest/conftest.py>`__.
+ We advice to use this example fixture code as a template for your customized
+ pytest plugins.
+
+modules_to_reload
+~~~~~~~~~~~~~~~~~
+Pyfakefs patches modules that are imported before starting the test by
+finding and replacing file system modules in all loaded modules at test
+initialization time.
+This allows to automatically patch file system related modules that are:
- imported directly, for example:
@@ -127,46 +149,95 @@
from io import open as io_open
from builtins import open as bltn_open
-There are other cases where automatic patching does not work.
-Both ``fake_filesystem_unittest.Patcher`` and
``fake_filesystem_unittest.TestCase``
-provide a few additional arguments to handle such cases.
-In case of ``fake_filesystem_unittest.TestCase``, these arguments can either
-be set in the TestCase instance initialization, or when you call
-``setUpPyfakefs()``.
+There are a few cases where automatic patching does not work. We know of two
+specific cases where this is the case:
-.. note:: If you need these arguments in ``PyTest``, you must
- use ``Patcher`` directly instead of the ``fs`` fixture. Alternatively,
- you can add your own fixture with the needed parameters.
+- initializing global variables:
- An example for both approaches can be found in
- `pytest_fixture_test.py
<https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/tests/pytest/pytest_fixture_test.py>`__
- with the example fixture in `conftest.py
<https://github.com/jmcgeheeiv/pyfakefs/blob/master/pyfakefs/tests/pytest/conftest.py>`__.
+.. code:: python
+ from pathlib import Path
-modules_to_reload
-~~~~~~~~~~~~~~~~~
-This allows to pass a list of modules that shall be reloaded, thus allowing
-to patch modules not patched automatically.
+ path = Path("/example_home")
-A common example for failed automatic patching is the assignment of file
-system functions to a variable, as shown in the following example with
-default argument assignment:
+In this case, ``path`` will hold the real file system path inside the test.
+
+- initializing a default argument:
.. code:: python
+ import os
+
def check_if_exists(filepath, file_exists=os.path.exists):
return file_exists(filepath)
-If adding the module containing this code to ``modules_to_reload``, it
-will be correctly patched.
+Here, ``file_exists`` will not be patched in the test.
+
+To get these cases to work as expected under test, the respective modules
+containing the code shall be added to the ``modules_to_reload`` argument (a
+module list).
+The passed modules will be reloaded, thus allowing pyfakefs to patch them
+dynamically. All modules loaded after the initial patching described above
+will be patched using this second mechanism.
+
+Given tat the example code shown above is located in the file
``example/sut.py``,
+the following code will work:
+
+.. code:: python
+
+ # example using unittest
+ class ReloadModuleTest(fake_filesystem_unittest.TestCase):
+ def setUp(self):
+ self.setUpPyfakefs(modules_to_reload=[example.sut])
+
+ def test_path_exists(self):
+ file_path = '/foo/bar'
+ self.fs.create_dir(file_path)
+ self.assertTrue(example.sut.check_if_exists(file_path))
+
+ # example using Patcher
+ def test_path_exists():
+ with Patcher() as patcher:
+ file_path = '/foo/bar'
+ patcher.fs.create_dir(file_path)
+ assert example.sut.check_if_exists(file_path)
+
+Example using pytest:
+
+.. code:: python
+
+ # conftest.py
+ ...
+ from example import sut
+
+ @pytest.fixture
+ def fs_reload_sut():
+ patcher = Patcher(modules_to_reload=[sut])
+ patcher.setUp()
+ linecache.open = patcher.original_open
+ tokenize._builtin_open = patcher.original_open
+ yield patcher.fs
+ patcher.tearDown()
+
+ # test_code.py
+ ...
+ def test_path_exists(fs_reload_sut):
+ file_path = '/foo/bar'
+ fs_reload_sut.create_dir(file_path)
+ assert example.sut.check_if_exists(file_path)
+
modules_to_patch
~~~~~~~~~~~~~~~~
-This also allows patching modules that are not patched out of the box, in
-this case by adding a fake module implementation for a module name. The
-argument is a dictionary of fake modules mapped to the names to be faked.
-This can be used to fake out modules that use OS-specific file system calls
-as in the following example:
+Sometimes there are file system modules in other packages that are not
+patched in standard pyfakefs. To allow patching such modules,
+``modules_to_patch`` can be used by adding a fake module implementation for
+a module name. The argument is a dictionary of fake modules mapped to the
+names to be faked.
+
+This mechanism is used in pyfakefs itself to patch the external modules
+`pathlib2` and `scandir` if present, and the following example shows how to
+fake a module in Django that uses OS file system functions:
.. code:: python
@@ -199,14 +270,18 @@
~~~~~~~~~~~~~~~~~~~~~
This may be used to add modules that shall not be patched. This is mostly
used to avoid patching the Python file system modules themselves, but may be
-helpful in some special situations.
+helpful in some special situations. There is also the global
+variable ``Patcher.SKIPNAMES`` that can be extended for that purpose, though
+this seldom shall be needed (except for own pytest plugins, as shown in
+the example mentioned above)
use_dynamic_patch
~~~~~~~~~~~~~~~~~
If ``True`` (the default), dynamic patching after setup is used (for example
for modules loaded locally inside of functions).
-Can be switched off if it causes unwanted side effects. This parameter may
-be removed in the future if no use case turns up for it.
+Can be switched off if it causes unwanted side effects. This parameter will
+probably removed in the future - it has been added while dynamic patching
+was an experimental feature.
Using convenience methods
-------------------------
@@ -323,3 +398,45 @@
To get the file system size, you may use ``get_disk_usage()``, which is
modeled after ``shutil.disk_usage()``.
+
+Pausing patching
+~~~~~~~~~~~~~~~~
+Sometimes, you may want to access the real filesystem inside the test with
+no patching applied. This can be achieved by using the ``pause/resume``
+functions, which exist in ``fake_filesystem_unittest.Patcher``,
+``fake_filesystem_unittest.TestCase`` and ``fake_filesystem.FakeFilesystem``.
+There is also a context manager class ``fake_filesystem_unittest.Pause``
+which encapsulates the calls to ``pause()`` and ``resume()``.
+
+Here is an example that tests the usage with the pyfakefs pytest fixture:
+
+.. code:: python
+
+ from pyfakefs.fake_filesystem_unittest import Pause
+
+ def test_pause_resume_contextmanager(fs):
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ assert os.path.exists(fake_temp_file.name)
+ fs.pause()
+ assert not os.path.exists(fake_temp_file.name)
+ real_temp_file = tempfile.NamedTemporaryFile()
+ assert os.path.exists(real_temp_file.name)
+ fs.resume()
+ assert not os.path.exists(real_temp_file.name)
+ assert os.path.exists(fake_temp_file.name)
+
+Here is the same code using a context manager:
+
+.. code:: python
+
+ from pyfakefs.fake_filesystem_unittest import Pause
+
+ def test_pause_resume_contextmanager(fs):
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ assert os.path.exists(fake_temp_file.name)
+ with Pause(fs):
+ assert not os.path.exists(fake_temp_file.name)
+ real_temp_file = tempfile.NamedTemporaryFile()
+ assert os.path.exists(real_temp_file.name)
+ assert not os.path.exists(real_temp_file.name)
+ assert os.path.exists(fake_temp_file.name)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/fake_filesystem.py
new/pyfakefs-3.5.4/pyfakefs/fake_filesystem.py
--- old/pyfakefs-3.5.3/pyfakefs/fake_filesystem.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/fake_filesystem.py 2018-12-19
20:07:15.000000000 +0100
@@ -111,11 +111,15 @@
from pyfakefs.helpers import (
FakeStatResult, FileBufferIO, IS_PY2, NullFileBufferIO,
is_int_type, is_byte_string, is_unicode_string,
- make_string_path, text_type
+ make_string_path, text_type, IS_WIN
)
+
+if sys.version_info[0] < 3:
+ import __builtin__
+
__pychecker__ = 'no-reimportself'
-__version__ = '3.5.3'
+__version__ = '3.5.4'
PERM_READ = 0o400 # Read permission bit.
PERM_WRITE = 0o200 # Write permission bit.
@@ -162,8 +166,8 @@
)
NR_STD_STREAMS = 3
-USER_ID = 1
-GROUP_ID = 1
+USER_ID = 1 if IS_WIN else os.getuid()
+GROUP_ID = 1 if IS_WIN else os.getgid()
def set_uid(uid):
@@ -4277,6 +4281,8 @@
if os_error.errno == errno.ENOENT:
return False
raise
+ if is_root():
+ mode &= ~os.W_OK
return (mode & ((stat_result.st_mode >> 6) & 7)) == mode
def chmod(self, path, mode, dir_fd=None, follow_symlinks=None):
@@ -4418,7 +4424,7 @@
# note that a default value of 0o600 without a device type is
# documented - this is not how it seems to work
mode = S_IFREG | 0o600
- if device or not mode & S_IFREG:
+ if device or not mode & S_IFREG and not is_root():
self.filesystem.raise_os_error(errno.EPERM)
filename = self._path_with_dir_fd(filename, self.mknod, dir_fd)
@@ -4570,6 +4576,8 @@
file system information.
"""
self.filesystem = filesystem
+ if IS_PY2:
+ self._builtin_module = __builtin__
def open(self, *args, **kwargs):
"""Redirect the call to FakeFileOpen.
@@ -4577,6 +4585,11 @@
"""
return FakeFileOpen(self.filesystem)(*args, **kwargs)
+ if IS_PY2:
+ def __getattr__(self, name):
+ """Forwards any unfaked calls to the standard builtins."""
+ return getattr(self._builtin_module, name)
+
class FakeFileWrapper(object):
"""Wrapper for a stream object for use by a FakeFile object.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/fake_filesystem_unittest.py
new/pyfakefs-3.5.4/pyfakefs/fake_filesystem_unittest.py
--- old/pyfakefs-3.5.3/pyfakefs/fake_filesystem_unittest.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/fake_filesystem_unittest.py 2018-12-19
20:07:15.000000000 +0100
@@ -432,6 +432,30 @@
Later, `setUp()` will stub these with the fake file system
modules.
"""
+
+ def is_fs_module(mod, name):
+ try:
+ return (inspect.ismodule(mod) and
+ mod.__name__ in module_names
+ or inspect.isclass(mod) and
+ mod.__module__ in self._class_modules.get(name, []))
+ except AttributeError:
+ # handle cases where the module has no __name__ or __module__
+ # attribute - see #460
+ return False
+
+ def is_fs_function(fct):
+ try:
+ return ((inspect.isfunction(fct) or
+ inspect.isbuiltin(fct)) and
+ fct.__name__ in self._fake_module_functions and
+ fct.__module__ in self._fake_module_functions[
+ fct.__name__])
+ except AttributeError:
+ # handle cases where the function has no __name__ or __module__
+ # attribute
+ return False
+
module_names = list(self._fake_module_classes.keys()) + [PATH_MODULE]
for name, module in set(sys.modules.items()):
try:
@@ -446,20 +470,13 @@
continue
modules = {name: mod for name, mod in module.__dict__.items()
- if inspect.ismodule(mod) and
- mod.__name__ in module_names
- or inspect.isclass(mod) and
- mod.__module__ in self._class_modules.get(name, [])}
+ if is_fs_module(mod, name)}
for name, mod in modules.items():
self._modules.setdefault(name, set()).add((module,
mod.__name__))
functions = {name: fct for name, fct in module.__dict__.items()
- if (inspect.isfunction(fct) or
- inspect.isbuiltin(fct)) and
- fct.__name__ in self._fake_module_functions and
- fct.__module__ in self._fake_module_functions[
- fct.__name__]}
+ if is_fs_function(fct)}
for name, fct in functions.items():
self._fct_modules.setdefault(
(name, fct.__name__, fct.__module__), set()).add(module)
@@ -565,6 +582,36 @@
self.start_patching()
+class Pause(object):
+ """Simple context manager that allows to pause/resume patching the
+ filesystem. Patching is paused in the context manager, and resumed after
+ going out of it's scope.
+ """
+ def __init__(self, caller):
+ """Initializes the context manager with the fake filesystem.
+
+ Args:
+ caller: either the FakeFilesystem instance, the Patcher instance
+ or the pyfakefs test case.
+ """
+ if isinstance(caller, (Patcher, TestCaseMixin)):
+ self._fs = caller.fs
+ elif isinstance(caller, fake_filesystem.FakeFilesystem):
+ self._fs = caller
+ else:
+ raise ValueError('Invalid argument - should be of type '
+ '"fake_filesystem_unittest.Patcher", '
+ '"fake_filesystem_unittest.TestCase" '
+ 'or "fake_filesystem.FakeFilesystem"')
+
+ def __enter__(self):
+ self._fs.pause()
+ return self._fs
+
+ def __exit__(self, *args):
+ return self._fs.resume()
+
+
class DynamicPatcher(object):
"""A file loader that replaces file system related modules by their
fake implementation if they are loaded after calling `setupPyFakefs()`.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/helpers.py
new/pyfakefs-3.5.4/pyfakefs/helpers.py
--- old/pyfakefs-3.5.3/pyfakefs/helpers.py 2018-11-22 19:03:44.000000000
+0100
+++ new/pyfakefs-3.5.4/pyfakefs/helpers.py 2018-12-19 20:07:15.000000000
+0100
@@ -22,6 +22,7 @@
IS_PY2 = sys.version_info[0] < 3
IS_PYPY = platform.python_implementation() == 'PyPy'
+IS_WIN = sys.platform == 'win32'
try:
text_type = unicode # Python 2
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/pytest_plugin.py
new/pyfakefs-3.5.4/pyfakefs/pytest_plugin.py
--- old/pyfakefs-3.5.3/pyfakefs/pytest_plugin.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/pytest_plugin.py 2018-12-19
20:07:15.000000000 +0100
@@ -17,6 +17,7 @@
from pyfakefs.fake_filesystem_unittest import Patcher
+Patcher.SKIPMODULES.add(pytest)
Patcher.SKIPMODULES.add(py) # Ignore pytest components when faking filesystem
# The "linecache" module is used to read the test file in case of test failure
@@ -26,14 +27,15 @@
# as a local function in the module (used in Python 2).
# In Python 3, we also have to set back the cached open function in tokenize.
Patcher.SKIPMODULES.add(linecache)
+Patcher.SKIPMODULES.add(tokenize)
@pytest.fixture
-def fs(request):
+def fs():
""" Fake filesystem. """
patcher = Patcher()
patcher.setUp()
linecache.open = patcher.original_open
tokenize._builtin_open = patcher.original_open
- request.addfinalizer(patcher.tearDown)
- return patcher.fs
+ yield patcher.fs
+ patcher.tearDown()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_shutil_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_shutil_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_shutil_test.py
2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_shutil_test.py
2018-12-19 20:07:15.000000000 +0100
@@ -25,7 +25,7 @@
import unittest
from pyfakefs import fake_filesystem_unittest
-from pyfakefs.fake_filesystem import set_uid
+from pyfakefs.fake_filesystem import is_root
from pyfakefs.tests.test_utils import RealFsTestMixin
is_windows = sys.platform == 'win32'
@@ -103,9 +103,13 @@
file_path = os.path.join(dir_path, 'baz')
self.create_file(file_path)
self.os.chmod(dir_path, 0o555)
- self.assertRaises(OSError, shutil.rmtree, dir_path)
- self.assertTrue(os.path.exists(file_path))
- self.os.chmod(dir_path, 0o777)
+ if not is_root():
+ self.assertRaises(OSError, shutil.rmtree, dir_path)
+ self.assertTrue(os.path.exists(file_path))
+ self.os.chmod(dir_path, 0o777)
+ else:
+ shutil.rmtree(dir_path)
+ self.assertFalse(os.path.exists(file_path))
@unittest.skipIf(is_windows, 'Posix specific behavior')
def test_rmtree_with_open_file_posix(self):
@@ -357,7 +361,6 @@
class FakeCopyFileTest(RealFsTestCase):
def tearDown(self):
- set_uid(1)
super(FakeCopyFileTest, self).tearDown()
def test_common_case(self):
@@ -414,13 +417,15 @@
os.chmod(dst_file, 0o400)
self.assertTrue(os.path.exists(src_file))
self.assertTrue(os.path.exists(dst_file))
- self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)
- if not self.use_real_fs():
- set_uid(0)
+
+ if is_root():
shutil.copyfile(src_file, dst_file)
self.assertTrue(self.os.path.exists(dst_file))
with self.open(dst_file) as f:
self.assertEqual('contents of source file', f.read())
+ else:
+ self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)
+
os.chmod(dst_file, 0o666)
@unittest.skipIf(is_windows, 'Posix specific behavior')
@@ -435,8 +440,13 @@
os.chmod(dst_dir, 0o555)
self.assertTrue(os.path.exists(src_file))
self.assertTrue(os.path.exists(dst_dir))
- exception = OSError if sys.version_info[0] > 2 else IOError
- self.assertRaises(exception, shutil.copyfile, src_file, dst_file)
+ if not is_root():
+ exception = OSError if sys.version_info[0] > 2 else IOError
+ self.assertRaises(exception, shutil.copyfile, src_file, dst_file)
+ else:
+ shutil.copyfile(src_file, dst_file)
+ self.assertTrue(os.path.exists(dst_file))
+ self.check_contents(dst_file, src_contents)
def test_raises_if_src_doesnt_exist(self):
src_file = self.make_path('xyzzy')
@@ -453,7 +463,12 @@
self.create_file(src_file, contents=src_contents)
os.chmod(src_file, 0o000)
self.assertTrue(os.path.exists(src_file))
- self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)
+ if not is_root():
+ self.assertRaises(IOError, shutil.copyfile, src_file, dst_file)
+ else:
+ shutil.copyfile(src_file, dst_file)
+ self.assertTrue(os.path.exists(dst_file))
+ self.check_contents(dst_file, src_contents)
def test_raises_if_src_is_a_directory(self):
src_file = self.make_path('xyzzy')
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_test.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_test.py 2018-12-19
20:07:15.000000000 +0100
@@ -24,7 +24,8 @@
import unittest
from pyfakefs import fake_filesystem
-from pyfakefs.fake_filesystem import set_uid, set_gid
+from pyfakefs.fake_filesystem import set_uid, set_gid, is_root
+from pyfakefs.helpers import IS_WIN
from pyfakefs.tests.test_utils import DummyTime, TestCase
@@ -260,7 +261,6 @@
'foobaz', filesystem=self.filesystem)
self.fake_grandchild = fake_filesystem.FakeDirectory(
'quux', filesystem=self.filesystem)
- set_uid(1)
def test_new_filesystem(self):
self.assertEqual('/', self.filesystem.path_separator)
@@ -487,15 +487,19 @@
dir_path = '/foo/bar'
self.filesystem.create_dir(dir_path, perm_bits=0o555)
file_path = dir_path + '/baz'
- if sys.version_info[0] < 3:
- self.assert_raises_io_error(errno.EACCES,
- self.filesystem.create_file, file_path)
+
+ if not is_root():
+ if sys.version_info[0] < 3:
+ self.assert_raises_io_error(errno.EACCES,
+ self.filesystem.create_file,
+ file_path)
+ else:
+ self.assert_raises_os_error(errno.EACCES,
+ self.filesystem.create_file,
+ file_path)
else:
- self.assert_raises_os_error(errno.EACCES,
- self.filesystem.create_file, file_path)
- set_uid(0)
- self.filesystem.create_file(file_path)
- self.assertTrue(self.filesystem.exists(file_path))
+ self.filesystem.create_file(file_path)
+ self.assertTrue(self.filesystem.exists(file_path))
def test_create_file_in_read_only_directory_possible_in_windows(self):
self.filesystem.is_windows_fs = True
@@ -545,8 +549,12 @@
self.assertTrue(self.filesystem.exists(os.path.dirname(path)))
new_file = self.filesystem.get_object(path)
self.assertEqual(os.path.basename(path), new_file.name)
- self.assertEqual(1, new_file.st_uid)
- self.assertEqual(1, new_file.st_gid)
+ if IS_WIN:
+ self.assertEqual(1, new_file.st_uid)
+ self.assertEqual(1, new_file.st_gid)
+ else:
+ self.assertEqual(os.getuid(), new_file.st_uid)
+ self.assertEqual(os.getgid(), new_file.st_gid)
self.assertEqual(new_file, retval)
def test_create_file_with_changed_ids(self):
@@ -558,8 +566,8 @@
new_file = self.filesystem.get_object(path)
self.assertEqual(42, new_file.st_uid)
self.assertEqual(2, new_file.st_gid)
- set_uid(1)
- set_gid(1)
+ set_uid(1 if IS_WIN else os.getuid())
+ set_gid(1 if IS_WIN else os.getgid())
def test_empty_file_created_for_none_contents(self):
fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
@@ -1829,7 +1837,6 @@
self.pyfakefs_path = os.path.split(
os.path.dirname(os.path.abspath(__file__)))[0]
self.root_path = os.path.split(self.pyfakefs_path)[0]
- set_uid(1)
def test_add_non_existing_real_file_raises(self):
nonexisting_path = os.path.join('nonexisting', 'test.txt')
@@ -1881,8 +1888,12 @@
with open(real_file_path, 'rb') as f:
real_contents = f.read()
self.assertEqual(fake_file.byte_contents, real_contents)
- self.assert_raises_io_error(
- errno.EACCES, self.fake_open, real_file_path, 'w')
+ if not is_root():
+ self.assert_raises_io_error(
+ errno.EACCES, self.fake_open, real_file_path, 'w')
+ else:
+ with self.fake_open(real_file_path, 'w'):
+ pass
def check_writable_file(self, fake_file, real_file_path):
with open(real_file_path, 'rb') as f:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_unittest_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_unittest_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/fake_filesystem_unittest_test.py
2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/fake_filesystem_unittest_test.py
2018-12-19 20:07:15.000000000 +0100
@@ -31,7 +31,7 @@
from pyfakefs import fake_filesystem_unittest, fake_filesystem
from pyfakefs.extra_packages import pathlib
-from pyfakefs.fake_filesystem_unittest import Patcher
+from pyfakefs.fake_filesystem_unittest import Patcher, Pause
import pyfakefs.tests.import_as_example
from pyfakefs.helpers import IS_PYPY, IS_PY2
from pyfakefs.tests.fixtures import module_with_attributes
@@ -338,6 +338,32 @@
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
+ def test_pause_resume_contextmanager(self):
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ self.assertTrue(self.fs.exists(fake_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+ with Pause(self):
+ self.assertTrue(self.fs.exists(fake_temp_file.name))
+ self.assertFalse(os.path.exists(fake_temp_file.name))
+ real_temp_file = tempfile.NamedTemporaryFile()
+ self.assertFalse(self.fs.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(real_temp_file.name))
+ self.assertFalse(os.path.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+
+ def test_pause_resume_fs_contextmanager(self):
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ self.assertTrue(self.fs.exists(fake_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+ with Pause(self.fs):
+ self.assertTrue(self.fs.exists(fake_temp_file.name))
+ self.assertFalse(os.path.exists(fake_temp_file.name))
+ real_temp_file = tempfile.NamedTemporaryFile()
+ self.assertFalse(self.fs.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(real_temp_file.name))
+ self.assertFalse(os.path.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+
def test_pause_resume_without_patcher(self):
fs = fake_filesystem.FakeFilesystem()
self.assertRaises(RuntimeError, fs.resume)
@@ -359,6 +385,20 @@
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
+ def test_pause_resume_contextmanager(self):
+ with Patcher() as p:
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ self.assertTrue(p.fs.exists(fake_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+ with Pause(p):
+ self.assertTrue(p.fs.exists(fake_temp_file.name))
+ self.assertFalse(os.path.exists(fake_temp_file.name))
+ real_temp_file = tempfile.NamedTemporaryFile()
+ self.assertFalse(p.fs.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(real_temp_file.name))
+ self.assertFalse(os.path.exists(real_temp_file.name))
+ self.assertTrue(os.path.exists(fake_temp_file.name))
+
class TestCopyOrAddRealFile(TestPyfakefsUnittestBase):
"""Tests the `fake_filesystem_unittest.TestCase.copyRealFile()` method.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/tests/fake_open_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/fake_open_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/fake_open_test.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/fake_open_test.py 2018-12-19
20:07:15.000000000 +0100
@@ -27,7 +27,7 @@
import unittest
from pyfakefs import fake_filesystem
-from pyfakefs.fake_filesystem import set_uid
+from pyfakefs.fake_filesystem import is_root
from pyfakefs.tests.test_utils import TestCase, RealFsTestCase
@@ -40,7 +40,6 @@
def setUp(self):
super(FakeFileOpenTest, self).setUp()
self.orig_time = time.time
- set_uid(1)
def tearDown(self):
super(FakeFileOpenTest, self).tearDown()
@@ -452,10 +451,10 @@
self.create_with_permission(file_path, 0o400)
# actual tests
self.open(file_path, 'r').close()
- self.assert_raises_io_error(errno.EACCES, self.open, file_path, 'w')
- self.assert_raises_io_error(errno.EACCES, self.open, file_path, 'w+')
- if not self.use_real_fs():
- set_uid(0)
+ if not is_root():
+ self.assert_raises_io_error(errno.EACCES, self.open, file_path,
'w')
+ self.assert_raises_io_error(errno.EACCES, self.open, file_path,
'w+')
+ else:
self.open(file_path, 'w').close()
self.open(file_path, 'w+').close()
@@ -465,11 +464,11 @@
file_path = self.make_path('target_file')
self.create_with_permission(file_path, 0o200)
# actual tests
- self.assertRaises(IOError, self.open, file_path, 'r')
self.open(file_path, 'w').close()
- self.assertRaises(IOError, self.open, file_path, 'w+')
- if not self.use_real_fs():
- set_uid(0)
+ if not is_root():
+ self.assertRaises(IOError, self.open, file_path, 'r')
+ self.assertRaises(IOError, self.open, file_path, 'w+')
+ else:
self.open(file_path, 'r').close()
self.open(file_path, 'w+').close()
@@ -479,11 +478,11 @@
file_path = self.make_path('target_file')
self.create_with_permission(file_path, 0o100)
# actual tests
- self.assertRaises(IOError, self.open, file_path, 'r')
- self.assertRaises(IOError, self.open, file_path, 'w')
- self.assertRaises(IOError, self.open, file_path, 'w+')
- if not self.use_real_fs():
- set_uid(0)
+ if not is_root():
+ self.assertRaises(IOError, self.open, file_path, 'r')
+ self.assertRaises(IOError, self.open, file_path, 'w')
+ self.assertRaises(IOError, self.open, file_path, 'w+')
+ else:
self.open(file_path, 'r').close()
self.open(file_path, 'w').close()
self.open(file_path, 'w+').close()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/tests/fake_os_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/fake_os_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/fake_os_test.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/fake_os_test.py 2018-12-19
20:07:15.000000000 +0100
@@ -25,7 +25,7 @@
import unittest
from pyfakefs import fake_filesystem
-from pyfakefs.fake_filesystem import FakeFileOpen, set_uid
+from pyfakefs.fake_filesystem import FakeFileOpen, is_root
from pyfakefs.extra_packages import use_scandir, use_scandir_package
from pyfakefs.tests.test_utils import DummyTime, TestCase, RealFsTestCase
@@ -54,7 +54,6 @@
super(FakeOsModuleTest, self).setUp()
self.rwx = self.os.R_OK | self.os.W_OK | self.os.X_OK
self.rw = self.os.R_OK | self.os.W_OK
- set_uid(1)
def test_chdir(self):
"""chdir should work on a directory."""
@@ -224,11 +223,12 @@
fileno1 = fake_file1.fileno()
self.os.fdopen(fileno1)
self.os.fdopen(fileno1, 'r')
- exception = OSError if self.is_python2 else IOError
- self.assertRaises(exception, self.os.fdopen, fileno1, 'w')
- set_uid(0)
- self.os.fdopen(fileno1, 'w')
- self.os.close(fileno1)
+ if not is_root():
+ exception = OSError if self.is_python2 else IOError
+ self.assertRaises(exception, self.os.fdopen, fileno1, 'w')
+ else:
+ self.os.fdopen(fileno1, 'w')
+ self.os.close(fileno1)
def test_fstat(self):
directory = self.make_path('xyzzy')
@@ -754,9 +754,19 @@
path = self.os.path.join(parent_dir, 'bar')
self.create_file(path)
self.os.chmod(parent_dir, 0o666) # missing execute permission
- self.assert_raises_os_error(errno.EACCES, self.os.remove, path)
+ if not is_root():
+ self.assert_raises_os_error(errno.EACCES, self.os.remove, path)
+ else:
+ self.os.remove(path)
+ self.assertFalse(self.os.path.exists(path))
+ self.create_file(path)
self.os.chmod(parent_dir, 0o555) # missing write permission
- self.assert_raises_os_error(errno.EACCES, self.os.remove, path)
+ if not is_root():
+ self.assert_raises_os_error(errno.EACCES, self.os.remove, path)
+ else:
+ self.os.remove(path)
+ self.assertFalse(self.os.path.exists(path))
+ self.create_file(path)
self.os.chmod(parent_dir, 0o333)
self.os.remove(path)
self.assertFalse(self.os.path.exists(path))
@@ -1606,9 +1616,9 @@
self.os.chmod(directory, 0o400)
directory = self.make_path('a', 'b')
- self.assert_raises_os_error(errno.EACCES, self.os.mkdir, directory)
- if not self.use_real_fs():
- set_uid(0)
+ if not is_root():
+ self.assert_raises_os_error(errno.EACCES, self.os.mkdir, directory)
+ else:
self.os.mkdir(directory)
self.assertTrue(self.os.path.exists(directory))
@@ -1680,10 +1690,9 @@
self.os.chmod(directory, 0o400)
directory = self.make_path('a', 'b')
- set_uid(1)
- self.assertRaises(Exception, self.os.makedirs, directory)
- if not self.use_real_fs():
- set_uid(0)
+ if not is_root():
+ self.assertRaises(Exception, self.os.makedirs, directory)
+ else:
self.os.makedirs(directory)
self.assertTrue(self.os.path.exists(directory))
@@ -1795,10 +1804,14 @@
# actual tests
self.assertTrue(self.os.access(path, self.os.F_OK))
self.assertTrue(self.os.access(path, self.os.R_OK))
- self.assertFalse(self.os.access(path, self.os.W_OK))
self.assertFalse(self.os.access(path, self.os.X_OK))
self.assertFalse(self.os.access(path, self.rwx))
- self.assertFalse(self.os.access(path, self.rw))
+ if is_root():
+ self.assertTrue(self.os.access(path, self.os.W_OK))
+ self.assertTrue(self.os.access(path, self.rw))
+ else:
+ self.assertFalse(self.os.access(path, self.os.W_OK))
+ self.assertFalse(self.os.access(path, self.rw))
@unittest.skipIf(sys.version_info < (3, 3),
'follow_symlinks new in Python 3.3')
@@ -1814,10 +1827,14 @@
# test file
self.assertTrue(self.os.access(link_path, self.os.F_OK))
self.assertTrue(self.os.access(link_path, self.os.R_OK))
- self.assertFalse(self.os.access(link_path, self.os.W_OK))
+ if is_root():
+ self.assertTrue(self.os.access(link_path, self.os.W_OK))
+ self.assertTrue(self.os.access(link_path, self.rw))
+ else:
+ self.assertFalse(self.os.access(link_path, self.os.W_OK))
+ self.assertFalse(self.os.access(link_path, self.rw))
self.assertFalse(self.os.access(link_path, self.os.X_OK))
self.assertFalse(self.os.access(link_path, self.rwx))
- self.assertFalse(self.os.access(link_path, self.rw))
# test link itself
self.assertTrue(
@@ -2114,8 +2131,12 @@
def test_mknod_raises_if_unsupported_options(self):
self.check_posix_only()
filename = 'abcde'
- self.assert_raises_os_error(errno.EPERM, self.os.mknod, filename,
- stat.S_IFCHR)
+ if not is_root():
+ self.assert_raises_os_error(errno.EPERM, self.os.mknod, filename,
+ stat.S_IFCHR)
+ else:
+ self.os.mknod(filename, stat.S_IFCHR)
+ self.os.remove(filename)
def test_mknod_raises_if_parent_is_not_a_directory(self):
self.check_linux_only()
@@ -2683,10 +2704,10 @@
self.os.fdopen(fileno1)
self.os.fdopen(fileno1, 'r')
exception = OSError if self.is_python2 else IOError
- set_uid(1)
- self.assertRaises(exception, self.os.fdopen, fileno1, 'w')
- set_uid(0)
- self.os.fdopen(fileno1, 'w')
+ if not is_root():
+ self.assertRaises(exception, self.os.fdopen, fileno1, 'w')
+ else:
+ self.os.fdopen(fileno1, 'w')
def test_stat(self):
directory = self.make_path('xyzzy')
@@ -4711,9 +4732,13 @@
[f.path for f in self.scandir(link_path)])
def test_inode(self):
- if use_scandir and self.is_windows and self.use_real_fs():
- self.skipTest(
- 'inode seems not to work in scandir module under Windows')
+ if use_scandir and self.use_real_fs():
+ if self.is_windows:
+ self.skipTest(
+ 'inode seems not to work in scandir module under Windows')
+ if os.path.exists('/.dockerenv'):
+ self.skipTest(
+ 'inode seems not to work in a Docker container')
self.assertEqual(self.os.stat(self.dir_path).st_ino,
self.dir_entries[0].inode())
self.assertEqual(self.os.stat(self.file_path).st_ino,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/pyfakefs-3.5.3/pyfakefs/tests/pytest/conftest.py
new/pyfakefs-3.5.4/pyfakefs/tests/pytest/conftest.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/pytest/conftest.py 2018-11-22
19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/pytest/conftest.py 2018-12-19
20:07:15.000000000 +0100
@@ -11,17 +11,33 @@
# limitations under the License.
# Example for a custom pytest fixture with an argument to Patcher.
+# Use this as a template if you want to write your own pytest plugin
+# with specific Patcher arguments.
+# See `pytest_plugin.py` for more information.
+import linecache
+import tokenize
+
+import py
import pytest
from pyfakefs.fake_filesystem_unittest import Patcher
+
+Patcher.SKIPMODULES.add(pytest)
+Patcher.SKIPMODULES.add(py)
+Patcher.SKIPMODULES.add(linecache)
+Patcher.SKIPMODULES.add(tokenize)
+
+from pyfakefs.fake_filesystem_unittest import Patcher
from pyfakefs.tests.pytest import example
@pytest.fixture
-def fs_reload_example(request):
+def fs_reload_example():
""" Fake filesystem. """
patcher = Patcher(modules_to_reload=[example])
patcher.setUp()
- request.addfinalizer(patcher.tearDown)
- return patcher.fs
+ linecache.open = patcher.original_open
+ tokenize._builtin_open = patcher.original_open
+ yield patcher.fs
+ patcher.tearDown()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/pytest/pytest_check_failed_plugin_test.py
2018-12-19 20:07:15.000000000 +0100
@@ -16,4 +16,5 @@
assert contents
print('contents', contents)
assert '???' not in contents
+ assert 'AttributeError' not in contents
assert 'def test_fs(fs):' in contents
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/pyfakefs-3.5.3/pyfakefs/tests/pytest/pytest_plugin_test.py
new/pyfakefs-3.5.4/pyfakefs/tests/pytest/pytest_plugin_test.py
--- old/pyfakefs-3.5.3/pyfakefs/tests/pytest/pytest_plugin_test.py
2018-11-22 19:03:44.000000000 +0100
+++ new/pyfakefs-3.5.4/pyfakefs/tests/pytest/pytest_plugin_test.py
2018-12-19 20:07:15.000000000 +0100
@@ -2,6 +2,8 @@
import os
import tempfile
+from pyfakefs.fake_filesystem_unittest import Pause
+
def test_fs_fixture(fs):
fs.create_file('/var/data/xx1.txt')
@@ -21,3 +23,16 @@
fs.resume()
assert not os.path.exists(real_temp_file.name)
assert os.path.exists(fake_temp_file.name)
+
+def test_pause_resume_contextmanager(fs):
+ fake_temp_file = tempfile.NamedTemporaryFile()
+ assert fs.exists(fake_temp_file.name)
+ assert os.path.exists(fake_temp_file.name)
+ with Pause(fs):
+ assert fs.exists(fake_temp_file.name)
+ assert not os.path.exists(fake_temp_file.name)
+ real_temp_file = tempfile.NamedTemporaryFile()
+ assert not fs.exists(real_temp_file.name)
+ assert os.path.exists(real_temp_file.name)
+ assert not os.path.exists(real_temp_file.name)
+ assert os.path.exists(fake_temp_file.name)