How to use the pyfakefs.fake_pathlib.FakePath function in pyfakefs

To help you get started, we’ve selected a few pyfakefs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
def expanduser(self):
        """ Return a new path with expanded ~ and ~user constructs
        (as returned by os.path.expanduser)
        """
        return FakePath(os.path.expanduser(self._path())
                        .replace(os.path.sep,
                                 self.filesystem.path_separator))
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
def init_module(filesystem):
    """Initializes the fake module with the fake file system."""
    # pylint: disable=protected-access
    FakePath.filesystem = filesystem
    FakePathlibModule.PureWindowsPath._flavour = _FakeWindowsFlavour(
        filesystem)
    FakePathlibModule.PurePosixPath._flavour = _FakePosixFlavour(filesystem)
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
filesystem: FakeFilesystem used to provide file system information
        """
        init_module(filesystem)
        self._pathlib_module = pathlib

    class PurePosixPath(PurePath):
        """A subclass of PurePath, that represents non-Windows filesystem
        paths"""
        __slots__ = ()

    class PureWindowsPath(PurePath):
        """A subclass of PurePath, that represents Windows filesystem paths"""
        __slots__ = ()

    if sys.platform == 'win32':
        class WindowsPath(FakePath, PureWindowsPath):
            """A subclass of Path and PureWindowsPath that represents
            concrete Windows filesystem paths.
            """
            __slots__ = ()
    else:
        class PosixPath(FakePath, PurePosixPath):
            """A subclass of Path and PurePosixPath that represents
            concrete non-Windows filesystem paths.
            """
            __slots__ = ()

    Path = FakePath

    def __getattr__(self, name):
        """Forwards any unfaked calls to the standard pathlib module."""
        return getattr(self._pathlib_module, name)
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
if sys.version_info >= (3, 6) or pathlib2:
            if strict is None:
                strict = False
        else:
            if strict is not None:
                raise TypeError(
                    "resolve() got an unexpected keyword argument 'strict'")
            strict = True
        if self._closed:
            self._raise_closed()
        path = self._flavour.resolve(self, strict=strict)
        if path is None:
            self.stat()
            path = str(self.absolute())
        path = self.filesystem.absnormpath(path)
        return FakePath(path)
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
"""A subclass of PurePath, that represents non-Windows filesystem
        paths"""
        __slots__ = ()

    class PureWindowsPath(PurePath):
        """A subclass of PurePath, that represents Windows filesystem paths"""
        __slots__ = ()

    if sys.platform == 'win32':
        class WindowsPath(FakePath, PureWindowsPath):
            """A subclass of Path and PureWindowsPath that represents
            concrete Windows filesystem paths.
            """
            __slots__ = ()
    else:
        class PosixPath(FakePath, PurePosixPath):
            """A subclass of Path and PurePosixPath that represents
            concrete non-Windows filesystem paths.
            """
            __slots__ = ()

    Path = FakePath

    def __getattr__(self, name):
        """Forwards any unfaked calls to the standard pathlib module."""
        return getattr(self._pathlib_module, name)


class FakePathlibPathModule:
    """Patches `pathlib.Path` by passing all calls to FakePathlibModule."""
    fake_pathlib = None
github jmcgeheeiv / pyfakefs / pyfakefs / fake_pathlib.py View on Github external
__slots__ = ()

    if sys.platform == 'win32':
        class WindowsPath(FakePath, PureWindowsPath):
            """A subclass of Path and PureWindowsPath that represents
            concrete Windows filesystem paths.
            """
            __slots__ = ()
    else:
        class PosixPath(FakePath, PurePosixPath):
            """A subclass of Path and PurePosixPath that represents
            concrete non-Windows filesystem paths.
            """
            __slots__ = ()

    Path = FakePath

    def __getattr__(self, name):
        """Forwards any unfaked calls to the standard pathlib module."""
        return getattr(self._pathlib_module, name)


class FakePathlibPathModule:
    """Patches `pathlib.Path` by passing all calls to FakePathlibModule."""
    fake_pathlib = None

    def __init__(self, filesystem):
        if self.fake_pathlib is None:
            self.__class__.fake_pathlib = FakePathlibModule(filesystem)

    def __call__(self, *args, **kwargs):
        return self.fake_pathlib.Path(*args, **kwargs)