PHP 8.2.30
Preview: pytest_plugin_test.py Size: 2.50 KB
//proc/thread-self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/pyfakefs/pytest_tests/pytest_plugin_test.py

"""Tests that the pytest plugin properly provides the "fs" fixture"""

import os
import tempfile

from pyfakefs.fake_filesystem import OSType
from pyfakefs.fake_filesystem_unittest import Pause
import pyfakefs.pytest_tests.io


def test_fs_fixture(fs):
    fs.create_file("/var/data/xx1.txt")
    assert os.path.exists("/var/data/xx1.txt")


def test_fs_fixture_alias(fake_filesystem):
    fake_filesystem.create_file("/var/data/xx1.txt")
    assert os.path.exists("/var/data/xx1.txt")


def test_both_fixtures(fs, fake_filesystem):
    fake_filesystem.create_file("/var/data/xx1.txt")
    fs.create_file("/var/data/xx2.txt")
    assert os.path.exists("/var/data/xx1.txt")
    assert os.path.exists("/var/data/xx2.txt")
    assert fs == fake_filesystem


def test_pause_resume(fs):
    fake_temp_file = tempfile.NamedTemporaryFile()
    assert fs.exists(fake_temp_file.name)
    assert os.path.exists(fake_temp_file.name)
    fs.pause()
    assert fs.exists(fake_temp_file.name)
    assert not os.path.exists(fake_temp_file.name)
    real_temp_file = tempfile.NamedTemporaryFile()
    assert not fs.exists(real_temp_file.name)
    assert os.path.exists(real_temp_file.name)
    fs.resume()
    assert not os.path.exists(real_temp_file.name)
    assert os.path.exists(fake_temp_file.name)


def test_pause_resume_contextmanager(fs):
    fake_temp_file = tempfile.NamedTemporaryFile()
    assert fs.exists(fake_temp_file.name)
    assert os.path.exists(fake_temp_file.name)
    with Pause(fs):
        assert fs.exists(fake_temp_file.name)
        assert not os.path.exists(fake_temp_file.name)
        real_temp_file = tempfile.NamedTemporaryFile()
        assert not fs.exists(real_temp_file.name)
        assert os.path.exists(real_temp_file.name)
    assert not os.path.exists(real_temp_file.name)
    assert os.path.exists(fake_temp_file.name)


def test_use_own_io_module(fs):
    filepath = "foo.txt"
    with open(filepath, "w") as f:
        f.write("bar")

    stream = pyfakefs.pytest_tests.io.InputStream(filepath)
    assert stream.read() == "bar"


def test_switch_to_windows(fs):
    fs.os = OSType.WINDOWS
    assert os.path.exists(tempfile.gettempdir())


def test_switch_to_linux(fs):
    fs.os = OSType.LINUX
    assert os.path.exists(tempfile.gettempdir())


def test_switch_to_macos(fs):
    fs.os = OSType.MACOS
    assert os.path.exists(tempfile.gettempdir())


def test_updatecache_problem(fs):
    # regression test for #1096
    filename = r"C:\source_file"
    fs.create_file(filename)
    with open(filename):
        assert True

Directory Contents

Dirs: 4 × Files: 19

Name Size Perms Modified Actions
data DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
hook_test DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:05
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
1.30 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
652 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
855 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
341 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
75 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
132 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
659 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.36 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.85 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.48 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.02 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
128 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
828 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
348 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
949 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
771 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
390 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).