From 6646762480b312490834f994f83acb984ba4c718 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sun, 1 Nov 2020 20:00:45 +0100 Subject: [PATCH] Use GitHub actions for tests - replace all tests by GitHub actions - fix some tests failing in real fs due to different environment --- .../workflows}/dockerfiles/Dockerfile_centos | 0 .../workflows}/dockerfiles/Dockerfile_debian | 0 .../workflows}/dockerfiles/Dockerfile_fedora | 0 .../workflows}/dockerfiles/Dockerfile_ubuntu | 0 .github/workflows/pythonpackage.yml | 79 +++++++++ .../workflows/run_pytest.sh | 9 +- .travis.yml | 164 ------------------ .travis/docker_tests.sh | 10 -- .travis/install.sh | 47 ----- .travis/run_flake.sh | 6 - .travis/run_pytest_fixture_param_test.sh | 7 - .travis/run_pytest_fixture_test.sh | 7 - .travis/run_tests_as_root.sh | 11 -- .travis/run_tests_no_extra_packages.sh | 10 -- .travis/run_tests_with_extra_packages.sh | 11 -- CHANGES.md | 3 + appveyor.yml | 23 --- pyfakefs/tests/fake_filesystem_test.py | 44 ++--- .../tests/fake_filesystem_vs_real_test.py | 13 +- pyfakefs/tests/fake_os_test.py | 9 +- pyfakefs/tests/fake_pathlib_test.py | 15 +- pyfakefs/tests/test_utils.py | 33 ++-- 22 files changed, 145 insertions(+), 356 deletions(-) rename {.travis => .github/workflows}/dockerfiles/Dockerfile_centos (100%) rename {.travis => .github/workflows}/dockerfiles/Dockerfile_debian (100%) rename {.travis => .github/workflows}/dockerfiles/Dockerfile_fedora (100%) rename {.travis => .github/workflows}/dockerfiles/Dockerfile_ubuntu (100%) create mode 100644 .github/workflows/pythonpackage.yml rename .travis/run_pytest_plugin_test.sh => .github/workflows/run_pytest.sh (53%) delete mode 100644 .travis.yml delete mode 100755 .travis/docker_tests.sh delete mode 100755 .travis/install.sh delete mode 100755 .travis/run_flake.sh delete mode 100755 .travis/run_pytest_fixture_param_test.sh delete mode 100755 .travis/run_pytest_fixture_test.sh delete mode 100755 .travis/run_tests_as_root.sh delete mode 100755 .travis/run_tests_no_extra_packages.sh delete mode 100755 .travis/run_tests_with_extra_packages.sh delete mode 100644 appveyor.yml diff --git a/.travis/dockerfiles/Dockerfile_centos b/.github/workflows/dockerfiles/Dockerfile_centos similarity index 100% rename from .travis/dockerfiles/Dockerfile_centos rename to .github/workflows/dockerfiles/Dockerfile_centos diff --git a/.travis/dockerfiles/Dockerfile_debian b/.github/workflows/dockerfiles/Dockerfile_debian similarity index 100% rename from .travis/dockerfiles/Dockerfile_debian rename to .github/workflows/dockerfiles/Dockerfile_debian diff --git a/.travis/dockerfiles/Dockerfile_fedora b/.github/workflows/dockerfiles/Dockerfile_fedora similarity index 100% rename from .travis/dockerfiles/Dockerfile_fedora rename to .github/workflows/dockerfiles/Dockerfile_fedora diff --git a/.travis/dockerfiles/Dockerfile_ubuntu b/.github/workflows/dockerfiles/Dockerfile_ubuntu similarity index 100% rename from .travis/dockerfiles/Dockerfile_ubuntu rename to .github/workflows/dockerfiles/Dockerfile_ubuntu diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 00000000..1443a9c0 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,79 @@ +name: Python package + +on: [push] + +jobs: + linter: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + python-version: [3.8] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install linter + run: python -m pip install flake8 + - name: Check syntax and style + run: flake8 . --exclude get-pip.py --max-complexity=13 --statistics + + tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macOS-latest, windows-2016] + python-version: [3.6, 3.7, 3.8, 3.9] + include: + - python-version: pypy3 + os: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r extra_requirements.txt + pip install . + - name: Run unit tests with extra packages as non-root user + run: | + python -m pyfakefs.tests.all_tests + - name: Run unit tests without extra packages as non-root user + run: | + export TEST_REAL_FS=1 + python -m pyfakefs.tests.all_tests_without_extra_packages + shell: bash + - name: Run unit tests without extra packages as root + run: | + if [[ '${{ matrix.os }}' != 'windows-2016' ]]; then + # 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 + shell: bash + - name: Run pytest tests + run: | + export PY_VERSION=${{ matrix.python-version }} + $GITHUB_WORKSPACE/.github/workflows/run_pytest.sh + shell: bash + + dockertests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + docker-image: [centos, debian, fedora, ubuntu] + steps: + - uses: actions/checkout@v2 + - name: Setup docker container + run: | + docker build -t pyfakefs -f $GITHUB_WORKSPACE/.github/workflows/dockerfiles/Dockerfile_${{ matrix.docker-image }} . --build-arg github_repo=$GITHUB_REPOSITORY --build-arg github_branch=$(basename $GITHUB_REF) + - name: Run tests + run: docker run -t pyfakefs diff --git a/.travis/run_pytest_plugin_test.sh b/.github/workflows/run_pytest.sh similarity index 53% rename from .travis/run_pytest_plugin_test.sh rename to .github/workflows/run_pytest.sh index a0dc7cb2..725deb9c 100755 --- a/.travis/run_pytest_plugin_test.sh +++ b/.github/workflows/run_pytest.sh @@ -1,9 +1,8 @@ #!/bin/bash -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate +python -m pytest pyfakefs/pytest_tests/pytest_plugin_test.py +if [[ $PY_VERSION == '3.6' ]] || [[ $PY_VERSION == '3.7' ]] || [[ $PY_VERSION == '3.8' ]] || [[ $PY_VERSION == '3.9' ]] ; then + python -m pytest pyfakefs/pytest_tests/pytest_fixture_test.py fi - python -m pytest pyfakefs/pytest_tests/pytest_plugin_failing_helper.py > ./testresult.txt -python -m pytest pyfakefs/pytest_tests/pytest_check_failed_plugin_test.py && \ -python -m pytest pyfakefs/pytest_tests/pytest_plugin_test.py +python -m pytest pyfakefs/pytest_tests/pytest_check_failed_plugin_test.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8adb1285..00000000 --- a/.travis.yml +++ /dev/null @@ -1,164 +0,0 @@ -# Perform continuous integration testing with Travis CI. -# -# Copyright 2015 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. - -language: python - -before_script: - - ./.travis/install.sh - -jobs: - include: - - stage: flake8 - script: ./.travis/run_flake.sh - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_plugin_test.sh - python: 3.5.9 - env: - - PYTHON=py35 - - PY_VERSION=3.5.9 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - python: 3.6.9 - env: - - PYTHON=py36 - - PY_VERSION=3.6.9 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - python: 3.7.5 - dist: xenial - sudo: true - env: - - PYTHON=py37 - - PY_VERSION=3.7.5 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - python: 3.8.1 - dist: xenial - sudo: true - env: - - PYTHON=py38 - - PY_VERSION=3.8.1 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_plugin_test.sh - python: pypy3.5-7.0.0 - dist: xenial - sudo: true - env: PYTHON=pypy3 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - os: osx - language: generic - env: - - PYTHON=py36 - - PY_VERSION=3.6.9 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - os: osx - language: generic - env: - - PYTHON=py37 - - PY_VERSION=3.7.6 - - - stage: test - script: - - ./.travis/run_tests_with_extra_packages.sh - - ./.travis/run_tests_no_extra_packages.sh - - ./.travis/run_tests_as_root.sh - - ./.travis/run_pytest_fixture_test.sh - - ./.travis/run_pytest_fixture_param_test.sh - - ./.travis/run_pytest_plugin_test.sh - os: osx - language: generic - env: - - PYTHON=py38 - - PY_VERSION=3.8.1 - - - stage: test - script: - - ./.travis/docker_tests.sh - language: minimal - env: - - VM=Docker - - DOCKERFILE=ubuntu - - - stage: test - script: - - ./.travis/docker_tests.sh - language: minimal - env: - - VM=Docker - - DOCKERFILE=centos - - - stage: test - script: - - ./.travis/docker_tests.sh - language: minimal - env: - - VM=Docker - - DOCKERFILE=fedora - - - stage: test - script: - - ./.travis/docker_tests.sh - language: minimal - env: - - VM=Docker - - DOCKERFILE=debian diff --git a/.travis/docker_tests.sh b/.travis/docker_tests.sh deleted file mode 100755 index 8f5f7e7f..00000000 --- a/.travis/docker_tests.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -if [[ $VM == 'Docker' ]]; then - echo "Running tests in Docker image '$DOCKERFILE'" - echo "=============================" - export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) - export REPO_SLUG=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_REPO_SLUG; else echo $TRAVIS_PULL_REQUEST_SLUG; fi) - docker build -t pyfakefs -f .travis/dockerfiles/Dockerfile_$DOCKERFILE . --build-arg github_repo=$REPO_SLUG --build-arg github_branch=$BRANCH - docker run -t pyfakefs -fi diff --git a/.travis/install.sh b/.travis/install.sh deleted file mode 100755 index c280a7a7..00000000 --- a/.travis/install.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -# script to install Python versions under MacOS, as Travis.IO -# does not have explicit Python support for MacOS -# Taken from https://github.com/pyca/cryptography and adapted. - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - sw_vers - - # install pyenv - git clone --depth 1 https://github.com/pyenv/pyenv ~/.pyenv - PYENV_ROOT="$HOME/.pyenv" - PATH="$PYENV_ROOT/bin:$PATH" - eval "$(pyenv init -)" - - case "${PYTHON}" in - py34|py35|py36|py37|py38) - pyenv install "${PY_VERSION}" - pyenv global "${PY_VERSION}" - ;; - pypy*) - pyenv install "$PYPY_VERSION" - pyenv global "$PYPY_VERSION" - ;; - esac - pyenv rehash - python -m pip install --user virtualenv - python -m virtualenv ~/.venv - source ~/.venv/bin/activate -fi - -if [ -n "$PY_VERSION" ] -then - echo Checking Python version... - if [ "$(python --version)" != "Python ${PY_VERSION}" ] - then - echo Incorrect version - expected "${PY_VERSION}". - echo Exiting. - exit 1 - fi - echo Python version ok. -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 --git a/.travis/run_flake.sh b/.travis/run_flake.sh deleted file mode 100755 index f1cf807f..00000000 --- a/.travis/run_flake.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -pip install flake8 - -# let the build fail for any flake8 warning -flake8 . --exclude get-pip.py --max-complexity=13 --statistics diff --git a/.travis/run_pytest_fixture_param_test.sh b/.travis/run_pytest_fixture_param_test.sh deleted file mode 100755 index c57de656..00000000 --- a/.travis/run_pytest_fixture_param_test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate -fi - -python -m pytest pyfakefs/pytest_tests/pytest_fixture_param_test.py diff --git a/.travis/run_pytest_fixture_test.sh b/.travis/run_pytest_fixture_test.sh deleted file mode 100755 index 6b0c9e72..00000000 --- a/.travis/run_pytest_fixture_test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate -fi - -python -m pytest pyfakefs/pytest_tests/pytest_fixture_test.py diff --git a/.travis/run_tests_as_root.sh b/.travis/run_tests_as_root.sh deleted file mode 100755 index 264dbdf6..00000000 --- a/.travis/run_tests_as_root.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate -fi - -python --version -export TEST_REAL_FS=1 -echo ============================================ -echo Running tests without extra packages as root -sudo env "PATH=$PATH" python -m pyfakefs.tests.all_tests_without_extra_packages diff --git a/.travis/run_tests_no_extra_packages.sh b/.travis/run_tests_no_extra_packages.sh deleted file mode 100755 index 0aceb308..00000000 --- a/.travis/run_tests_no_extra_packages.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate -fi - -export TEST_REAL_FS=1 -echo ========================================================== -echo Running unit tests without extra packages as non-root user -python -m pyfakefs.tests.all_tests_without_extra_packages diff --git a/.travis/run_tests_with_extra_packages.sh b/.travis/run_tests_with_extra_packages.sh deleted file mode 100755 index 28d0e0e7..00000000 --- a/.travis/run_tests_with_extra_packages.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -if [[ $TRAVIS_OS_NAME == 'osx' ]]; then - source ~/.venv/bin/activate -fi - -python --version -export TEST_REAL_FS=1 -echo ======================================================= -echo Running unit tests with extra packages as non-root user -python -m pyfakefs.tests.all_tests diff --git a/CHANGES.md b/CHANGES.md index efbfc1f3..af22e971 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ The released versions correspond to PyPi releases. ## Version 4.4.0 (as yet unreleased) +### Infrastructure +* Moved CI builds to GitHub Actions for performance reasons + ## [Version 4.3.0](https://pypi.python.org/pypi/pyfakefs/4.3.0) (2020-11-19) This is mostly a performance release. The performance of the pyfakefs setup has diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 4e5524c2..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,23 +0,0 @@ -environment: - - matrix: - - PYTHON: "C:\\Python35-x64" - - PYTHON: "C:\\Python36-x64" - - PYTHON: "C:\\Python37-x64" - - PYTHON: "C:\\Python38-x64" - -install: - - "%PYTHON%\\python.exe -m pip install -r requirements.txt" - - "%PYTHON%\\python.exe -m pip install -r extra_requirements.txt" - -build: off - -test_script: - - SET TEST_REAL_FS=1 - - "%PYTHON%\\python.exe -m pyfakefs.tests.all_tests" - - "%PYTHON%\\python.exe -m pyfakefs.tests.all_tests_without_extra_packages" - - "%PYTHON%\\python.exe -m pytest pyfakefs\\pytest_tests\\pytest_plugin_test.py" - - ps: If ($env:PYTHON -Match ".*3[678]-x64") { "$env:PYTHON\\python.exe -m pytest pyfakefs\\pytest_tests\\pytest_fixture_test.py" } - - ps: If ($env:PYTHON -Match ".*3[678]-x64") { "$env:PYTHON\\python.exe -m pytest pyfakefs\\pytest_tests\\pytest_fixture_param_test.py" } - - "%PYTHON%\\python.exe -m pytest pyfakefs\\pytest_tests\\pytest_plugin_failing_helper.py > testresult.txt | echo." - - "%PYTHON%\\python.exe -m pytest pyfakefs\\pytest_tests\\pytest_check_failed_plugin_test.py" diff --git a/pyfakefs/tests/fake_filesystem_test.py b/pyfakefs/tests/fake_filesystem_test.py index 5e4f3d3c..8e0a327d 100644 --- a/pyfakefs/tests/fake_filesystem_test.py +++ b/pyfakefs/tests/fake_filesystem_test.py @@ -26,7 +26,7 @@ from pyfakefs import fake_filesystem from pyfakefs.fake_filesystem import set_uid, set_gid, is_root, reset_ids from pyfakefs.helpers import IS_WIN -from pyfakefs.tests.test_utils import DummyTime, TestCase +from pyfakefs.tests.test_utils import DummyTime, TestCase, RealFsTestCase class FakeDirectoryUnitTest(TestCase): @@ -1773,7 +1773,7 @@ def test_that_unc_paths_are_auto_mounted(self): '!!foo!bar!bip!bop').st_dev) -class RealFileSystemAccessTest(TestCase): +class RealFileSystemAccessTest(RealFsTestCase): def setUp(self): # use the real path separator to work with the real file system self.filesystem = fake_filesystem.FakeFilesystem() @@ -2005,6 +2005,7 @@ def test_add_existing_real_directory_symlink(self): ) def test_add_existing_real_directory_symlink_target_path(self): + self.skip_if_symlink_not_supported() real_directory = os.path.join(self.root_path, 'pyfakefs', 'tests') symlinks = [ ('..', os.path.join( @@ -2013,15 +2014,9 @@ def test_add_existing_real_directory_symlink_target_path(self): real_directory, 'fixtures', 'symlink_file_relative')), ] - try: - with self.create_symlinks(symlinks): - self.filesystem.add_real_directory( - real_directory, target_path='/path', lazy_read=False) - except OSError: - if self.is_windows: - raise unittest.SkipTest( - 'Symlinks under Windows need admin privileges') - raise + with self.create_symlinks(symlinks): + self.filesystem.add_real_directory( + real_directory, target_path='/path', lazy_read=False) self.assertTrue(self.filesystem.exists( '/path/fixtures/symlink_dir_relative')) @@ -2031,6 +2026,7 @@ def test_add_existing_real_directory_symlink_target_path(self): '/path/fixtures/symlink_file_relative')) def test_add_existing_real_directory_symlink_lazy_read(self): + self.skip_if_symlink_not_supported() real_directory = os.path.join(self.root_path, 'pyfakefs', 'tests') symlinks = [ ('..', os.path.join( @@ -2039,22 +2035,16 @@ def test_add_existing_real_directory_symlink_lazy_read(self): real_directory, 'fixtures', 'symlink_file_relative')), ] - try: - with self.create_symlinks(symlinks): - self.filesystem.add_real_directory( - real_directory, target_path='/path', lazy_read=True) - - self.assertTrue(self.filesystem.exists( - '/path/fixtures/symlink_dir_relative')) - self.assertTrue(self.filesystem.exists( - '/path/fixtures/symlink_dir_relative/all_tests.py')) - self.assertTrue(self.filesystem.exists( - '/path/fixtures/symlink_file_relative')) - except OSError: - if self.is_windows: - raise unittest.SkipTest( - 'Symlinks under Windows need admin privileges') - raise + with self.create_symlinks(symlinks): + self.filesystem.add_real_directory( + real_directory, target_path='/path', lazy_read=True) + + self.assertTrue(self.filesystem.exists( + '/path/fixtures/symlink_dir_relative')) + self.assertTrue(self.filesystem.exists( + '/path/fixtures/symlink_dir_relative/all_tests.py')) + self.assertTrue(self.filesystem.exists( + '/path/fixtures/symlink_file_relative')) def test_add_existing_real_directory_tree_to_existing_path(self): self.filesystem.create_dir('/foo/bar') diff --git a/pyfakefs/tests/fake_filesystem_vs_real_test.py b/pyfakefs/tests/fake_filesystem_vs_real_test.py index 756d7cdc..c2835c3f 100644 --- a/pyfakefs/tests/fake_filesystem_vs_real_test.py +++ b/pyfakefs/tests/fake_filesystem_vs_real_test.py @@ -23,6 +23,7 @@ import unittest from pyfakefs import fake_filesystem +from pyfakefs.helpers import IS_PYPY def sep(path): @@ -337,14 +338,12 @@ def assertAllOsBehaviorsMatch(self, path): path = sep(path) os_method_names = [] if self.is_windows else ['readlink'] os_method_names_no_args = ['getcwd'] - os_path_method_names = ['isabs', - 'isdir', - 'isfile', - 'exists' - ] + os_path_method_names = ['isabs', 'isdir'] if not self.is_windows: - os_path_method_names.append('islink') - os_path_method_names.append('lexists') + os_path_method_names += ['islink', 'lexists'] + if not self.is_windows or not IS_PYPY: + os_path_method_names += ['isfile', 'exists'] + wrapped_methods = [ ['access', self._access_real, self._access_fake], ['stat.size', self._stat_size_real, self._stat_size_fake], diff --git a/pyfakefs/tests/fake_os_test.py b/pyfakefs/tests/fake_os_test.py index 00006e74..7644fd61 100644 --- a/pyfakefs/tests/fake_os_test.py +++ b/pyfakefs/tests/fake_os_test.py @@ -184,7 +184,7 @@ def test_fdopen(self): def test_out_of_range_fdopen(self): # test some file descriptor that is clearly out of range - self.assert_raises_os_error(errno.EBADF, self.os.fdopen, 100) + self.assert_raises_os_error(errno.EBADF, self.os.fdopen, 500) def test_closed_file_descriptor(self): first_path = self.make_path('some_file1') @@ -1753,13 +1753,13 @@ def test_fdatasync_raises_on_non_int(self): self.assertRaises(TypeError, self.os.fdatasync, "zero") def test_fsync_raises_on_invalid_fd(self): - self.assert_raises_os_error(errno.EBADF, self.os.fsync, 100) + self.assert_raises_os_error(errno.EBADF, self.os.fsync, 500) def test_fdatasync_raises_on_invalid_fd(self): # No open files yet self.check_linux_only() self.assert_raises_os_error(errno.EINVAL, self.os.fdatasync, 0) - self.assert_raises_os_error(errno.EBADF, self.os.fdatasync, 100) + self.assert_raises_os_error(errno.EBADF, self.os.fdatasync, 500) def test_fsync_pass_posix(self): self.check_posix_only() @@ -3060,6 +3060,8 @@ def test_rename_dir_to_existing_dir(self): # Regression test for #317 self.check_posix_only() dest_dir_path = self.make_path('Dest') + # seems to behave differently under different MacOS versions + self.skip_real_fs() new_dest_dir_path = self.make_path('dest') self.os.mkdir(dest_dir_path) source_dir_path = self.make_path('src') @@ -4676,6 +4678,7 @@ def test_symlink(self): self.assertTrue(self.os.path.exists('/bat')) def test_readlink(self): + self.skip_if_symlink_not_supported() self.filesystem.create_symlink('/meyer/lemon/pie', '/foo/baz') self.filesystem.create_symlink('/geo/metro', '/meyer') self.assertRaises( diff --git a/pyfakefs/tests/fake_pathlib_test.py b/pyfakefs/tests/fake_pathlib_test.py index 0d96ca79..ec64c903 100644 --- a/pyfakefs/tests/fake_pathlib_test.py +++ b/pyfakefs/tests/fake_pathlib_test.py @@ -401,11 +401,10 @@ def test_resolve(self): self.create_file(self.make_path('antoine', 'setup.py')) self.os.chdir(self.make_path('antoine')) # use real path to handle symlink /var to /private/var in MacOs - self.assertEqual(self.path().resolve(), - self.path( - self.os.path.realpath( - self.make_path('antoine')))) - self.assertEqual( + self.assert_equal_paths(self.path().resolve(), + self.path(self.os.path.realpath( + self.make_path('antoine')))) + self.assert_equal_paths( self.path( self.os.path.join('docs', '..', 'setup.py')).resolve(), self.path( @@ -469,8 +468,8 @@ def test_cwd(self): dir_path = self.make_path('jane') self.create_dir(dir_path) self.os.chdir(dir_path) - self.assertEqual(self.path.cwd(), - self.path(self.os.path.realpath(dir_path))) + self.assert_equal_paths(self.path.cwd(), + self.path(self.os.path.realpath(dir_path))) def test_expanduser(self): if is_windows: @@ -868,7 +867,7 @@ def test_chdir(self): self.create_dir(path) self.os.chdir(self.path(path)) # use real path to handle symlink /var to /private/var in MacOs - self.assertEqual(self.os.path.realpath(path), self.os.getcwd()) + self.assert_equal_paths(self.os.path.realpath(path), self.os.getcwd()) def test_chmod(self): path = self.make_path('some_file') diff --git a/pyfakefs/tests/test_utils.py b/pyfakefs/tests/test_utils.py index a40f01f0..b4f5d8c6 100644 --- a/pyfakefs/tests/test_utils.py +++ b/pyfakefs/tests/test_utils.py @@ -66,16 +66,6 @@ def assert_raises_os_error(self, subtype, expression, *args, **kwargs): else: self.assertEqual(subtype, exc.errno) - def assert_equal_paths(self, actual, expected): - if self.is_windows: - self.assertEqual(actual.replace('\\\\?\\', ''), - expected.replace('\\\\?\\', '')) - elif self.is_macos: - self.assertEqual(actual.replace('/private/var/', '/var/'), - expected.replace('/private/var/', '/var/')) - else: - self.assertEqual(actual, expected) - class RealFsTestMixin: """Test mixin to allow tests to run both in the fake filesystem and in the @@ -350,6 +340,29 @@ def create_basepath(self): if old_base_path is not None: self.setUpFileSystem() + def assert_equal_paths(self, actual, expected): + if self.is_windows: + actual = str(actual).replace('\\\\?\\', '') + expected = str(expected).replace('\\\\?\\', '') + if os.name == 'nt' and self.use_real_fs(): + # work around a problem that the user name, but not the full + # path is shown as the short name + self.assertEqual(self.path_with_short_username(actual), + self.path_with_short_username(expected)) + else: + self.assertEqual(actual, expected) + elif self.is_macos: + self.assertEqual(str(actual).replace('/private/var/', '/var/'), + str(expected).replace('/private/var/', '/var/')) + else: + self.assertEqual(actual, expected) + + def path_with_short_username(self, path): + components = path.split(os.sep) + if len(components) >= 3: + components[2] = components[2][:6].upper() + '~1' + return os.sep.join(components) + class RealFsTestCase(TestCase, RealFsTestMixin): """Can be used as base class for tests also running in the real