Permalink
Browse files

Moved tests into package to conform with standard package structure

- adapted tests
- fixed bug in add_real_directory for nested paths
  • Loading branch information...
mrbean-bremen committed Apr 25, 2018
1 parent ea2fa1d commit 99029d88065b3fbbe95226008b54e6ef16b92bf6
View
@@ -4,4 +4,4 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
source ~/.venv/bin/activate
fi
py.test tests/pytest_plugin_test.py
python -m pytest pyfakefs/tests/pytest_plugin_test.py
View
@@ -10,11 +10,11 @@ pip install flake8
EXCLUDES='--exclude get-pip.py'
if [[ $PYTHON == 'py27' ]] || [[ $PYTHON == 'pypy2' ]]; then
EXCLUDES=$EXCLUDES',pyfakefs/fake_pathlib.py,tests/fake_pathlib_test.py'
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 tests.all_tests
python -m pyfakefs.tests.all_tests
View
@@ -6,8 +6,10 @@ The release versions are PyPi releases.
#### New Features
#### Infrastructure
* moved tests into package
#### Fixes
* `add_real_directory` did not behave correctly for nested paths
* several fixes for the behavior if using file paths that end with a path
separator:
* `os.exists` returned `True` instead of `False` ([#364](../../issues/364))
View
@@ -70,8 +70,8 @@ pyfakefs is currently automatically tested:
pyfakefs unit tests are available via two test scripts:
```bash
$ python -m tests.all_tests
$ py.test tests/pytest_plugin_test.py
$ python -m pyfakefs.tests.all_tests
$ python -m pytest pyfakefs/tests/pytest_plugin_test.py
```
These scripts are called by `tox` and Travis-CI. `tox` can be used to run tests
View
@@ -13,6 +13,6 @@ install:
build: off
test_script:
- "%PYTHON%\\python.exe -m tests.all_tests"
- "%PYTHON%\\Scripts\\py.test.exe tests\\pytest_plugin_test.py"
- "%PYTHON%\\python.exe -m pyfakefs.tests.all_tests"
- "%PYTHON%\\python.exe -m pytest pyfakefs\\tests\\pytest_plugin_test.py"
@@ -2303,8 +2303,9 @@ def add_real_directory(self, source_path, read_only=True, lazy_read=True,
new_dir.st_ino = self._last_ino
else:
new_dir = self.create_dir(target_path)
new_base = new_dir.path
for base, _, files in os.walk(source_path):
new_base = os.path.join(new_dir.path,
os.path.relpath(base, source_path))
for fileEntry in files:
self.add_real_file(os.path.join(base, fileEntry),
read_only,
File renamed without changes.
@@ -19,20 +19,20 @@
import sys
import unittest
from tests import dynamic_patch_test
from tests import fake_open_test
from tests import fake_os_test
from tests import example_test
from tests import fake_filesystem_glob_test
from tests import fake_filesystem_shutil_test
from tests import fake_filesystem_test
from tests import fake_filesystem_unittest_test
from tests import fake_tempfile_test
from tests import fake_filesystem_vs_real_test
from tests import mox3_stubout_test
from pyfakefs.tests import dynamic_patch_test
from pyfakefs.tests import fake_open_test
from pyfakefs.tests import fake_os_test
from pyfakefs.tests import example_test
from pyfakefs.tests import fake_filesystem_glob_test
from pyfakefs.tests import fake_filesystem_shutil_test
from pyfakefs.tests import fake_filesystem_test
from pyfakefs.tests import fake_filesystem_unittest_test
from pyfakefs.tests import fake_tempfile_test
from pyfakefs.tests import fake_filesystem_vs_real_test
from pyfakefs.tests import mox3_stubout_test
if sys.version_info >= (3, 4):
from tests import fake_pathlib_test
from pyfakefs.tests import fake_pathlib_test
class AllTests(unittest.TestSuite):
File renamed without changes.
File renamed without changes.
@@ -35,7 +35,7 @@
from pyfakefs import fake_filesystem_unittest
from pyfakefs.fake_filesystem_unittest import has_scandir
from tests import example # The module under test
from pyfakefs.tests import example # The module under test
def load_tests(loader, tests, ignore):
@@ -25,7 +25,7 @@
import unittest
from pyfakefs import fake_filesystem_unittest
from tests.test_utils import RealFsTestMixin
from pyfakefs.tests.test_utils import RealFsTestMixin
is_windows = sys.platform == 'win32'
@@ -24,7 +24,7 @@
import unittest
from pyfakefs import fake_filesystem
from tests.test_utils import DummyTime, TestCase
from pyfakefs.tests.test_utils import DummyTime, TestCase
class FakeDirectoryUnitTest(TestCase):
@@ -1337,9 +1337,8 @@ def test_normalize_case_for_non_existing_file(self):
def test_normalize_case_for_lazily_added_empty_file(self):
# regression test for specific issue with added empty real files
filesystem = fake_filesystem.FakeFilesystem()
root_path = os.path.split(
real_dir_path = os.path.split(
os.path.dirname(os.path.abspath(__file__)))[0]
real_dir_path = os.path.join(root_path, 'pyfakefs')
filesystem.add_real_directory(real_dir_path)
initPyPath = os.path.join(real_dir_path, '__init__.py')
self.assertEqual(initPyPath,
@@ -1793,8 +1792,9 @@ def setUp(self):
# use the real path separator to work with the real file system
self.filesystem = fake_filesystem.FakeFilesystem()
self.fake_open = fake_filesystem.FakeFileOpen(self.filesystem)
self.root_path = os.path.split(
self.pyfakefs_path = os.path.split(
os.path.dirname(os.path.abspath(__file__)))[0]
self.root_path = os.path.split(self.pyfakefs_path)[0]
def test_add_non_existing_real_file_raises(self):
nonexisting_path = os.path.join('nonexisting', 'test.txt')
@@ -1893,15 +1893,15 @@ def test_add_real_file_to_non_existing_path(self):
target_path='/foo/bar')
def test_add_existing_real_directory_read_only(self):
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_directory(real_dir_path)
self.assertTrue(self.filesystem.exists(real_dir_path))
self.filesystem.add_real_directory(self.pyfakefs_path)
self.assertTrue(self.filesystem.exists(self.pyfakefs_path))
self.assertTrue(self.filesystem.exists(
os.path.join(real_dir_path, 'fake_filesystem.py')))
os.path.join(self.pyfakefs_path, 'fake_filesystem.py')))
self.assertTrue(self.filesystem.exists(
os.path.join(real_dir_path, 'fake_pathlib.py')))
os.path.join(self.pyfakefs_path, 'fake_pathlib.py')))
file_path = os.path.join(real_dir_path, 'fake_filesystem_shutil.py')
file_path = os.path.join(self.pyfakefs_path,
'fake_filesystem_shutil.py')
fake_file = self.filesystem.resolve(file_path)
self.check_fake_file_stat(fake_file, file_path)
self.check_read_only_file(fake_file, file_path)
@@ -1910,7 +1910,7 @@ def test_add_existing_real_directory_tree(self):
self.filesystem.add_real_directory(self.root_path)
self.assertTrue(
self.filesystem.exists(
os.path.join(self.root_path, 'tests',
os.path.join(self.root_path, 'pyfakefs', 'tests',
'fake_filesystem_test.py')))
self.assertTrue(
self.filesystem.exists(
@@ -1932,11 +1932,11 @@ def test_add_existing_real_directory_tree_to_other_path(self):
target_path='/foo/bar')
self.assertFalse(
self.filesystem.exists(
os.path.join(self.root_path, 'tests',
os.path.join(self.pyfakefs_path, 'tests',
'fake_filesystem_test.py')))
self.assertTrue(
self.filesystem.exists(
os.path.join('foo', 'bar', 'tests',
os.path.join('foo', 'bar', 'pyfakefs', 'tests',
'fake_filesystem_test.py')))
self.assertFalse(
self.filesystem.exists(
@@ -1975,55 +1975,54 @@ def test_add_existing_real_directory_lazily(self):
def test_add_existing_real_directory_not_lazily(self):
disk_size = 1024 * 1024 * 1024
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.set_disk_usage(disk_size, real_dir_path)
self.filesystem.add_real_directory(real_dir_path, lazy_read=False)
self.filesystem.set_disk_usage(disk_size, self.pyfakefs_path)
self.filesystem.add_real_directory(self.pyfakefs_path, lazy_read=False)
# the directory has been read, so the file sizes have
# been subtracted from the free space
self.assertGreater(disk_size,
self.filesystem.get_disk_usage(real_dir_path).free)
self.assertGreater(disk_size, self.filesystem.get_disk_usage(
self.pyfakefs_path).free)
def test_add_existing_real_directory_read_write(self):
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_directory(real_dir_path, read_only=False)
self.assertTrue(self.filesystem.exists(real_dir_path))
self.filesystem.add_real_directory(self.pyfakefs_path, read_only=False)
self.assertTrue(self.filesystem.exists(self.pyfakefs_path))
self.assertTrue(self.filesystem.exists(
os.path.join(real_dir_path, 'fake_filesystem.py')))
os.path.join(self.pyfakefs_path, 'fake_filesystem.py')))
self.assertTrue(self.filesystem.exists(
os.path.join(real_dir_path, 'fake_pathlib.py')))
os.path.join(self.pyfakefs_path, 'fake_pathlib.py')))
file_path = os.path.join(real_dir_path, 'pytest_plugin.py')
file_path = os.path.join(self.pyfakefs_path, 'pytest_plugin.py')
fake_file = self.filesystem.resolve(file_path)
self.check_fake_file_stat(fake_file, file_path)
self.check_writable_file(fake_file, file_path)
def test_add_existing_real_paths_read_only(self):
real_file_path = os.path.realpath(__file__)
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_paths([real_file_path, real_dir_path])
fixture_path = os.path.join(self.pyfakefs_path, 'tests', 'fixtures')
self.filesystem.add_real_paths([real_file_path, fixture_path])
fake_file = self.filesystem.resolve(real_file_path)
self.check_fake_file_stat(fake_file, real_file_path)
self.check_read_only_file(fake_file, real_file_path)
real_file_path = os.path.join(real_dir_path,
'fake_filesystem_shutil.py')
real_file_path = os.path.join(fixture_path,
'module_with_attributes.py')
fake_file = self.filesystem.resolve(real_file_path)
self.check_fake_file_stat(fake_file, real_file_path)
self.check_read_only_file(fake_file, real_file_path)
def test_add_existing_real_paths_read_write(self):
real_file_path = os.path.realpath(__file__)
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_paths([real_file_path, real_dir_path],
fixture_path = os.path.join(self.pyfakefs_path, 'tests', 'fixtures')
self.filesystem.add_real_paths([real_file_path, fixture_path],
read_only=False)
fake_file = self.filesystem.resolve(real_file_path)
self.check_fake_file_stat(fake_file, real_file_path)
self.check_writable_file(fake_file, real_file_path)
real_file_path = os.path.join(real_dir_path, 'fake_pathlib.py')
real_file_path = os.path.join(fixture_path,
'module_with_attributes.py')
fake_file = self.filesystem.resolve(real_file_path)
self.check_fake_file_stat(fake_file, real_file_path)
self.check_writable_file(fake_file, real_file_path)
@@ -30,8 +30,8 @@
from pyfakefs import fake_filesystem_unittest, fake_filesystem
from pyfakefs.fake_filesystem_unittest import Patcher
import tests.import_as_example
from tests.fixtures import module_with_attributes
import pyfakefs.tests.import_as_example
from pyfakefs.tests.fixtures import module_with_attributes
if sys.version_info >= (3, 4):
import pathlib
@@ -141,7 +141,7 @@ def test_fakepathlib(self):
class TestImportAsOtherName(fake_filesystem_unittest.TestCase):
def __init__(self, methodName='RunTest'):
modules_to_load = [tests.import_as_example]
modules_to_load = [pyfakefs.tests.import_as_example]
super(TestImportAsOtherName, self).__init__(
methodName, modules_to_reload=modules_to_load)
@@ -152,7 +152,7 @@ def test_file_exists(self):
file_path = '/foo/bar/baz'
self.fs.create_file(file_path)
self.assertTrue(self.fs.exists(file_path))
self.assertTrue(tests.import_as_example.check_if_exists(file_path))
self.assertTrue(pyfakefs.tests.import_as_example.check_if_exists(file_path))
class TestAttributesWithFakeModuleNames(TestPyfakefsUnittestBase):
@@ -232,7 +232,7 @@ def test_path_exists(self):
file_path = '/foo/bar'
self.fs.create_dir(file_path)
self.assertTrue(
tests.import_as_example.check_if_path_exists(file_path))
pyfakefs.tests.import_as_example.check_if_path_exists(file_path))
class PatchAsOtherNameTest(TestPyfakefsUnittestBase):
@@ -248,7 +248,7 @@ def test_path_exists(self):
file_path = '/foo/bar'
self.fs.create_dir(file_path)
self.assertTrue(
tests.import_as_example.check_if_exists(file_path))
pyfakefs.tests.import_as_example.check_if_exists(file_path))
class TestCopyOrAddRealFile(TestPyfakefsUnittestBase):
@@ -331,8 +331,7 @@ def test_add_real_directory(self):
# fake_filesystem_test.RealFileSystemAccessTest.
# Note: this test fails (add_real_directory raises) if 'genericpath'
# is not added to SKIPNAMES
root_path = os.path.split(os.path.dirname(self.filepath))[0]
real_dir_path = os.path.join(root_path, 'pyfakefs')
real_dir_path = os.path.split(os.path.dirname(self.filepath))[0]
self.fs.add_real_directory(real_dir_path)
self.assertTrue(self.fs.exists(real_dir_path))
self.assertTrue(self.fs.exists(
@@ -27,7 +27,7 @@
import unittest
from pyfakefs import fake_filesystem
from tests.test_utils import DummyTime, TestCase, RealFsTestCase
from pyfakefs.tests.test_utils import DummyTime, TestCase, RealFsTestCase
class FakeFileOpenTestBase(RealFsTestCase):
@@ -28,7 +28,7 @@
from pyfakefs.fake_filesystem import FakeFileOpen
from pyfakefs.fake_filesystem_unittest import has_scandir
from tests.test_utils import DummyTime, TestCase, RealFsTestCase
from pyfakefs.tests.test_utils import DummyTime, TestCase, RealFsTestCase
class FakeOsModuleTestBase(RealFsTestCase):
@@ -28,7 +28,7 @@
import unittest
from pyfakefs import fake_pathlib
from tests.test_utils import RealFsTestCase
from pyfakefs.tests.test_utils import RealFsTestCase
is_windows = sys.platform == 'win32'
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -19,7 +19,7 @@
from os import path
from pyfakefs import mox3_stubout
from tests import mox3_stubout_example
from pyfakefs.tests import mox3_stubout_example
class NoPanicMath(object):
File renamed without changes.
File renamed without changes.
View
@@ -5,5 +5,5 @@ envlist=py27,py33,py34,py35,py36,py37,pypy
deps = -rrequirements.txt
passenv = HOME USERPROFILE
commands=
python -m tests.all_tests
py.test tests/pytest_plugin_test.py
python -m pyfakefs.tests.all_tests
python -m pytest pyfakefs/tests/pytest_plugin_test.py

0 comments on commit 99029d8

Please sign in to comment.