Permalink
Browse files

Moved tests to separate directory

- better conforms to Python conventions
- avoid clutter in root path
  • Loading branch information...
mrbean-bremen committed Dec 23, 2017
1 parent 09632f9 commit ec6ce30430b3cc8df4613d95e7faa9762b263a66
View
@@ -4,4 +4,4 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
source ~/.venv/bin/activate
fi
py.test pytest_plugin_test.py
py.test tests/pytest_plugin_test.py
View
@@ -5,4 +5,4 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
fi
python --version
python ./all_tests.py
python -m tests.all_tests
View
@@ -13,6 +13,6 @@ install:
build: off
test_script:
- "%PYTHON%\\python.exe all_tests.py"
- "%PYTHON%\\Scripts\\py.test.exe pytest_plugin_test.py"
- "%PYTHON%\\python.exe -m tests.all_tests"
- "%PYTHON%\\Scripts\\py.test.exe tests\\pytest_plugin_test.py"
@@ -1,6 +1,6 @@
"""A pytest plugin for using pyfakefs as a fixture
When pyfakefs is installed, the "fs" fixture becomes avaialable.
When pyfakefs is installed, the "fs" fixture becomes available.
:Usage:
File renamed without changes.
View
@@ -16,21 +16,21 @@
"""A test suite that runs all tests for pyfakefs at once."""
import unittest
import sys
import unittest
import dynamic_patch_test
import fake_filesystem_glob_test
import fake_filesystem_shutil_test
import fake_filesystem_test
import fake_filesystem_vs_real_test
import fake_tempfile_test
import fake_filesystem_unittest_test
import example_test
import mox3_stubout_test
from tests import dynamic_patch_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
if sys.version_info >= (3, 4):
import fake_pathlib_test
from tests import fake_pathlib_test
class AllTests(unittest.TestSuite):
File renamed without changes.
File renamed without changes.
@@ -34,9 +34,10 @@
from pyfakefs import fake_filesystem_unittest
from pyfakefs.fake_filesystem_unittest import has_scandir
from tests import example
# The module under test is pyfakefs/example
import example
def load_tests(loader, tests, ignore):
@@ -64,7 +65,8 @@ def setUp(self):
"""
# This is before setUpPyfakefs(), so still using the real file system
with io.open(__file__, 'rb') as f:
self.filepath = os.path.realpath(__file__)
with io.open(self.filepath, 'rb') as f:
self.real_contents = f.read()
self.setUpPyfakefs()
@@ -166,11 +168,10 @@ def test_scandir_scandir(self):
def test_real_file_access(self):
"""Test `example.file_contents()` for a real file after adding it using
`add_real_file()`."""
filename = __file__
with self.assertRaises(IOError):
example.file_contents(filename)
self.fs.add_real_file(filename)
self.assertEqual(example.file_contents(filename), self.real_contents)
example.file_contents(self.filepath)
self.fs.add_real_file(self.filepath)
self.assertEqual(example.file_contents(self.filepath), self.real_contents)
if __name__ == "__main__":
File renamed without changes.
@@ -24,8 +24,8 @@
import sys
import unittest
from fake_filesystem_test import RealFsTestMixin
from pyfakefs import fake_filesystem_unittest
from tests.fake_filesystem_test import RealFsTestMixin
class RealFsTestCase(fake_filesystem_unittest.TestCase, RealFsTestMixin):
@@ -34,6 +34,7 @@ def __init__(self, methodName='runTest'):
RealFsTestMixin.__init__(self)
def setUp(self):
self.cwd = os.getcwd()
if not self.use_real_fs():
self.setUpPyfakefs()
self.filesystem = self.fs
@@ -46,6 +47,7 @@ def tearDown(self):
if self.use_real_fs():
self.os.chdir(os.path.dirname(self.base_path))
shutil.rmtree(self.base_path, ignore_errors=True)
os.chdir(self.cwd)
@property
def is_windows_fs(self):
@@ -269,6 +269,7 @@ def __init__(self, methodName='runTest'):
RealFsTestMixin.__init__(self)
def setUp(self):
self.cwd = os.getcwd()
if not self.use_real_fs():
self.filesystem = fake_filesystem.FakeFilesystem(
path_separator=self.path_separator())
@@ -292,6 +293,7 @@ def tearDown(self):
if self.use_real_fs():
self.os.chdir(os.path.dirname(self.base_path))
shutil.rmtree(self.base_path, ignore_errors=True)
self.os.chdir(self.cwd)
class FakeDirectoryUnitTest(TestCase):
@@ -7029,7 +7031,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()
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
root_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,
@@ -7483,6 +7486,7 @@ 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(os.path.dirname(os.path.abspath(__file__)))[0]
def test_add_non_existing_real_file_raises(self):
nonexisting_path = os.path.join('nonexisting', 'test.txt')
@@ -7504,11 +7508,10 @@ def test_existing_fake_file_raises(self):
real_file_path)
def test_existing_fake_directory_raises(self):
real_dir_path = os.path.dirname(__file__)
self.filesystem.create_dir(real_dir_path)
self.filesystem.create_dir(self.root_path)
self.assert_raises_os_error(errno.EEXIST,
self.filesystem.add_real_directory,
real_dir_path)
self.root_path)
def check_fake_file_stat(self, fake_file, real_file_path):
self.assertTrue(self.filesystem.exists(real_file_path))
@@ -7545,7 +7548,7 @@ def check_writable_file(self, fake_file, real_file_path):
self.assertEqual(fake_contents, b'test')
def test_add_existing_real_file_read_only(self):
real_file_path = __file__
real_file_path = os.path.abspath(__file__)
fake_file = self.filesystem.add_real_file(real_file_path)
self.check_fake_file_stat(fake_file, real_file_path)
self.assertEqual(fake_file.st_mode & 0o333, 0)
@@ -7561,7 +7564,7 @@ def test_add_existing_real_file_read_write(self):
self.check_writable_file(fake_file, real_file_path)
def test_add_existing_real_directory_read_only(self):
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
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.assertTrue(self.filesystem.exists(
@@ -7575,31 +7578,29 @@ def test_add_existing_real_directory_read_only(self):
self.check_read_only_file(fake_file, file_path)
def test_add_existing_real_directory_tree(self):
real_dir_path = os.path.dirname(__file__)
self.filesystem.add_real_directory(real_dir_path)
self.filesystem.add_real_directory(self.root_path)
self.assertTrue(
self.filesystem.exists(
os.path.join(real_dir_path, 'fake_filesystem_test.py')))
os.path.join(self.root_path, 'tests', 'fake_filesystem_test.py')))
self.assertTrue(
self.filesystem.exists(
os.path.join(real_dir_path, 'pyfakefs', 'fake_filesystem.py')))
os.path.join(self.root_path, 'pyfakefs', 'fake_filesystem.py')))
self.assertTrue(
self.filesystem.exists(
os.path.join(real_dir_path, 'pyfakefs', '__init__.py')))
os.path.join(self.root_path, 'pyfakefs', '__init__.py')))
def test_get_object_from_lazily_added_real_directory(self):
self.filesystem.is_case_sensitive = True
real_dir_path = os.path.dirname(__file__)
self.filesystem.add_real_directory(real_dir_path)
self.filesystem.add_real_directory(self.root_path)
self.assertTrue(self.filesystem.get_object(
os.path.join(real_dir_path, 'pyfakefs', 'fake_filesystem.py')))
os.path.join(self.root_path, 'pyfakefs', 'fake_filesystem.py')))
self.assertTrue(
self.filesystem.get_object(
os.path.join(real_dir_path, 'pyfakefs', '__init__.py')))
os.path.join(self.root_path, 'pyfakefs', '__init__.py')))
def test_add_existing_real_directory_lazily(self):
disk_size = 1024 * 1024 * 1024
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
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)
@@ -7617,7 +7618,7 @@ 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(os.path.dirname(__file__), 'pyfakefs')
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)
@@ -7627,7 +7628,7 @@ def test_add_existing_real_directory_not_lazily(self):
self.filesystem.get_disk_usage(real_dir_path).free)
def test_add_existing_real_directory_read_write(self):
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
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.assertTrue(self.filesystem.exists(
@@ -7642,7 +7643,7 @@ def test_add_existing_real_directory_read_write(self):
def test_add_existing_real_paths_read_only(self):
real_file_path = os.path.realpath(__file__)
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_paths([real_file_path, real_dir_path])
fake_file = self.filesystem.resolve(real_file_path)
@@ -7657,7 +7658,7 @@ def test_add_existing_real_paths_read_only(self):
def test_add_existing_real_paths_read_write(self):
real_file_path = os.path.realpath(__file__)
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
real_dir_path = os.path.join(self.root_path, 'pyfakefs')
self.filesystem.add_real_paths([real_file_path, real_dir_path],
read_only=False)
@@ -19,17 +19,17 @@
"""
Test the :py:class`pyfakefs.fake_filesystem_unittest.TestCase` base class.
"""
import glob
import io
import os
import glob
import shutil
import sys
import unittest
from unittest import TestCase
from import_as_example import check_if_exists
from pyfakefs.fake_filesystem_unittest import Patcher
from pyfakefs import fake_filesystem_unittest
from pyfakefs.fake_filesystem_unittest import Patcher
from tests.import_as_example import check_if_exists
if sys.version_info >= (3, 4):
import pathlib
@@ -135,7 +135,7 @@ def test_fakepathlib(self):
class TestImportAsOtherName(fake_filesystem_unittest.TestCase):
def __init__(self, methodName='RunTest'):
special_names = {'import_as_example': {'os': '_os'}}
special_names = {'tests.import_as_example': {'os': '_os'}}
super(TestImportAsOtherName, self).__init__(methodName,
special_names=special_names)
@@ -148,8 +148,8 @@ def test_file_exists(self):
self.assertTrue(self.fs.exists(file_path))
self.assertTrue(check_if_exists(file_path))
sys.path.append(os.path.join(os.path.dirname(__file__), 'fixtures'))
import module_with_attributes
from tests.fixtures import module_with_attributes
class TestAttributesWithFakeModuleNames(TestPyfakefsUnittestBase):
@@ -203,21 +203,22 @@ class TestCopyOrAddRealFile(TestPyfakefsUnittestBase):
Note that `copyRealFile()` is deprecated in favor of
`FakeFilesystem.add_real_file()`.
"""
filepath = None
@classmethod
def setUpClass(cls):
with open(__file__) as f:
cls.filepath = os.path.abspath(__file__)
with open(cls.filepath) as f:
cls.real_string_contents = f.read()
with open(__file__, 'rb') as f:
with open(cls.filepath, 'rb') as f:
cls.real_byte_contents = f.read()
cls.real_stat = os.stat(__file__)
cls.real_stat = os.stat(cls.filepath)
@unittest.skipIf(sys.platform == 'darwin', 'Different copy behavior')
def test_copy_real_file(self):
'''Typical usage of deprecated copyRealFile()'''
# Use this file as the file to be copied to the fake file system
real_file_path = os.path.realpath(__file__)
fake_file = self.copyRealFile(real_file_path)
fake_file = self.copyRealFile(self.filepath)
self.assertTrue('class TestCopyOrAddRealFile(TestPyfakefsUnittestBase)'
in self.real_string_contents,
@@ -240,26 +241,24 @@ def test_copy_real_file(self):
def test_copy_real_file_deprecated_arguments(self):
'''Deprecated copyRealFile() arguments'''
real_file_path = __file__
self.assertFalse(self.fs.exists(real_file_path))
self.assertFalse(self.fs.exists(self.filepath))
# Specify redundant fake file path
self.copyRealFile(real_file_path, real_file_path)
self.assertTrue(self.fs.exists(real_file_path))
self.copyRealFile(self.filepath, self.filepath)
self.assertTrue(self.fs.exists(self.filepath))
# Test deprecated argument values
with self.assertRaises(ValueError):
self.copyRealFile(real_file_path, '/different/filename')
self.copyRealFile(self.filepath, '/different/filename')
with self.assertRaises(ValueError):
self.copyRealFile(real_file_path, create_missing_dirs=False)
self.copyRealFile(self.filepath, create_missing_dirs=False)
def test_add_real_file(self):
'''Add a real file to the fake file system to be read on demand'''
# this tests only the basic functionality inside a unit test, more thorough tests
# are done in fake_filesystem_test.RealFileSystemAccessTest
real_file_path = __file__
fake_file = self.fs.add_real_file(real_file_path)
self.assertTrue(self.fs.exists(real_file_path))
fake_file = self.fs.add_real_file(self.filepath)
self.assertTrue(self.fs.exists(self.filepath))
self.assertIsNone(fake_file._byte_contents)
self.assertEqual(self.real_byte_contents, fake_file.byte_contents)
@@ -269,7 +268,8 @@ def test_add_real_directory(self):
# this tests only the basic functionality inside a unit test, more thorough tests
# are done in fake_filesystem_test.RealFileSystemAccessTest
# Note: this test fails (add_real_directory raises) if 'genericpath' is not added to SKIPNAMES
real_dir_path = os.path.join(os.path.dirname(__file__), 'pyfakefs')
root_path = os.path.split(os.path.dirname(self.filepath))[0]
real_dir_path = os.path.join(root_path, 'pyfakefs')
self.fs.add_real_directory(real_dir_path)
self.assertTrue(self.fs.exists(real_dir_path))
self.assertTrue(self.fs.exists(os.path.join(real_dir_path, 'fake_filesystem.py')))
@@ -89,6 +89,7 @@ def setUp(self):
# so that missing features in the fake don't fall through to the base
# operations and magically succeed.
tsname = 'fakefs.%s' % time.time()
self.cwd = os.getcwd()
# Fully expand the base_path - required on OS X.
self.real_base = os.path.realpath(
os.path.join(tempfile.gettempdir(), tsname))
@@ -134,6 +135,7 @@ def tearDown(self):
self.fake_os.remove(fake_path)
finally:
shutil.rmtree(self.real_base)
os.chdir(self.cwd)
def _GetErrno(self, raised_error):
try:
Oops, something went wrong.

0 comments on commit ec6ce30

Please sign in to comment.