`os.mkfifo` is not supported

Open
#999 4 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
testing

Research direction

Start in fake_os.py at FakeOsModule and compare the existing os.pipe() handling. Resolve whether mkfifo should only create a filesystem entry or use a FakeFIFO object with distinct open/read/write behavior; done means Unix-only os.mkfifo support without creating a real FIFO, including the documented options and errors.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem? Please describe.
No implementation for os.mkfifo() (Unix only).

Describe the solution you'd like
Add implementation so that real FIFOs don't get created in the filesystem.

Describe alternatives you've considered
Currently requires additional mocking.

Need to add something like the following to FakeOsModule in fake_os.py:

    def mkfifo(
        self,
        path: AnyStr,
        mode: int = PERM_DEF_FILE,
        *,
        dir_fd: Optional[int] = None,
    ) -> None:
        """Create a FIFO (a named pipe) named 'path'.

        Args:
            path: (str) Name of the file to create.
            mode: (int) Permissions to use and type of file to be created.
                Default permissions are 0o666.  The umask is applied to this
                mode.
            dir_fd: If not `None`, the file descriptor of a directory,
                with `path` being relative to this directory.

        Raises:
            OSError: If called with unsupported options or the file can not be
                created.
        """
        if self.filesystem.is_windows_fs:
            raise AttributeError("module 'os' has no attribute 'mkfifo'")

        path = self._path_with_dir_fd(path, self.mkfifo, dir_fd)
        head, tail = self.path.split(path)
        if not tail:
            if self.filesystem.exists(head, check_link=True):
                self.filesystem.raise_os_error(errno.EEXIST, path)
            self.filesystem.raise_os_error(errno.ENOENT, path)
        if tail in (matching_string(tail, "."), matching_string(tail, "..")):
            self.filesystem.raise_os_error(errno.ENOENT, path)
        if self.filesystem.exists(path, check_link=True):
            self.filesystem.raise_os_error(errno.EEXIST, path)
        self.filesystem.add_object(
            head,
            FakeFile(tail, mode & ~self.filesystem.umask, filesystem=self.filesystem),
        )

However, in using a regular file object in the example above, this doesn't simulate the semantics of a FIFO. Could also take inspiration from os.pipe(), except os.mkfifo() doesn't actually open fds, it just creates the entry in the filesystem - maybe create a FakeFIFO object in the filesystem which would then presumably need to handle open/read/write differently.

Dominant language
Python
Stars
756
Forks
111
Avg merge
3d 21h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pytest-dev/pyfakefs

All issues in pytest-dev/pyfakefs

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.