aboutsummaryrefslogtreecommitdiff
path: root/pyfakefs
diff options
context:
space:
mode:
authormrbean-bremen <hansemrbean@googlemail.com>2022-10-07 22:49:44 +0200
committermrbean-bremen <mrbean-bremen@users.noreply.github.com>2022-10-08 12:27:56 +0200
commitdc906c93cbc05cf32ee7bff0ab4462668cfc3953 (patch)
tree1722ced2b606ddde9736ec8257976fad902c5195 /pyfakefs
parent7e2e60d6ac0e11504b17cb5b6d4061a2a8397fb6 (diff)
downloadpyfakefs-dc906c93cbc05cf32ee7bff0ab4462668cfc3953.tar.gz
Remove long deprecated old API
- also removed deprecated copyRealFile method - will be released as version 5.0.0
Diffstat (limited to 'pyfakefs')
-rw-r--r--pyfakefs/deprecator.py69
-rw-r--r--pyfakefs/fake_filesystem.py135
-rw-r--r--pyfakefs/fake_filesystem_unittest.py47
3 files changed, 2 insertions, 249 deletions
diff --git a/pyfakefs/deprecator.py b/pyfakefs/deprecator.py
deleted file mode 100644
index 99d0ae6..0000000
--- a/pyfakefs/deprecator.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# 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.
-"""Utilities for handling deprecated functions."""
-
-import functools
-import warnings
-
-
-class Deprecator(object):
- """Decorator class for adding deprecated functions.
-
- Warnings are switched on by default.
- To disable deprecation warnings, use:
-
- >>> from pyfakefs.deprecator import Deprecator
- >>>
- >>> Deprecator.show_warnings = False
- """
-
- show_warnings = True
-
- def __init__(self, use_instead=None, func_name=None):
- self.use_instead = use_instead
- self.func_name = func_name
-
- def __call__(self, func):
- """Decorator to mark functions as deprecated. Emit warning
- when the function is used."""
-
- @functools.wraps(func)
- def _new_func(*args, **kwargs):
- if self.show_warnings:
- with warnings.catch_warnings():
- warnings.simplefilter('always', DeprecationWarning)
- message = ''
- if self.use_instead is not None:
- message = 'Use {} instead.'.format(self.use_instead)
- warnings.warn('Call to deprecated function {}. {}'.format(
- self.func_name or func.__name__, message),
- category=DeprecationWarning, stacklevel=2)
- return func(*args, **kwargs)
-
- return _new_func
-
- @staticmethod
- def add(clss, func, deprecated_name):
- """Add the deprecated version of a member function to the given class.
- Gives a deprecation warning on usage.
-
- Args:
- clss: the class where the deprecated function is to be added
- func: the actual function that is called by the deprecated version
- deprecated_name: the deprecated name of the function
- """
-
- @Deprecator(func.__name__, deprecated_name)
- def _old_function(*args, **kwargs):
- return func(*args, **kwargs)
-
- setattr(clss, deprecated_name, _old_function)
diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py
index 0dd0fdf..7ac0185 100644
--- a/pyfakefs/fake_filesystem.py
+++ b/pyfakefs/fake_filesystem.py
@@ -116,7 +116,6 @@ from typing import (
List, Optional, Callable, Union, Any, Dict, Tuple, cast, AnyStr, overload,
NoReturn, ClassVar, IO, Iterator, TextIO, Type
)
-from pyfakefs.deprecator import Deprecator
from pyfakefs.extra_packages import use_scandir
from pyfakefs.fake_scandir import scandir, walk, ScanDirIter
from pyfakefs.helpers import (
@@ -524,45 +523,6 @@ class FakeFile:
dir_path = sep.join(names)
return self.filesystem.absnormpath(dir_path)
- @Deprecator('property path')
- def GetPath(self):
- return self.path
-
- @Deprecator('property size')
- def GetSize(self):
- return self.size
-
- @Deprecator('property size')
- def SetSize(self, value):
- self.size = value
-
- @Deprecator('property st_atime')
- def SetATime(self, st_atime):
- """Set the self.st_atime attribute.
-
- Args:
- st_atime: The desired access time.
- """
- self.st_atime = st_atime
-
- @Deprecator('property st_mtime')
- def SetMTime(self, st_mtime):
- """Set the self.st_mtime attribute.
-
- Args:
- st_mtime: The desired modification time.
- """
- self.st_mtime = st_mtime
-
- @Deprecator('property st_ctime')
- def SetCTime(self, st_ctime):
- """Set the self.st_ctime attribute.
-
- Args:
- st_ctime: The desired creation time.
- """
- self.st_ctime = st_ctime
-
def __getattr__(self, item: str) -> Any:
"""Forward some properties to stat_result."""
if item in self.stat_types:
@@ -578,18 +538,6 @@ class FakeFile:
def __str__(self) -> str:
return '%r(%o)' % (self.name, self.st_mode)
- @Deprecator('st_ino')
- def SetIno(self, st_ino):
- """Set the self.st_ino attribute.
- Note that a unique inode is assigned automatically to a new fake file.
- This function does not guarantee uniqueness and should be used with
- caution.
-
- Args:
- st_ino: (int) The desired inode.
- """
- self.st_ino = st_ino
-
class FakeNullFile(FakeFile):
def __init__(self, filesystem: "FakeFilesystem") -> None:
@@ -605,11 +553,6 @@ class FakeNullFile(FakeFile):
return False
-Deprecator.add(FakeFile, FakeFile.set_large_file_size, 'SetLargeFileSize')
-Deprecator.add(FakeFile, FakeFile.set_contents, 'SetContents')
-Deprecator.add(FakeFile, FakeFile.is_large_file, 'IsLargeFile')
-
-
class FakeFileFromRealFile(FakeFile):
"""Represents a fake file copied from the real file system.
@@ -790,10 +733,6 @@ class FakeDirectory(FakeFile):
"""Setting the size is an error for a directory."""
raise self.filesystem.raise_os_error(errno.EISDIR, self.path)
- @Deprecator('property size')
- def GetSize(self):
- return self.size
-
def has_parent_object(self, dir_object: "FakeDirectory") -> bool:
"""Return `True` if dir_object is a direct or indirect parent
directory, or if both are the same object."""
@@ -814,12 +753,6 @@ class FakeDirectory(FakeFile):
return description
-Deprecator.add(FakeDirectory, FakeDirectory.add_entry, 'AddEntry')
-Deprecator.add(FakeDirectory, FakeDirectory.get_entry, 'GetEntry')
-Deprecator.add(FakeDirectory, FakeDirectory.set_contents, 'SetContents')
-Deprecator.add(FakeDirectory, FakeDirectory.remove_entry, 'RemoveEntry')
-
-
class FakeDirectoryFromRealDirectory(FakeDirectory):
"""Represents a fake directory copied from the real file system.
@@ -1483,19 +1416,6 @@ class FakeFilesystem:
if ns is not None and len(ns) != 2:
raise TypeError("utime: 'ns' must be a tuple of two ints")
- @Deprecator
- def SetIno(self, path, st_ino):
- """Set the self.st_ino attribute of file at 'path'.
- Note that a unique inode is assigned automatically to a new fake file.
- Using this function does not guarantee uniqueness and should used
- with caution.
-
- Args:
- path: Path to file.
- st_ino: The desired inode.
- """
- self.get_object(path).st_ino = st_ino
-
def _add_open_file(
self,
file_obj: AnyFileWrapper) -> int:
@@ -3446,57 +3366,6 @@ class FakeFilesystem:
self._add_open_file(StandardStreamWrapper(sys.stderr))
-Deprecator.add(FakeFilesystem, FakeFilesystem.get_disk_usage, 'GetDiskUsage')
-Deprecator.add(FakeFilesystem, FakeFilesystem.set_disk_usage, 'SetDiskUsage')
-Deprecator.add(FakeFilesystem,
- FakeFilesystem.change_disk_usage, 'ChangeDiskUsage')
-Deprecator.add(FakeFilesystem, FakeFilesystem.add_mount_point, 'AddMountPoint')
-Deprecator.add(FakeFilesystem, FakeFilesystem.stat, 'GetStat')
-Deprecator.add(FakeFilesystem, FakeFilesystem.chmod, 'ChangeMode')
-Deprecator.add(FakeFilesystem, FakeFilesystem.utime, 'UpdateTime')
-Deprecator.add(FakeFilesystem, FakeFilesystem._add_open_file, 'AddOpenFile')
-Deprecator.add(FakeFilesystem,
- FakeFilesystem._close_open_file, 'CloseOpenFile')
-Deprecator.add(FakeFilesystem, FakeFilesystem.has_open_file, 'HasOpenFile')
-Deprecator.add(FakeFilesystem, FakeFilesystem.get_open_file, 'GetOpenFile')
-Deprecator.add(FakeFilesystem,
- FakeFilesystem.normcase, 'NormalizePathSeparator')
-Deprecator.add(FakeFilesystem, FakeFilesystem.normpath, 'CollapsePath')
-Deprecator.add(FakeFilesystem, FakeFilesystem._original_path, 'NormalizeCase')
-Deprecator.add(FakeFilesystem, FakeFilesystem.absnormpath, 'NormalizePath')
-Deprecator.add(FakeFilesystem, FakeFilesystem.splitpath, 'SplitPath')
-Deprecator.add(FakeFilesystem, FakeFilesystem.splitdrive, 'SplitDrive')
-Deprecator.add(FakeFilesystem, FakeFilesystem.joinpaths, 'JoinPaths')
-Deprecator.add(FakeFilesystem,
- FakeFilesystem._path_components, 'GetPathComponents')
-Deprecator.add(FakeFilesystem, FakeFilesystem.starts_with_drive_letter,
- 'StartsWithDriveLetter')
-Deprecator.add(FakeFilesystem, FakeFilesystem.exists, 'Exists')
-Deprecator.add(FakeFilesystem, FakeFilesystem.resolve_path, 'ResolvePath')
-Deprecator.add(FakeFilesystem, FakeFilesystem.get_object_from_normpath,
- 'GetObjectFromNormalizedPath')
-Deprecator.add(FakeFilesystem, FakeFilesystem.get_object, 'GetObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.resolve, 'ResolveObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.lresolve, 'LResolveObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.add_object, 'AddObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.remove_object, 'RemoveObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.rename, 'RenameObject')
-Deprecator.add(FakeFilesystem, FakeFilesystem.create_dir, 'CreateDirectory')
-Deprecator.add(FakeFilesystem, FakeFilesystem.create_file, 'CreateFile')
-Deprecator.add(FakeFilesystem, FakeFilesystem.create_symlink, 'CreateLink')
-Deprecator.add(FakeFilesystem, FakeFilesystem.link, 'CreateHardLink')
-Deprecator.add(FakeFilesystem, FakeFilesystem.readlink, 'ReadLink')
-Deprecator.add(FakeFilesystem, FakeFilesystem.makedir, 'MakeDirectory')
-Deprecator.add(FakeFilesystem, FakeFilesystem.makedirs, 'MakeDirectories')
-Deprecator.add(FakeFilesystem, FakeFilesystem.isdir, 'IsDir')
-Deprecator.add(FakeFilesystem, FakeFilesystem.isfile, 'IsFile')
-Deprecator.add(FakeFilesystem, FakeFilesystem.islink, 'IsLink')
-Deprecator.add(FakeFilesystem, FakeFilesystem.confirmdir, 'ConfirmDir')
-Deprecator.add(FakeFilesystem, FakeFilesystem.remove, 'RemoveFile')
-Deprecator.add(FakeFilesystem, FakeFilesystem.rmdir, 'RemoveDirectory')
-Deprecator.add(FakeFilesystem, FakeFilesystem.listdir, 'ListDir')
-
-
class FakePathModule:
"""Faked os.path module replacement.
@@ -5744,10 +5613,6 @@ class FakePipeWrapper:
return False
-Deprecator.add(FakeFileWrapper, FakeFileWrapper.get_object, 'GetObject')
-Deprecator.add(FakeFileWrapper, FakeFileWrapper.size, 'Size')
-
-
class FakeFileOpen:
"""Faked `file()` and `open()` function replacements.
diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py
index 6d62ac0..3ccd6ad 100644
--- a/pyfakefs/fake_filesystem_unittest.py
+++ b/pyfakefs/fake_filesystem_unittest.py
@@ -51,15 +51,14 @@ from importlib.abc import Loader, MetaPathFinder
from types import ModuleType, TracebackType, FunctionType
from typing import (
Any, Callable, Dict, List, Set, Tuple, Optional, Union,
- AnyStr, Type, Iterator, cast, ItemsView, Sequence
+ Type, Iterator, cast, ItemsView, Sequence
)
import unittest
import warnings
from unittest import TestSuite
-from pyfakefs.deprecator import Deprecator
from pyfakefs.fake_filesystem import (
- set_uid, set_gid, reset_ids, PatchMode, FakeFile, FakeFilesystem
+ set_uid, set_gid, reset_ids, PatchMode, FakeFilesystem
)
from pyfakefs.helpers import IS_PYPY
from pyfakefs.mox3_stubout import StubOutForTesting
@@ -305,48 +304,6 @@ class TestCase(unittest.TestCase, TestCaseMixin):
self.modules_to_reload = modules_to_reload
self.modules_to_patch = modules_to_patch
- @Deprecator('add_real_file')
- def copyRealFile(self, real_file_path: AnyStr,
- fake_file_path: Optional[AnyStr] = None,
- create_missing_dirs: bool = True) -> FakeFile:
- """Add the file `real_file_path` in the real file system to the same
- path in the fake file system.
-
- **This method is deprecated** in favor of
- :py:meth:`FakeFilesystem.add_real_file`.
- `copyRealFile()` is retained with limited functionality for backward
- compatibility only.
-
- Args:
- real_file_path: Path to the file in both the real and fake
- file systems
- fake_file_path: Deprecated. Use the default, which is
- `real_file_path`.
- If a value other than `real_file_path` is specified, a `ValueError`
- exception will be raised.
- create_missing_dirs: Deprecated. Use the default, which creates
- missing directories in the fake file system. If `False` is
- specified, a `ValueError` exception is raised.
-
- Returns:
- The newly created FakeFile object.
-
- Raises:
- OSError: If the file already exists in the fake file system.
- ValueError: If deprecated argument values are specified.
-
- See:
- :py:meth:`FakeFileSystem.add_real_file`
- """
- if fake_file_path is not None and real_file_path != fake_file_path:
- raise ValueError("CopyRealFile() is deprecated and no longer "
- "supports different real and fake file paths")
- if not create_missing_dirs:
- raise ValueError("CopyRealFile() is deprecated and no longer "
- "supports NOT creating missing directories")
- assert self._stubber.fs is not None
- return self._stubber.fs.add_real_file(real_file_path, read_only=False)
-
def tearDownPyfakefs(self) -> None:
"""This method is deprecated and exists only for backward
compatibility. It does nothing.